@diegopluna/narvi 0.1.0 → 0.3.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 (493) hide show
  1. package/README.md +102 -41
  2. package/dist/base.css +2 -2
  3. package/dist/color.d.ts +2 -2
  4. package/dist/color.js +1 -1
  5. package/dist/components/activity/ActivityContent.svelte +5 -17
  6. package/dist/components/activity/ActivityContent.svelte.d.ts +2 -2
  7. package/dist/components/activity/ActivityRoot.svelte +5 -5
  8. package/dist/components/activity/ActivityRoot.svelte.d.ts +5 -5
  9. package/dist/components/activity/ActivityStep.svelte +21 -21
  10. package/dist/components/activity/ActivityStep.svelte.d.ts +9 -9
  11. package/dist/components/activity/ActivityThought.svelte +7 -7
  12. package/dist/components/activity/ActivityThought.svelte.d.ts +3 -3
  13. package/dist/components/activity/ActivityTrigger.svelte +8 -8
  14. package/dist/components/activity/ActivityTrigger.svelte.d.ts +5 -5
  15. package/dist/components/announcer/Announcer.svelte +5 -18
  16. package/dist/components/announcer/Announcer.svelte.d.ts +3 -3
  17. package/dist/components/app-shell/AppShellBar.svelte +89 -0
  18. package/dist/components/app-shell/AppShellBar.svelte.d.ts +20 -0
  19. package/dist/components/app-shell/AppShellHeader.svelte +20 -19
  20. package/dist/components/app-shell/AppShellHeader.svelte.d.ts +5 -5
  21. package/dist/components/app-shell/AppShellMain.svelte +6 -22
  22. package/dist/components/app-shell/AppShellMain.svelte.d.ts +2 -2
  23. package/dist/components/app-shell/AppShellPanel.svelte +27 -25
  24. package/dist/components/app-shell/AppShellPanel.svelte.d.ts +6 -6
  25. package/dist/components/app-shell/AppShellPanes.svelte +58 -0
  26. package/dist/components/app-shell/AppShellPanes.svelte.d.ts +11 -0
  27. package/dist/components/app-shell/AppShellRail.svelte +85 -0
  28. package/dist/components/app-shell/AppShellRail.svelte.d.ts +11 -0
  29. package/dist/components/app-shell/AppShellRoot.svelte +58 -32
  30. package/dist/components/app-shell/AppShellRoot.svelte.d.ts +16 -14
  31. package/dist/components/app-shell/AppShellSheet.svelte +95 -0
  32. package/dist/components/app-shell/AppShellSheet.svelte.d.ts +17 -0
  33. package/dist/components/app-shell/AppShellSidebar.svelte +40 -64
  34. package/dist/components/app-shell/AppShellSidebar.svelte.d.ts +4 -8
  35. package/dist/components/app-shell/AppShellToggle.svelte +66 -26
  36. package/dist/components/app-shell/AppShellToggle.svelte.d.ts +5 -3
  37. package/dist/components/app-shell/context.d.ts +6 -0
  38. package/dist/components/app-shell/index.d.ts +9 -1
  39. package/dist/components/app-shell/index.js +5 -1
  40. package/dist/components/approval/Approval.svelte +101 -29
  41. package/dist/components/approval/Approval.svelte.d.ts +17 -10
  42. package/dist/components/avatar/AvatarFallback.svelte +4 -4
  43. package/dist/components/avatar/AvatarFallback.svelte.d.ts +2 -2
  44. package/dist/components/avatar/AvatarImage.svelte +3 -3
  45. package/dist/components/avatar/AvatarImage.svelte.d.ts +3 -3
  46. package/dist/components/avatar/AvatarRoot.svelte +7 -7
  47. package/dist/components/avatar/AvatarRoot.svelte.d.ts +5 -5
  48. package/dist/components/badge/Badge.svelte +26 -11
  49. package/dist/components/badge/Badge.svelte.d.ts +8 -5
  50. package/dist/components/button/Button.svelte +263 -53
  51. package/dist/components/button/Button.svelte.d.ts +53 -11
  52. package/dist/components/card/Card.svelte +21 -32
  53. package/dist/components/card/Card.svelte.d.ts +6 -6
  54. package/dist/components/change-stats/ChangeStats.svelte +5 -6
  55. package/dist/components/change-stats/ChangeStats.svelte.d.ts +4 -4
  56. package/dist/components/changes-summary/ChangesSummary.svelte +20 -21
  57. package/dist/components/changes-summary/ChangesSummary.svelte.d.ts +6 -6
  58. package/dist/components/checkbox/Checkbox.svelte +37 -23
  59. package/dist/components/checkbox/Checkbox.svelte.d.ts +14 -7
  60. package/dist/components/choice-cards/ChoiceCards.svelte +145 -0
  61. package/dist/components/choice-cards/ChoiceCards.svelte.d.ts +29 -0
  62. package/dist/components/code/Code.svelte +3 -4
  63. package/dist/components/code/Code.svelte.d.ts +2 -2
  64. package/dist/components/collapsible/CollapsibleContent.svelte +8 -8
  65. package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +10 -5
  66. package/dist/components/collapsible/CollapsibleRoot.svelte +8 -5
  67. package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +10 -5
  68. package/dist/components/collapsible/CollapsibleTrigger.svelte +19 -10
  69. package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +20 -7
  70. package/dist/components/command/CommandDialog.svelte +3 -3
  71. package/dist/components/command/CommandDialog.svelte.d.ts +3 -3
  72. package/dist/components/command/CommandEmpty.svelte +8 -5
  73. package/dist/components/command/CommandEmpty.svelte.d.ts +10 -5
  74. package/dist/components/command/CommandFooter.svelte +2 -2
  75. package/dist/components/command/CommandFooter.svelte.d.ts +2 -2
  76. package/dist/components/command/CommandGroup.svelte +9 -6
  77. package/dist/components/command/CommandGroup.svelte.d.ts +12 -6
  78. package/dist/components/command/CommandInput.svelte +4 -1
  79. package/dist/components/command/CommandInput.svelte.d.ts +7 -4
  80. package/dist/components/command/CommandItem.svelte +15 -12
  81. package/dist/components/command/CommandItem.svelte.d.ts +18 -8
  82. package/dist/components/command/CommandList.svelte +7 -4
  83. package/dist/components/command/CommandList.svelte.d.ts +9 -5
  84. package/dist/components/command/CommandRoot.svelte +8 -5
  85. package/dist/components/command/CommandRoot.svelte.d.ts +10 -5
  86. package/dist/components/command/index.d.ts +3 -2
  87. package/dist/components/command/index.js +3 -2
  88. package/dist/components/command/styles.d.ts +3 -2
  89. package/dist/components/command/styles.js +13 -10
  90. package/dist/components/composer/ComposerAttachButton.svelte +5 -5
  91. package/dist/components/composer/ComposerAttachButton.svelte.d.ts +4 -4
  92. package/dist/components/composer/ComposerAttachment.svelte +11 -14
  93. package/dist/components/composer/ComposerAttachment.svelte.d.ts +2 -2
  94. package/dist/components/composer/ComposerAttachments.svelte +3 -3
  95. package/dist/components/composer/ComposerAttachments.svelte.d.ts +3 -3
  96. package/dist/components/composer/ComposerModelPicker.svelte +27 -29
  97. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +9 -9
  98. package/dist/components/composer/ComposerRoot.svelte +26 -32
  99. package/dist/components/composer/ComposerRoot.svelte.d.ts +15 -15
  100. package/dist/components/composer/ComposerSubmit.svelte +14 -20
  101. package/dist/components/composer/ComposerSubmit.svelte.d.ts +4 -4
  102. package/dist/components/composer/ComposerTextarea.svelte +4 -4
  103. package/dist/components/composer/ComposerTextarea.svelte.d.ts +3 -3
  104. package/dist/components/composer/ComposerToggle.svelte +13 -15
  105. package/dist/components/composer/ComposerToggle.svelte.d.ts +4 -4
  106. package/dist/components/composer/ComposerToolbar.svelte +2 -2
  107. package/dist/components/composer/ComposerToolbar.svelte.d.ts +2 -2
  108. package/dist/components/composer/ComposerTray.svelte +78 -0
  109. package/dist/components/composer/ComposerTray.svelte.d.ts +15 -0
  110. package/dist/components/composer/index.d.ts +3 -1
  111. package/dist/components/composer/index.js +3 -2
  112. package/dist/components/conversation/ConversationContent.svelte +7 -6
  113. package/dist/components/conversation/ConversationContent.svelte.d.ts +4 -4
  114. package/dist/components/conversation/ConversationEmpty.svelte +6 -6
  115. package/dist/components/conversation/ConversationEmpty.svelte.d.ts +5 -5
  116. package/dist/components/conversation/ConversationRoot.svelte +4 -4
  117. package/dist/components/conversation/ConversationRoot.svelte.d.ts +4 -4
  118. package/dist/components/conversation/ConversationScrollButton.svelte +7 -7
  119. package/dist/components/conversation/ConversationScrollButton.svelte.d.ts +4 -4
  120. package/dist/components/dialog/ConfirmDialog.svelte +47 -16
  121. package/dist/components/dialog/ConfirmDialog.svelte.d.ts +14 -9
  122. package/dist/components/dialog/DialogBody.svelte +12 -4
  123. package/dist/components/dialog/DialogBody.svelte.d.ts +5 -3
  124. package/dist/components/dialog/DialogContent.svelte +16 -11
  125. package/dist/components/dialog/DialogContent.svelte.d.ts +21 -9
  126. package/dist/components/dialog/DialogDescription.svelte +7 -4
  127. package/dist/components/dialog/DialogDescription.svelte.d.ts +9 -5
  128. package/dist/components/dialog/DialogFooter.svelte +2 -2
  129. package/dist/components/dialog/DialogFooter.svelte.d.ts +2 -2
  130. package/dist/components/dialog/DialogHeader.svelte +2 -2
  131. package/dist/components/dialog/DialogHeader.svelte.d.ts +2 -2
  132. package/dist/components/dialog/DialogTitle.svelte +7 -4
  133. package/dist/components/dialog/DialogTitle.svelte.d.ts +9 -5
  134. package/dist/components/dialog/index.d.ts +5 -4
  135. package/dist/components/dialog/index.js +4 -3
  136. package/dist/components/dialog/styles.d.ts +8 -3
  137. package/dist/components/dialog/styles.js +11 -7
  138. package/dist/components/divider/Divider.svelte +6 -6
  139. package/dist/components/divider/Divider.svelte.d.ts +3 -3
  140. package/dist/components/empty-state/EmptyState.svelte +14 -10
  141. package/dist/components/empty-state/EmptyState.svelte.d.ts +5 -4
  142. package/dist/components/field/Field.svelte +92 -31
  143. package/dist/components/field/Field.svelte.d.ts +24 -11
  144. package/dist/components/field/context.d.ts +6 -3
  145. package/dist/components/frame/Frame.svelte +12 -13
  146. package/dist/components/frame/Frame.svelte.d.ts +7 -7
  147. package/dist/components/grid/Grid.svelte +17 -6
  148. package/dist/components/grid/Grid.svelte.d.ts +6 -6
  149. package/dist/components/heading/Heading.svelte +31 -8
  150. package/dist/components/heading/Heading.svelte.d.ts +6 -4
  151. package/dist/components/hover-card/HoverCardContent.svelte +7 -4
  152. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +9 -5
  153. package/dist/components/hover-card/HoverCardRoot.svelte +2 -1
  154. package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +3 -2
  155. package/dist/components/hover-card/index.d.ts +2 -1
  156. package/dist/components/hover-card/index.js +2 -1
  157. package/dist/components/input/Input.svelte +63 -17
  158. package/dist/components/input/Input.svelte.d.ts +12 -5
  159. package/dist/components/kbd/Kbd.svelte +14 -9
  160. package/dist/components/kbd/Kbd.svelte.d.ts +2 -2
  161. package/dist/components/link/Link.svelte +12 -8
  162. package/dist/components/link/Link.svelte.d.ts +9 -6
  163. package/dist/components/list/ListItem.svelte +41 -0
  164. package/dist/components/list/ListItem.svelte.d.ts +10 -0
  165. package/dist/components/list/ListRoot.svelte +69 -0
  166. package/dist/components/list/ListRoot.svelte.d.ts +28 -0
  167. package/dist/components/list/context.d.ts +5 -0
  168. package/dist/components/list/context.js +8 -0
  169. package/dist/components/list/index.d.ts +5 -0
  170. package/dist/components/list/index.js +3 -0
  171. package/dist/components/markdown/Markdown.svelte +714 -0
  172. package/dist/components/markdown/Markdown.svelte.d.ts +80 -0
  173. package/dist/components/markdown/MarkdownBlock.svelte +231 -0
  174. package/dist/components/markdown/MarkdownBlock.svelte.d.ts +11 -0
  175. package/dist/components/markdown/MarkdownBlocks.svelte +115 -0
  176. package/dist/components/markdown/MarkdownBlocks.svelte.d.ts +15 -0
  177. package/dist/components/markdown/MarkdownCode.svelte +583 -0
  178. package/dist/components/markdown/MarkdownCode.svelte.d.ts +23 -0
  179. package/dist/components/markdown/MarkdownDiagram.svelte +310 -0
  180. package/dist/components/markdown/MarkdownDiagram.svelte.d.ts +6 -0
  181. package/dist/components/markdown/MarkdownFile.svelte +136 -0
  182. package/dist/components/markdown/MarkdownFile.svelte.d.ts +19 -0
  183. package/dist/components/markdown/MarkdownFootnotes.svelte +62 -0
  184. package/dist/components/markdown/MarkdownFootnotes.svelte.d.ts +8 -0
  185. package/dist/components/markdown/MarkdownFresh.svelte +69 -0
  186. package/dist/components/markdown/MarkdownFresh.svelte.d.ts +6 -0
  187. package/dist/components/markdown/MarkdownHtml.svelte +72 -0
  188. package/dist/components/markdown/MarkdownHtml.svelte.d.ts +7 -0
  189. package/dist/components/markdown/MarkdownImage.svelte +150 -0
  190. package/dist/components/markdown/MarkdownImage.svelte.d.ts +8 -0
  191. package/dist/components/markdown/MarkdownInlines.svelte +225 -0
  192. package/dist/components/markdown/MarkdownInlines.svelte.d.ts +7 -0
  193. package/dist/components/markdown/MarkdownLink.svelte +120 -0
  194. package/dist/components/markdown/MarkdownLink.svelte.d.ts +25 -0
  195. package/dist/components/markdown/MarkdownMath.svelte +138 -0
  196. package/dist/components/markdown/MarkdownMath.svelte.d.ts +7 -0
  197. package/dist/components/markdown/MarkdownTable.svelte +258 -0
  198. package/dist/components/markdown/MarkdownTable.svelte.d.ts +17 -0
  199. package/dist/components/markdown/caret.d.ts +14 -0
  200. package/dist/components/markdown/caret.js +67 -0
  201. package/dist/components/markdown/context.d.ts +93 -0
  202. package/dist/components/markdown/context.js +128 -0
  203. package/dist/components/markdown/copy.d.ts +13 -0
  204. package/dist/components/markdown/copy.js +74 -0
  205. package/dist/components/markdown/hidden.d.ts +12 -0
  206. package/dist/components/markdown/hidden.js +31 -0
  207. package/dist/components/markdown/kept.d.ts +32 -0
  208. package/dist/components/markdown/kept.js +71 -0
  209. package/dist/components/markdown/labels.d.ts +46 -0
  210. package/dist/components/markdown/labels.js +35 -0
  211. package/dist/components/markdown/save.d.ts +11 -0
  212. package/dist/components/markdown/save.js +58 -0
  213. package/dist/components/markdown/scrollable.d.ts +24 -0
  214. package/dist/components/markdown/scrollable.js +152 -0
  215. package/dist/components/markdown/static.d.ts +37 -0
  216. package/dist/components/markdown/static.js +233 -0
  217. package/dist/components/markdown/styles.d.ts +320 -0
  218. package/dist/components/markdown/styles.js +294 -0
  219. package/dist/components/menu/ContextMenuContent.svelte +8 -5
  220. package/dist/components/menu/ContextMenuContent.svelte.d.ts +10 -5
  221. package/dist/components/menu/ContextMenuTrigger.svelte +8 -5
  222. package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +10 -5
  223. package/dist/components/menu/MenuCheckboxItem.svelte +8 -5
  224. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +11 -6
  225. package/dist/components/menu/MenuContent.svelte +7 -4
  226. package/dist/components/menu/MenuContent.svelte.d.ts +9 -5
  227. package/dist/components/menu/MenuItem.svelte +14 -11
  228. package/dist/components/menu/MenuItem.svelte.d.ts +18 -8
  229. package/dist/components/menu/MenuLabel.svelte +7 -4
  230. package/dist/components/menu/MenuLabel.svelte.d.ts +9 -5
  231. package/dist/components/menu/MenuRadioItem.svelte +26 -11
  232. package/dist/components/menu/MenuRadioItem.svelte.d.ts +20 -6
  233. package/dist/components/menu/MenuSeparator.svelte +6 -3
  234. package/dist/components/menu/MenuSeparator.svelte.d.ts +7 -4
  235. package/dist/components/menu/MenuSubContent.svelte +7 -4
  236. package/dist/components/menu/MenuSubContent.svelte.d.ts +9 -5
  237. package/dist/components/menu/MenuSubTrigger.svelte +9 -6
  238. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +11 -6
  239. package/dist/components/menu/context-menu.d.ts +3 -1
  240. package/dist/components/menu/context-menu.js +2 -1
  241. package/dist/components/menu/index.d.ts +24 -0
  242. package/dist/components/menu/index.js +9 -6
  243. package/dist/components/message/MessageAction.svelte +26 -6
  244. package/dist/components/message/MessageAction.svelte.d.ts +13 -4
  245. package/dist/components/message/MessageActions.svelte +4 -4
  246. package/dist/components/message/MessageActions.svelte.d.ts +4 -4
  247. package/dist/components/message/MessageContent.svelte +5 -6
  248. package/dist/components/message/MessageContent.svelte.d.ts +3 -3
  249. package/dist/components/message/MessageCopy.svelte +74 -18
  250. package/dist/components/message/MessageCopy.svelte.d.ts +22 -6
  251. package/dist/components/message/MessageHeader.svelte +6 -6
  252. package/dist/components/message/MessageHeader.svelte.d.ts +3 -3
  253. package/dist/components/message/MessagePending.svelte +3 -3
  254. package/dist/components/message/MessagePending.svelte.d.ts +2 -2
  255. package/dist/components/message/MessageRoot.svelte +5 -5
  256. package/dist/components/message/MessageRoot.svelte.d.ts +5 -5
  257. package/dist/components/message/MessageTime.svelte +4 -4
  258. package/dist/components/message/MessageTime.svelte.d.ts +3 -3
  259. package/dist/components/notice/Notice.svelte +59 -19
  260. package/dist/components/notice/Notice.svelte.d.ts +13 -8
  261. package/dist/components/plan/Plan.svelte +28 -30
  262. package/dist/components/plan/Plan.svelte.d.ts +5 -5
  263. package/dist/components/popover/PopoverContent.svelte +7 -4
  264. package/dist/components/popover/PopoverContent.svelte.d.ts +9 -5
  265. package/dist/components/popover/index.d.ts +4 -3
  266. package/dist/components/popover/index.js +4 -3
  267. package/dist/components/progress/Progress.svelte +34 -36
  268. package/dist/components/progress/Progress.svelte.d.ts +3 -3
  269. package/dist/components/questionnaire/Questionnaire.svelte +36 -33
  270. package/dist/components/questionnaire/Questionnaire.svelte.d.ts +11 -11
  271. package/dist/components/queued-message/QueuedMessage.svelte +24 -17
  272. package/dist/components/queued-message/QueuedMessage.svelte.d.ts +10 -10
  273. package/dist/components/rail/RailItem.svelte +49 -53
  274. package/dist/components/rail/RailItem.svelte.d.ts +11 -9
  275. package/dist/components/rail/RailRoot.svelte +20 -6
  276. package/dist/components/rail/RailRoot.svelte.d.ts +3 -3
  277. package/dist/components/rail/RailSeparator.svelte +17 -0
  278. package/dist/components/rail/RailSeparator.svelte.d.ts +18 -0
  279. package/dist/components/rail/index.d.ts +2 -1
  280. package/dist/components/rail/index.js +2 -1
  281. package/dist/components/reasoning/ReasoningContent.svelte +6 -10
  282. package/dist/components/reasoning/ReasoningContent.svelte.d.ts +2 -2
  283. package/dist/components/reasoning/ReasoningRoot.svelte +6 -6
  284. package/dist/components/reasoning/ReasoningRoot.svelte.d.ts +6 -6
  285. package/dist/components/reasoning/ReasoningTrigger.svelte +5 -5
  286. package/dist/components/reasoning/ReasoningTrigger.svelte.d.ts +3 -3
  287. package/dist/components/resize-handle/ResizeHandle.svelte +12 -13
  288. package/dist/components/resize-handle/ResizeHandle.svelte.d.ts +10 -10
  289. package/dist/components/reveal/Reveal.svelte +16 -10
  290. package/dist/components/reveal/Reveal.svelte.d.ts +4 -4
  291. package/dist/components/reveal/revealed.js +13 -9
  292. package/dist/components/rolling-text/RollingText.svelte +3 -3
  293. package/dist/components/rolling-text/RollingText.svelte.d.ts +3 -3
  294. package/dist/components/search-button/SearchButton.svelte +92 -0
  295. package/dist/components/search-button/SearchButton.svelte.d.ts +13 -0
  296. package/dist/components/segmented/SegmentedControl.svelte +78 -32
  297. package/dist/components/segmented/SegmentedControl.svelte.d.ts +14 -5
  298. package/dist/components/select/Select.svelte +40 -15
  299. package/dist/components/select/Select.svelte.d.ts +21 -13
  300. package/dist/components/separator/Separator.svelte +4 -4
  301. package/dist/components/separator/Separator.svelte.d.ts +3 -3
  302. package/dist/components/settings-group/SettingsGroup.svelte +118 -0
  303. package/dist/components/settings-group/SettingsGroup.svelte.d.ts +19 -0
  304. package/dist/components/settings-group/context.d.ts +7 -0
  305. package/dist/components/settings-group/context.js +9 -0
  306. package/dist/components/settings-row/SettingsRow.svelte +185 -57
  307. package/dist/components/settings-row/SettingsRow.svelte.d.ts +39 -14
  308. package/dist/components/sheet/SheetContent.svelte +31 -11
  309. package/dist/components/sheet/SheetContent.svelte.d.ts +33 -9
  310. package/dist/components/sheet/index.d.ts +5 -4
  311. package/dist/components/sheet/index.js +4 -3
  312. package/dist/components/sheet/styles.d.ts +6 -0
  313. package/dist/components/sheet/styles.js +2 -0
  314. package/dist/components/shimmer/Shimmer.svelte +37 -24
  315. package/dist/components/shimmer/Shimmer.svelte.d.ts +3 -3
  316. package/dist/components/sidebar/SidebarContent.svelte +4 -4
  317. package/dist/components/sidebar/SidebarContent.svelte.d.ts +3 -3
  318. package/dist/components/sidebar/SidebarFolder.svelte +147 -0
  319. package/dist/components/sidebar/SidebarFolder.svelte.d.ts +19 -0
  320. package/dist/components/sidebar/SidebarFooter.svelte +3 -3
  321. package/dist/components/sidebar/SidebarFooter.svelte.d.ts +2 -2
  322. package/dist/components/sidebar/SidebarGroup.svelte +41 -37
  323. package/dist/components/sidebar/SidebarGroup.svelte.d.ts +8 -8
  324. package/dist/components/sidebar/SidebarHeader.svelte +15 -9
  325. package/dist/components/sidebar/SidebarHeader.svelte.d.ts +7 -4
  326. package/dist/components/sidebar/SidebarItem.svelte +64 -45
  327. package/dist/components/sidebar/SidebarItem.svelte.d.ts +15 -10
  328. package/dist/components/sidebar/SidebarRoot.svelte +62 -0
  329. package/dist/components/sidebar/SidebarRoot.svelte.d.ts +14 -0
  330. package/dist/components/sidebar/SidebarSwitcher.svelte +28 -0
  331. package/dist/components/sidebar/SidebarSwitcher.svelte.d.ts +11 -0
  332. package/dist/components/sidebar/depth.d.ts +8 -0
  333. package/dist/components/sidebar/depth.js +14 -0
  334. package/dist/components/sidebar/index.d.ts +7 -1
  335. package/dist/components/sidebar/index.js +4 -1
  336. package/dist/components/skeleton/Skeleton.svelte +31 -20
  337. package/dist/components/skeleton/Skeleton.svelte.d.ts +5 -5
  338. package/dist/components/slider/Slider.svelte +24 -23
  339. package/dist/components/slider/Slider.svelte.d.ts +13 -13
  340. package/dist/components/spinner/Spinner.svelte +8 -14
  341. package/dist/components/spinner/Spinner.svelte.d.ts +3 -3
  342. package/dist/components/stack/Stack.svelte +19 -8
  343. package/dist/components/stack/Stack.svelte.d.ts +8 -8
  344. package/dist/components/status-indicator/StatusIndicator.svelte +6 -5
  345. package/dist/components/status-indicator/StatusIndicator.svelte.d.ts +4 -4
  346. package/dist/components/suggestions/SuggestionsItem.svelte +8 -8
  347. package/dist/components/suggestions/SuggestionsItem.svelte.d.ts +3 -3
  348. package/dist/components/suggestions/SuggestionsRoot.svelte +5 -5
  349. package/dist/components/suggestions/SuggestionsRoot.svelte.d.ts +5 -5
  350. package/dist/components/switch/Switch.svelte +27 -21
  351. package/dist/components/switch/Switch.svelte.d.ts +8 -6
  352. package/dist/components/tab-strip/TabStrip.svelte +421 -0
  353. package/dist/components/tab-strip/TabStrip.svelte.d.ts +31 -0
  354. package/dist/components/tabs/Tabs.svelte +83 -33
  355. package/dist/components/tabs/Tabs.svelte.d.ts +15 -5
  356. package/dist/components/text/Text.svelte +63 -31
  357. package/dist/components/text/Text.svelte.d.ts +18 -12
  358. package/dist/components/textarea/Textarea.svelte +5 -5
  359. package/dist/components/textarea/Textarea.svelte.d.ts +5 -5
  360. package/dist/components/theme/Theme.svelte +4 -4
  361. package/dist/components/theme/Theme.svelte.d.ts +4 -4
  362. package/dist/components/toast/Toaster.svelte +39 -32
  363. package/dist/components/toast/Toaster.svelte.d.ts +2 -2
  364. package/dist/components/toast/toasts.svelte.d.ts +52 -15
  365. package/dist/components/toast/toasts.svelte.js +45 -20
  366. package/dist/components/toggle/Toggle.svelte +11 -8
  367. package/dist/components/toggle/Toggle.svelte.d.ts +15 -7
  368. package/dist/components/toggle-group/ToggleGroupItem.svelte +9 -6
  369. package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +12 -6
  370. package/dist/components/toggle-group/ToggleGroupRoot.svelte +17 -14
  371. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +13 -12
  372. package/dist/components/tool/ToolContent.svelte +5 -10
  373. package/dist/components/tool/ToolContent.svelte.d.ts +2 -2
  374. package/dist/components/tool/ToolInput.svelte +3 -3
  375. package/dist/components/tool/ToolInput.svelte.d.ts +3 -3
  376. package/dist/components/tool/ToolOutput.svelte +4 -4
  377. package/dist/components/tool/ToolOutput.svelte.d.ts +4 -4
  378. package/dist/components/tool/ToolRoot.svelte +7 -7
  379. package/dist/components/tool/ToolRoot.svelte.d.ts +7 -7
  380. package/dist/components/tool/ToolSection.svelte +8 -9
  381. package/dist/components/tool/ToolSection.svelte.d.ts +4 -4
  382. package/dist/components/tool/ToolTrigger.svelte +14 -13
  383. package/dist/components/tool/ToolTrigger.svelte.d.ts +4 -4
  384. package/dist/components/tooltip/TooltipContent.svelte +12 -9
  385. package/dist/components/tooltip/TooltipContent.svelte.d.ts +12 -6
  386. package/dist/components/tooltip/TooltipRoot.svelte +7 -4
  387. package/dist/components/tooltip/TooltipRoot.svelte.d.ts +8 -4
  388. package/dist/components/tooltip/TooltipTrigger.svelte +2 -1
  389. package/dist/components/tooltip/TooltipTrigger.svelte.d.ts +3 -2
  390. package/dist/components/tooltip/index.d.ts +2 -1
  391. package/dist/components/tooltip/index.js +2 -1
  392. package/dist/components/work-fold/WorkFold.svelte +9 -13
  393. package/dist/components/work-fold/WorkFold.svelte.d.ts +4 -4
  394. package/dist/index.d.ts +30 -12
  395. package/dist/index.js +24 -10
  396. package/dist/internal/Chevron.svelte +1 -1
  397. package/dist/internal/Chevron.svelte.d.ts +1 -1
  398. package/dist/internal/Code.svelte +9 -5
  399. package/dist/internal/Code.svelte.d.ts +3 -3
  400. package/dist/internal/Collapse.svelte +4 -4
  401. package/dist/internal/Collapse.svelte.d.ts +4 -4
  402. package/dist/internal/Glyph.svelte +19 -1
  403. package/dist/internal/Glyph.svelte.d.ts +9 -2
  404. package/dist/internal/Tile.svelte +22 -42
  405. package/dist/internal/Tile.svelte.d.ts +5 -5
  406. package/dist/internal/complete.d.ts +8 -0
  407. package/dist/internal/complete.js +1 -0
  408. package/dist/internal/control.d.ts +4 -4
  409. package/dist/internal/control.js +20 -17
  410. package/dist/internal/icon.d.ts +9 -0
  411. package/dist/internal/icon.js +1 -0
  412. package/dist/internal/icons.css +14 -0
  413. package/dist/internal/json.d.ts +1 -1
  414. package/dist/internal/layer.d.ts +6 -6
  415. package/dist/internal/layer.js +17 -14
  416. package/dist/internal/layout.d.ts +1 -1
  417. package/dist/internal/layout.js +6 -0
  418. package/dist/internal/loose.d.ts +22 -0
  419. package/dist/internal/loose.js +4 -0
  420. package/dist/internal/markers.stylex.d.ts +12 -0
  421. package/dist/internal/markers.stylex.js +6 -0
  422. package/dist/internal/plugin-order.d.ts +8 -0
  423. package/dist/internal/plugin-order.js +16 -0
  424. package/dist/internal/responsive.d.ts +1 -1
  425. package/dist/internal/roving.d.ts +1 -1
  426. package/dist/internal/roving.js +5 -2
  427. package/dist/internal/shared.d.ts +8 -1
  428. package/dist/internal/shared.js +21 -5
  429. package/dist/internal/sx.d.ts +5 -5
  430. package/dist/internal/toggle.d.ts +1 -2
  431. package/dist/internal/toggle.js +8 -12
  432. package/dist/internal/tooltip-trigger.d.ts +9 -0
  433. package/dist/internal/tooltip-trigger.js +19 -0
  434. package/dist/internal/visible.d.ts +32 -0
  435. package/dist/internal/visible.js +44 -0
  436. package/dist/markdown/ast.d.ts +209 -0
  437. package/dist/markdown/ast.js +10 -0
  438. package/dist/markdown/blocks.d.ts +178 -0
  439. package/dist/markdown/blocks.js +1489 -0
  440. package/dist/markdown/code-info.d.ts +10 -0
  441. package/dist/markdown/code-info.js +16 -0
  442. package/dist/markdown/common.d.ts +25 -0
  443. package/dist/markdown/common.js +107 -0
  444. package/dist/markdown/diagrams.d.ts +2 -0
  445. package/dist/markdown/diagrams.js +18 -0
  446. package/dist/markdown/file-paths.d.ts +29 -0
  447. package/dist/markdown/file-paths.js +80 -0
  448. package/dist/markdown/files.d.ts +16 -0
  449. package/dist/markdown/files.js +133 -0
  450. package/dist/markdown/highlight.d.ts +30 -0
  451. package/dist/markdown/highlight.js +127 -0
  452. package/dist/markdown/html.d.ts +14 -0
  453. package/dist/markdown/html.js +289 -0
  454. package/dist/markdown/images.d.ts +15 -0
  455. package/dist/markdown/images.js +45 -0
  456. package/dist/markdown/index.d.ts +12 -0
  457. package/dist/markdown/index.js +5 -0
  458. package/dist/markdown/inlines.d.ts +48 -0
  459. package/dist/markdown/inlines.js +1714 -0
  460. package/dist/markdown/math.d.ts +2 -0
  461. package/dist/markdown/math.js +22 -0
  462. package/dist/markdown/parse.d.ts +81 -0
  463. package/dist/markdown/parse.js +204 -0
  464. package/dist/markdown/plugin.d.ts +179 -0
  465. package/dist/markdown/plugin.js +160 -0
  466. package/dist/markdown/sanitize.d.ts +78 -0
  467. package/dist/markdown/sanitize.js +522 -0
  468. package/dist/markdown/share.d.ts +12 -0
  469. package/dist/markdown/share.js +59 -0
  470. package/dist/markdown/table.d.ts +13 -0
  471. package/dist/markdown/table.js +60 -0
  472. package/dist/markers.stylex.d.ts +13 -0
  473. package/dist/markers.stylex.js +11 -0
  474. package/dist/preset.d.ts +44 -20
  475. package/dist/preset.js +169 -51
  476. package/dist/tokens.stylex.d.ts +57 -37
  477. package/dist/tokens.stylex.js +113 -62
  478. package/dist/typography.d.ts +55 -0
  479. package/dist/typography.js +63 -0
  480. package/dist/visually-hidden.d.ts +18 -0
  481. package/dist/visually-hidden.js +21 -0
  482. package/dist/vite.d.ts +9 -3
  483. package/dist/vite.js +27 -2
  484. package/package.json +57 -6
  485. package/skills/building-ui/SKILL.md +385 -0
  486. package/skills/building-ui/references/components.md +211 -0
  487. package/skills/markdown/SKILL.md +452 -0
  488. package/skills/markdown/references/plugins.md +103 -0
  489. package/skills/setup/SKILL.md +199 -0
  490. package/skills/styling/SKILL.md +318 -0
  491. package/skills/theming/SKILL.md +277 -0
  492. package/dist/internal/loop.d.ts +0 -35
  493. package/dist/internal/loop.js +0 -72
@@ -0,0 +1,452 @@
1
+ ---
2
+ name: markdown
3
+ description: >
4
+ Use when rendering Markdown with @diegopluna/narvi, especially an AI reply that streams: the
5
+ Markdown component, streaming and tidy, plugins (transforms, components by node type,
6
+ highlighters), the link and image policy, raw HTML, and parsing with MarkdownStream or parse
7
+ from @diegopluna/narvi/markdown.
8
+ metadata:
9
+ purpose: >
10
+ Render Markdown, streamed or finished, with Narvi's own incremental CommonMark and GFM
11
+ renderer: keep finished blocks from being drawn again, extend it with plugins instead of
12
+ patching the DOM, and decide which links and images text from a model may load.
13
+ type: core
14
+ library: '@diegopluna/narvi'
15
+ library_version: '0.3.0'
16
+ requires:
17
+ - setup
18
+ sources:
19
+ - src/lib/components/markdown/**
20
+ - src/lib/markdown/**
21
+ ---
22
+
23
+ # Render Markdown with Narvi
24
+
25
+ This assumes Narvi is installed and its styles load (see the `setup` skill). Narvi renders
26
+ Markdown with its own parser: CommonMark 0.31.2 plus GFM (tables, task lists, strikethrough,
27
+ bare links, footnotes) and GitHub's alerts. It departs from CommonMark in one place, for
28
+ Chinese, Japanese and Korean text: emphasis closes beside their punctuation, so
29
+ `**テスト。**次` is bold, as people writing without spaces expect. It needs no other Markdown
30
+ library. Don't add `marked`,
31
+ `svelte-streamdown` or `{@html}` next to it.
32
+
33
+ ## Setup
34
+
35
+ ```svelte
36
+ <script lang="ts">
37
+ import { Markdown } from '@diegopluna/narvi';
38
+
39
+ let { text, done }: { text: string; done: boolean } = $props();
40
+ </script>
41
+
42
+ <Markdown value={text} streaming={!done} />
43
+ ```
44
+
45
+ - `value` is **all the text so far**, not the latest chunk. Pass the whole string on every
46
+ update; when it continues the previous value, only the new part is read.
47
+ - `streaming` is true while the text is still being written. When it turns false, the document
48
+ finishes in place: blocks keep their elements, nothing is drawn again, and the page doesn't jump.
49
+ - Sizes are in `em`, so the document takes the font size of its container. Set the size on the
50
+ container or with `sx`, for example `sx={styles.reply}` with `fontSize: font.sizeReading`.
51
+ - Inside a chat, put it in `Message.Content`:
52
+ `<Message.Content><Markdown value={reply} streaming={!done} /></Message.Content>`.
53
+
54
+ Other props:
55
+
56
+ - `breaks` makes a line ending inside a paragraph break the line, as chat messages are usually
57
+ meant. Off by default, as Markdown has it. Use it for text a person typed, not for a model's.
58
+ - `headingOffset={2}` moves headings down two levels, so `#` is an `h3` under the page's own
59
+ headings. They keep the size they're written with.
60
+ - `ontaskchange={(item, checked) => …}` makes task items tickable. Without it the boxes are
61
+ shown but can't be ticked. `item.checkedAt` is where the item's `[` is in `value`: write `x`
62
+ or a space at `checkedAt + 1` and pass the new text back. Return `false`, or reject, and the
63
+ box goes back.
64
+ - `labels` rewords or translates what the controls show and say (the copy buttons, the table
65
+ menu, "Load image from" and "Load video from", the alert titles): `labels={{ copyCode: 'Copiar
66
+ código' }}`. The type is `MarkdownLabels`, exported from `@diegopluna/narvi`.
67
+ - `singleTilde` makes `~text~` strike through. It's off, so `~5 minutes` and `~/path` stay as
68
+ written; `~~text~~` always strikes through.
69
+ - `frontmatter` reads YAML front matter at the top of a file (`---`, `key: value` lines, `---`)
70
+ and leaves it out; without it, front matter is drawn as a rule and a heading. Turn it on for
71
+ Markdown files, not for replies: a reply that starts with `---` starts with a rule.
72
+ - `caret` shows a caret at the end of the text while it streams (`caret="circle"` for a dot).
73
+ `animated` fades text in a few words at a time as it arrives, where a new block otherwise
74
+ fades in whole. Both are off by default and do nothing once `streaming` is false.
75
+ - `lineNumbers` numbers the lines of code blocks that have a language, and `download` gives
76
+ code blocks a button that saves the code, named by the fence's file name or its language.
77
+ - `static` says whether finished blocks are written as markup, not built from parts: about
78
+ twice as fast to show, in a fifth of the memory. Leave it out. Narvi then writes markup for
79
+ text that was whole when the component was made and has not changed since (a reply loaded
80
+ from history), and draws parts for text that streams or is edited here, which change in
81
+ place. `static={false}` never writes markup, and `static` (true) does whenever nothing
82
+ streams. Prose, lists, tasks, quotes, code blocks, tables and file chips are written so,
83
+ and their buttons, links and boxes still do what they do (`links.open`, `ontaskchange`, the
84
+ `open` of `files()`). Images, formulas, diagrams, footnotes, alerts and raw HTML are drawn
85
+ by their parts as ever, with the block they are in. Markup written for a text is kept and
86
+ used again when the same text is shown with the same props and the same plugin objects
87
+ (a virtualised thread scrolling back), so keep `plugins` and `labels` the same objects
88
+ across rows: a new array of the same plugins is fine, new plugin objects are not. A plugin
89
+ whose output depends on something besides the text must be made again when that changes.
90
+ - `tidy={false}` and `gfm={false}` turn off the tidy preview and the GFM extensions.
91
+
92
+ A quote that starts with `[!NOTE]`, `[!TIP]`, `[!IMPORTANT]`, `[!WARNING]` or `[!CAUTION]`
93
+ is drawn as an alert with that title. Headings get the ids GitHub gives them, made unique to
94
+ each document, and a `#heading` link scrolls to its heading without changing the page's address.
95
+
96
+ In a thread, a reply that streams and a reply loaded from history take the same props. The
97
+ one loaded finished is written as markup, and the one that streams keeps the parts it was
98
+ drawn with after it ends:
99
+
100
+ ```svelte
101
+ <script lang="ts">
102
+ import { Markdown } from '@diegopluna/narvi';
103
+
104
+ type Turn = { text: string; done: boolean };
105
+ let { turn }: { turn: Turn } = $props();
106
+ </script>
107
+
108
+ <Markdown value={turn.text} streaming={!turn.done} caret animated />
109
+ ```
110
+
111
+ ## How streaming behaves
112
+
113
+ - A finished block keeps its object, and is keyed by a stable id, so Svelte never re-renders
114
+ it. Only the last, unfinished block changes as text arrives.
115
+ - With `tidy` (on by default), the unfinished end reads as it will. `**bold` shows bold, an
116
+ open code span runs to the end, and a link waiting for its address is drawn as a link
117
+ already, with its words and nowhere to go yet (a `link` node with `pending: true` and an
118
+ empty `url`), so it doesn't turn from text into a link when its address ends. A bare `**`, a
119
+ half-written tag, entity or image, a line that so far is only a marker (`-`, `#`, `1.`) and
120
+ a table's header row before its delimiter row are held back. Text that is complete is never tidied.
121
+ - Blocks that arrive while streaming fade in. A reply that is already written appears at once.
122
+ - Footnotes are numbered as soon as they're referenced. If the finished text never defines one,
123
+ its reference shows as text.
124
+
125
+ Don't throttle to whole paragraphs to avoid flicker: the tidy step does that job. Batching
126
+ updates to about once per frame (or every 50 ms) is still worthwhile for very fast streams.
127
+
128
+ `streaming` may turn off and on again, for a reply that pauses for a tool call and carries on:
129
+ text that continues the old value is still read from where it stopped.
130
+
131
+ ## First-party plugins
132
+
133
+ Three plugins ship on their own entry points, so an app only loads what it imports. Create the
134
+ plugin array once and reuse it: in a module script, or in the component's script when a plugin
135
+ needs the component's state. Never write a new array in the markup:
136
+
137
+ ```svelte
138
+ <script lang="ts" module>
139
+ import { diagrams } from '@diegopluna/narvi/markdown/diagrams';
140
+ import { highlight } from '@diegopluna/narvi/markdown/highlight';
141
+ import { math } from '@diegopluna/narvi/markdown/math';
142
+
143
+ const plugins = [highlight(), math(), diagrams()];
144
+ </script>
145
+
146
+ <script lang="ts">
147
+ import { Markdown } from '@diegopluna/narvi';
148
+
149
+ let { text, done }: { text: string; done: boolean } = $props();
150
+ </script>
151
+
152
+ <Markdown value={text} streaming={!done} {plugins} />
153
+ ```
154
+
155
+ - **`highlight()`** colours code in 152 languages with `@pierre/highlights`. A block that
156
+ streams is tokenized line by line as it arrives, never from the top again. Code takes Narvi's
157
+ syntax colours by default. Pass `highlight({ themes: { light, dark } })` with Zed-compatible
158
+ themes (for example from `@pierre/highlights/themes`) to use an editor theme. Importing the
159
+ module loads about 150 KB (gzipped) of WebAssembly. To keep it out of the first load, import
160
+ it in the browser and add it to the plugins once, when it arrives (see below).
161
+ - **`math()`** turns on formulas (`$x$`, `$$x$$`, `\(x\)`, `\[x\]` and a fenced `math` block)
162
+ and typesets them with KaTeX, which loads on the first formula. Prices and shell variables
163
+ stay text: "It costs $5 and $10" and `$HOME/bin:$PATH` are not formulas, and in "$5 and $10,
164
+ with $n$ tries" only `$n$` is one. A formula shows as
165
+ its TeX source until it closes, and when KaTeX can't read it. A `$$` or `\[` on a line of its
166
+ own that meets a blank line before its closing delimiter was not a formula, and is text.
167
+ `\[a-z\]` is a regex's escaped brackets, and `f\(x\)` is "f(x)". Without this plugin, a
168
+ dollar sign is always text.
169
+ - **`diagrams()`** draws a fenced `mermaid` block as a diagram, with Pele, in Narvi's colours.
170
+ It draws once the fence closes, offers the code and a full-size view that pans and zooms,
171
+ and says why when a diagram can't be drawn.
172
+
173
+ Two more are for replies from coding agents:
174
+
175
+ ```ts
176
+ import { files } from '@diegopluna/narvi/markdown/files';
177
+ import { images } from '@diegopluna/narvi/markdown/images';
178
+
179
+ declare const tree: { find(path: string): string | null };
180
+ declare const editor: { open(path: string, line?: number): void };
181
+
182
+ export const plugins = [
183
+ files({
184
+ // Says which paths are real files, and returns them as the app wants them
185
+ resolve: (path) => tree.find(path),
186
+ open: (file) => editor.open(file.path, file.line)
187
+ }),
188
+ // No image loads unasked unless `allow` says so
189
+ images({ allow: (url) => url.startsWith('https://cdn.example.com/') })
190
+ ];
191
+ ```
192
+
193
+ - **`files()`** turns inline code that names a file into a chip: `src/app.ts`,
194
+ `src/app.ts:42`, `src/app.ts:42:7`, `src/app.ts:42-50` and `src/app.ts#L42-L50`. A Markdown
195
+ link whose address is a file path, with or without a `#L10` fragment, becomes a chip too.
196
+ It keeps the link's words when they're prose ("the config") or name that file; one word, or
197
+ words that name another file, are replaced by the real name, so a chip can't claim to be a
198
+ file it isn't. A chip made from code shows the file's name and the place in it (`app.ts:42`),
199
+ and has the whole path as its title. A path that leaves the project (`../x`, `~/x`) is shown
200
+ whole. Network shares, paths that start with `-`, and paths with invisible characters never
201
+ become chips. With `open` it's a button that calls
202
+ `open(file, event)`, where `file` is `{ path, line?, column?, endLine? }`. With `resolve`,
203
+ every inline code without spaces is asked, so a bare `package.json` can be found, and a path
204
+ it returns null for stays code. `resolve` receives the path without its `:42` or `#L42`, and
205
+ what it returns becomes `file.path`.
206
+ Without `resolve`, only text that looks like a path becomes a chip: "and/or", `v1.2.3` and
207
+ `github.com/owner/repo` don't.
208
+ - **`images()`** holds an image the app hasn't allowed: it shows as a button that names the
209
+ image's host, and loads when pressed. By default no image loads unasked, not even one from
210
+ the app's own site, since that's a request with the person's cookies. To let the app's own
211
+ site through, pass `images({ allow: sameOrigin })`, with `sameOrigin` from the same module.
212
+ `allow` is given the address as written; the app's `links.image` still decides which
213
+ addresses may load at all, and can send them through a proxy.
214
+ Use it whenever the Markdown comes from a model or from other people, since an image is
215
+ requested as soon as it's shown. An `<img>` in raw HTML is held behind the same button. The
216
+ button reads "Load image from" and the host; reword it with the `loadImage` label.
217
+
218
+ An app that serves its own images (attachments, screenshots an agent took) should allow
219
+ only where they live, not its whole site. Resolve the address first, so `..` can't walk out
220
+ of the folder:
221
+
222
+ ```ts
223
+ import { images } from '@diegopluna/narvi/markdown/images';
224
+
225
+ export const ownImages = images({
226
+ allow(url) {
227
+ const to = new URL(url, location.href);
228
+ return to.origin === location.origin && to.pathname.startsWith('/attachments/');
229
+ }
230
+ });
231
+ ```
232
+
233
+ `url.startsWith('/attachments/')` alone would let `/attachments/../api/logout` through.
234
+
235
+ Tables need no plugin: each has a button, shown on hover or focus, that copies it as Markdown
236
+ or CSV or saves a CSV file. In the CSV, a cell a spreadsheet would run as a formula (one that
237
+ starts with `=`, `+`, `-` or `@`) is written as text. `tableToCsv` and `tableToMarkdown` from
238
+ `@diegopluna/narvi/markdown` do the same for a `table` node.
239
+
240
+ When a plugin needs the component's state, or should load late, build the array in the
241
+ component's script. A new array of the same plugin objects changes nothing, but a new plugin
242
+ object (calling `highlight()` again) transforms and draws the document again, so make each
243
+ plugin once. Hold the array in `$state.raw` or a plain `const`, never in deep `$state`, which
244
+ wraps each plugin in a proxy that is a new object to the cache:
245
+
246
+ ```svelte
247
+ <script lang="ts">
248
+ import { Markdown } from '@diegopluna/narvi';
249
+ import type { MarkdownPlugin } from '@diegopluna/narvi/markdown';
250
+ import { files } from '@diegopluna/narvi/markdown/files';
251
+
252
+ let { text }: { text: string } = $props();
253
+ let opened = $state<string[]>([]);
254
+
255
+ // Made once, when the component is: the callback can use the component's state
256
+ const base: MarkdownPlugin[] = [files({ open: (file) => opened.push(file.path) })];
257
+ let plugins = $state.raw(base);
258
+
259
+ // The highlighter joins once, after the page has loaded. `$effect` runs in the browser only
260
+ $effect(() => {
261
+ void import('@diegopluna/narvi/markdown/highlight').then(({ highlight }) => {
262
+ plugins = [highlight(), ...base];
263
+ });
264
+ });
265
+ </script>
266
+
267
+ <Markdown value={text} {plugins} />
268
+ ```
269
+
270
+ ## Writing plugins
271
+
272
+ `plugins` takes `MarkdownPlugin` objects. A plugin can rewrite blocks after they're parsed
273
+ (`transform`, with `mapText` and `mapInlines`), draw a node type or a node of its own with a
274
+ Svelte component (`components`), draw a fenced language (`languages`), colour code
275
+ (`highlight`, `highlightStream`), decide links and images (`links`), and say how to write its
276
+ nodes as markup for `static` (`static`). Where two plugins overlap, the later one wins, one
277
+ piece at a time; transforms all run, in order.
278
+
279
+ Read the [plugin reference](references/plugins.md) before writing one. It's also at
280
+ `node_modules/@diegopluna/narvi/skills/markdown/references/plugins.md`.
281
+
282
+ Replace Narvi's rendering with a plugin, never by patching the rendered DOM with a
283
+ `MutationObserver`. Svelte owns those nodes, and edits made from outside are lost or break the
284
+ next update.
285
+
286
+ ## Links, images and raw HTML
287
+
288
+ The default policy allows links to `http:`, `https:`, `mailto:`, `tel:` and addresses without a
289
+ scheme, and images from `http:`, `https:` and addresses without a scheme. A refused link shows
290
+ as its text; a refused image shows its alt text. Links to another origin open in a new tab.
291
+ When a link's words read as an address on one site and the link goes to another, the real host
292
+ is shown after the words, and a tooltip that names the other site is dropped.
293
+
294
+ **In a desktop app** (a page on `file:` or a scheme of its own, not `http:` or `https:`), an
295
+ address without a scheme is a file on the machine, and following it would load that file in
296
+ the app's window. There the default policy shows such a link as text, unless a plugin gives
297
+ `links.open` (then the app decides where it goes) or its own `links.href`. Links to a heading
298
+ of the same document always work. For links to files, use `files()`.
299
+
300
+ An address is judged as a browser will read it: tabs and line endings anywhere in it and
301
+ control characters at its ends are dropped first, so `java&#9;script:` in raw HTML is refused
302
+ like `javascript:`. `//host/path` is allowed only when the page itself is on `http:` or
303
+ `https:`, and an address that starts with backslashes never is, so a reply can't reach a
304
+ network share from a desktop app. When you write your own `links.href` or `links.image`, ask
305
+ `readUrl` where the address goes instead of testing how it starts:
306
+
307
+ ```ts
308
+ import { readUrl, type MarkdownPlugin } from '@diegopluna/narvi/markdown';
309
+
310
+ const ownSiteOnly: MarkdownPlugin = {
311
+ name: 'own-site-only',
312
+ links: {
313
+ // `kind` is 'relative', 'network' (`//host`), 'scheme' or 'unsafe'
314
+ href(url) {
315
+ const read = readUrl(url);
316
+ return read.kind === 'relative' ? read.url : null;
317
+ }
318
+ }
319
+ };
320
+ ```
321
+
322
+ Your function is handed the address already read that way, and a `javascript:` address is
323
+ refused whatever it returns. A test like `url.startsWith('/')` still lets `//evil.example` and `/\evil.example`
324
+ through. Test `readUrl(url).kind`, or parse the address with `new URL(url, location.href)` and
325
+ compare its `origin`.
326
+
327
+ To open links yourself (in the app's router, a side panel or an in-app browser), give
328
+ `links.open`. It's called on click, before the browser follows the link, with the address
329
+ that `links.href` returned (as written in the Markdown, unless your policy changed it). Links
330
+ to another origin open in a new tab; `event.preventDefault()` stops that too:
331
+
332
+ ```ts
333
+ import { readUrl, type MarkdownPlugin } from '@diegopluna/narvi/markdown';
334
+
335
+ declare function navigate(href: string): void;
336
+
337
+ const router: MarkdownPlugin = {
338
+ name: 'router',
339
+ links: {
340
+ open(href, event) {
341
+ // Only addresses on this site; `//host` is another one, though it starts with `/`
342
+ if (readUrl(href).kind !== 'relative') return; // let the browser follow the rest
343
+ event.preventDefault();
344
+ navigate(href);
345
+ }
346
+ }
347
+ };
348
+ ```
349
+
350
+ **A remote image is requested as soon as it's shown**, so text from a model can send data
351
+ out through an image's address. When rendering model output, decide which hosts load:
352
+
353
+ ```ts
354
+ import type { MarkdownPlugin } from '@diegopluna/narvi/markdown';
355
+
356
+ const safeImages: MarkdownPlugin = {
357
+ name: 'safe-images',
358
+ links: {
359
+ image: (url) => (url.startsWith('https://images.example.com/') ? url : null)
360
+ }
361
+ };
362
+ ```
363
+
364
+ Raw HTML goes through an allowlist and becomes real elements. HTML blocks are joined with the
365
+ Markdown they wrap, so the body of a `<details>` renders inside it. Formatting, tables, `details`,
366
+ `kbd`, `mark`, `img`, `video` and `a` stay; `style`, `class`, `id`, `name`, `on*` handlers, scripts,
367
+ iframes and forms are dropped. The same policy checks addresses in `href` and `src`. A tag that
368
+ isn't HTML, such as `<T>` or `<MyComponent>` in a sentence about code, shows as the text it was
369
+ written as.
370
+
371
+ Input can't hang the page: nesting stops at 64 levels of quotes and lists and 32 of emphasis
372
+ and links, a table at 128 columns, and a formula at 10,000 characters; a document's formulas
373
+ share a limit on how much they draw. Past a limit the text shows as written.
374
+
375
+ A `<video>` is drawn by the image component, as an `<img>` is: its node is an `image` with
376
+ `video: true` and the address of the video or of its first `<source>`. So `images()` holds it
377
+ behind the same button ("Load video from"), and a component you register for `image` receives
378
+ it. Shown, it has controls and fetches nothing until it's played; `autoplay`, `poster` and
379
+ `loop` are dropped. A transform can mark an image as a video itself, for a link to an `.mp4`,
380
+ by returning the image node with `video: true`.
381
+
382
+ In a code block, control characters and direction overrides are drawn as what they are (`␛`,
383
+ `⟨U+202E⟩`), so code can't read one way and run another, and the copy button leaves control
384
+ characters out.
385
+
386
+ ## Without the component
387
+
388
+ `@diegopluna/narvi/markdown` exports the engine:
389
+
390
+ ```ts
391
+ import { MarkdownStream, parse, toHtml } from '@diegopluna/narvi/markdown';
392
+
393
+ const doc = parse('# Hello\n\nSome *text*.');
394
+ const withMath = parse('Area $\\pi r^2$.', { math: true }); // options: gfm (on), math, singleTilde (off)
395
+ const file = parse('---\ntitle: Doors\n---\n# Hello', { frontmatter: true });
396
+ file.frontmatter; // 'title: Doors', as written: parse the YAML yourself
397
+ const html = toHtml(doc); // as the specs have it: raw HTML and any address pass through
398
+ const safe = toHtml(doc, { rawHtml: false, safeLinks: true }); // for text you don't trust
399
+
400
+ const stream = new MarkdownStream();
401
+ stream.append('Some **bo');
402
+ stream.snapshot({ tidy: true }); // the document so far, with the end tidied
403
+ stream.snapshot({ final: true }); // read as all there is, without ending the stream
404
+ stream.append('ld** text');
405
+ stream.finish(); // the final document
406
+ ```
407
+
408
+ ## Common mistakes
409
+
410
+ - **HIGH: passing only the latest chunk as `value`.** The component expects all the text so
411
+ far, so it shows only the chunk.
412
+ - **HIGH: rendering model output with `{@html}` or another Markdown library.** It loses
413
+ sanitising, stable blocks and tidy streaming. Use `Markdown`.
414
+ - **HIGH: leaving the default image policy on untrusted text.** Images load as soon as
415
+ they're shown. For model output, add `images()`, which makes them wait for a click, or set
416
+ `links.image` yourself. Either is enough.
417
+ - **HIGH: writing math without the `math()` plugin, or expecting `$5` to break with it.**
418
+ Formulas are off by default. With the plugin, a single dollar opens a formula only when no
419
+ space or comma follows it, a closing dollar is on the same line, and no letter or digit
420
+ follows that.
421
+ - **HIGH: making file paths clickable by patching the DOM, or by rewriting them into links.**
422
+ Use `files({ resolve, open })`. A Markdown link to a relative file path would otherwise
423
+ navigate the app to that path.
424
+ - **HIGH: testing how an address starts in your own link policy** (`url.startsWith('/')`,
425
+ `url.startsWith('https://cdn.example.com')`). `//evil.example`, `/\evil.example` and
426
+ `https://cdn.example.com.evil.example` pass those. Use `readUrl(url).kind`, or compare the
427
+ `origin` of `new URL(url, location.href)`.
428
+ - **MEDIUM: expecting relative links to work in a desktop app without `links.open`.** Off the
429
+ web they show as text by default. Give `links.open` and route them yourself.
430
+ - **MEDIUM: making new plugin objects on every render** (`plugins={[highlight()]}` in the
431
+ markup, or the array in deep `$state`). The caches are per plugin object, so every block is
432
+ transformed and highlighted again. Create each plugin once, in the module script or the
433
+ component's script, and hold the array in a `const` or `$state.raw`.
434
+ - **HIGH: writing a node's text into a `static` writer without `tools.escape`.** The markup is
435
+ put on the page as written, so text from a model would be read as markup. Escape every
436
+ value, including attribute values.
437
+ - **MEDIUM: turning `static` on the moment a reply finishes streaming.** Its blocks would be
438
+ drawn again, as markup this time. Leave `static` out: Narvi decides it once per reply, by
439
+ whether the text was whole when the component was made.
440
+ - **MEDIUM: reading a code block's text with `innerText` while it is off the screen.** Code
441
+ that is off the screen is not laid out yet, and `innerText` leaves out text that is not
442
+ laid out. Use `textContent`, or the text you gave `value`.
443
+ - **MEDIUM: turning `breaks` on for model output.** Models wrap lines in the middle of
444
+ sentences. It's for text a person typed.
445
+ - **MEDIUM: setting the task box in the DOM.** Change the text at `item.checkedAt + 1` in
446
+ `ontaskchange` and pass it back as `value`; the box follows the text.
447
+
448
+ ## Completion
449
+
450
+ A streamed reply shows formatting as it arrives, without raw `**` or table pipes flashing, and
451
+ when it finishes, nothing on the page jumps. A link with a `javascript:` address renders as
452
+ text, and an image from a host you didn't allow shows its alt text.
@@ -0,0 +1,103 @@
1
+ # Writing a Markdown plugin
2
+
3
+ For `<Markdown plugins={[…]}>` from `@diegopluna/narvi`. Read the `markdown` skill first: this
4
+ is the reference for the plugin object itself.
5
+
6
+ `plugins` takes `MarkdownPlugin` objects. Where two overlap, the later one wins, one piece at
7
+ a time: one component, one language, one function of `links`. So a plugin that sets only
8
+ `links.open` keeps another plugin's `links.image`. Transforms don't overlap: they all run, in order.
9
+
10
+ ```ts
11
+ import { mapText, type MarkdownPlugin } from '@diegopluna/narvi/markdown';
12
+
13
+ // `@thread:12` becomes a link to that thread
14
+ export const threadLinks: MarkdownPlugin = {
15
+ name: 'thread-links',
16
+ transform: (block) =>
17
+ mapText(block, (value) => {
18
+ if (!value.includes('@thread:')) return null;
19
+ return value.split(/(@thread:\d+)/).map((part) => {
20
+ const m = part.match(/^@thread:(\d+)$/);
21
+ return m
22
+ ? {
23
+ type: 'link',
24
+ url: `/threads/${m[1]}`,
25
+ title: null,
26
+ kind: 'literal',
27
+ children: [{ type: 'text', value: `Thread ${m[1]}` }]
28
+ }
29
+ : { type: 'text', value: part };
30
+ });
31
+ })
32
+ };
33
+ ```
34
+
35
+ - `transform(block, document)` rewrites a block after it's parsed. It's called for the blocks
36
+ that hold text or code (paragraphs, headings, tables, code blocks), wherever they're nested,
37
+ and never for the lists, items and quotes around them. A finished block keeps its object, so
38
+ it's transformed once. Return the same block to change nothing. `mapText` is a helper for
39
+ rewriting text nodes that skips code, links and images.
40
+ - `components` replaces Narvi's component for a node type: `{ inlineCode: FileChip }`. The
41
+ component receives `{ node, children }`, where `children` is a snippet that renders the
42
+ node's contents as Narvi would. Node types are `paragraph`, `heading`, `list`, `code`,
43
+ `table`, `blockquote`, `thematicBreak`, `html`, `text`, `strong`, `emphasis`, `delete`,
44
+ `inlineCode`, `link`, `image`, `break`, `softBreak` and `footnoteReference`, plus `math` and
45
+ `inlineMath` with formula syntax on, and any type your transform adds.
46
+ - A plugin that throws takes down only its own part. A component that throws falls back to
47
+ Narvi's drawing of that node, a transform that throws is skipped, a highlighter that throws
48
+ leaves the code plain, and a `links` function that throws refuses the link or image.
49
+ - `highlight(code, lang)` returns lines of `{ text, kind }` tokens, or null for plain code.
50
+ The kinds Narvi colours are `keyword`, `string`, `number`, `constant`, `comment`,
51
+ `function`, `type`, `property`, `tag`, `attribute`, `punctuation`, `operator`, `inserted`
52
+ and `deleted`.
53
+ - `highlightStream(lang)` returns `{ push(chunk), end(), dispose() }` for code that arrives in
54
+ pieces, or null for a language it doesn't know. Without it, a streaming block is highlighted
55
+ once its fence closes.
56
+ - `languages` gives a component for fenced code in a language: `{ mermaid: Diagram }`. It
57
+ takes over once the fence has closed and receives `{ node }`, a `code` node with `lang`,
58
+ `meta` and `value`.
59
+ - `syntax: { math: true }` turns on formula syntax, which adds `math` and `inlineMath` nodes.
60
+ - A transform can add its own inline node: `{ type: 'custom', name: 'mention', data: {…},
61
+ children: [] }`. The component registered under that `name` in `components` draws it and
62
+ receives `{ node, children }`. `mapInlines(block, (node, { inLink }) => …)` visits every inline
63
+ node; `mapText` is the same for text only.
64
+ - `static` says how to write a node your plugin draws as markup, for text that is written
65
+ as markup (text that was whole when it was first shown, unless `static={false}`). Without
66
+ it, a block that holds your node is built from parts, which is correct and slower. It is used only while your component is the one that draws the node:
67
+
68
+ ```ts
69
+ import type { InlineCustom, MarkdownPlugin } from '@diegopluna/narvi/markdown';
70
+ import Mention from './Mention.svelte';
71
+
72
+ declare function openProfile(who: string): void;
73
+
74
+ export const mentions: MarkdownPlugin = {
75
+ name: 'mentions',
76
+ components: { mention: Mention },
77
+ static: {
78
+ mention: {
79
+ // `tools.part` marks the element whose clicks come back to `click`
80
+ html: (node: InlineCustom, tools) =>
81
+ `<button type="button"${tools.part} data-who="${tools.escape(String(node.data.who))}">` +
82
+ `@${tools.escape(String(node.data.who))}</button>`,
83
+ click: (element) => openProfile(element.dataset.who!)
84
+ }
85
+ }
86
+ };
87
+ ```
88
+
89
+ What `html` returns is put on the page as it is. Put every piece of text and every
90
+ attribute value from the node through `tools.escape`, and write the same elements your
91
+ component draws. Return null for a node only the component can draw.
92
+
93
+ - `withProps(Component, props)` registers a component with extra props:
94
+ `components: { mention: withProps(Mention, { onopen }) }`.
95
+ - Give an element `data-markdown-copy="…"` to say what a copy of it holds. That's how a formula
96
+ copies as its TeX and a file chip as its path. `Markdown` handles copies that start inside
97
+ it. For a selection that starts above a reply and runs into it, put the same handler on what
98
+ holds the conversation: `<div oncopy={copyAsWritten}>`, from `@diegopluna/narvi`.
99
+ - `links` is the policy for links and images (below).
100
+
101
+ Replace Narvi's rendering with a plugin, never by patching the rendered DOM with a
102
+ `MutationObserver`. Svelte owns those nodes, and edits made from outside are lost or break the
103
+ next update.