@diegopluna/narvi 0.0.2 → 0.2.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.
- package/README.md +116 -44
- package/dist/base.css +96 -0
- package/dist/color.d.ts +1 -1
- package/dist/color.js +1 -1
- package/dist/components/activity/ActivityContent.svelte +3 -15
- package/dist/components/activity/ActivityStep.svelte +12 -12
- package/dist/components/activity/ActivityThought.svelte +4 -4
- package/dist/components/activity/ActivityTrigger.svelte +5 -6
- package/dist/components/app-shell/AppShellBar.svelte +89 -0
- package/dist/components/app-shell/AppShellBar.svelte.d.ts +20 -0
- package/dist/components/app-shell/AppShellHeader.svelte +17 -17
- package/dist/components/app-shell/AppShellHeader.svelte.d.ts +2 -2
- package/dist/components/app-shell/AppShellMain.svelte +4 -20
- package/dist/components/app-shell/AppShellPanel.svelte +21 -19
- package/dist/components/app-shell/AppShellPanes.svelte +58 -0
- package/dist/components/app-shell/AppShellPanes.svelte.d.ts +11 -0
- package/dist/components/app-shell/AppShellRail.svelte +85 -0
- package/dist/components/app-shell/AppShellRail.svelte.d.ts +11 -0
- package/dist/components/app-shell/AppShellRoot.svelte +50 -24
- package/dist/components/app-shell/AppShellRoot.svelte.d.ts +8 -6
- package/dist/components/app-shell/AppShellSheet.svelte +95 -0
- package/dist/components/app-shell/AppShellSheet.svelte.d.ts +17 -0
- package/dist/components/app-shell/AppShellSidebar.svelte +41 -65
- package/dist/components/app-shell/AppShellSidebar.svelte.d.ts +1 -5
- package/dist/components/app-shell/AppShellToggle.svelte +62 -23
- package/dist/components/app-shell/AppShellToggle.svelte.d.ts +2 -0
- package/dist/components/app-shell/context.d.ts +6 -0
- package/dist/components/app-shell/index.d.ts +9 -1
- package/dist/components/app-shell/index.js +5 -1
- package/dist/components/approval/Approval.svelte +99 -23
- package/dist/components/approval/Approval.svelte.d.ts +7 -0
- package/dist/components/avatar/AvatarFallback.svelte +1 -2
- package/dist/components/avatar/AvatarRoot.svelte +2 -2
- package/dist/components/badge/Badge.svelte +5 -5
- package/dist/components/button/Button.svelte +227 -51
- package/dist/components/button/Button.svelte.d.ts +38 -2
- package/dist/components/card/Card.svelte +19 -33
- package/dist/components/change-stats/ChangeStats.svelte +1 -2
- package/dist/components/changes-summary/ChangesSummary.svelte +14 -15
- package/dist/components/checkbox/Checkbox.svelte +31 -25
- package/dist/components/checkbox/Checkbox.svelte.d.ts +5 -0
- package/dist/components/code/Code.svelte +1 -2
- package/dist/components/collapsible/CollapsibleContent.svelte +38 -0
- package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +11 -0
- package/dist/components/collapsible/CollapsibleRoot.svelte +44 -0
- package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +11 -0
- package/dist/components/collapsible/CollapsibleTrigger.svelte +83 -0
- package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +13 -0
- package/dist/components/collapsible/context.d.ts +5 -0
- package/dist/components/collapsible/context.js +11 -0
- package/dist/components/collapsible/index.d.ts +7 -0
- package/dist/components/collapsible/index.js +4 -0
- package/dist/components/command/CommandItem.svelte +1 -1
- package/dist/components/command/styles.d.ts +3 -2
- package/dist/components/command/styles.js +15 -12
- package/dist/components/composer/ComposerAttachButton.svelte +1 -1
- package/dist/components/composer/ComposerAttachment.svelte +13 -18
- package/dist/components/composer/ComposerModelPicker.svelte +24 -28
- package/dist/components/composer/ComposerRoot.svelte +15 -13
- package/dist/components/composer/ComposerSubmit.svelte +12 -20
- package/dist/components/composer/ComposerTextarea.svelte +1 -1
- package/dist/components/composer/ComposerToggle.svelte +16 -18
- package/dist/components/composer/ComposerTray.svelte +78 -0
- package/dist/components/composer/ComposerTray.svelte.d.ts +15 -0
- package/dist/components/composer/index.d.ts +3 -1
- package/dist/components/composer/index.js +3 -2
- package/dist/components/conversation/ConversationContent.svelte +3 -2
- package/dist/components/conversation/ConversationEmpty.svelte +1 -1
- package/dist/components/conversation/ConversationScrollButton.svelte +9 -11
- package/dist/components/dialog/ConfirmDialog.svelte +1 -1
- package/dist/components/dialog/DialogContent.svelte +5 -1
- package/dist/components/dialog/styles.d.ts +2 -26
- package/dist/components/dialog/styles.js +12 -49
- package/dist/components/divider/Divider.svelte +3 -3
- package/dist/components/empty-state/EmptyState.svelte +4 -5
- package/dist/components/field/Field.svelte +4 -4
- package/dist/components/frame/Frame.svelte +6 -7
- package/dist/components/frame/Frame.svelte.d.ts +1 -1
- package/dist/components/grid/Grid.svelte +111 -0
- package/dist/components/grid/Grid.svelte.d.ts +27 -0
- package/dist/components/heading/Heading.svelte +2 -2
- package/dist/components/hover-card/HoverCardContent.svelte +50 -0
- package/dist/components/hover-card/HoverCardContent.svelte.d.ts +10 -0
- package/dist/components/hover-card/HoverCardRoot.svelte +22 -0
- package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -0
- package/dist/components/hover-card/index.d.ts +7 -0
- package/dist/components/hover-card/index.js +7 -0
- package/dist/components/kbd/Kbd.svelte +12 -7
- package/dist/components/link/Link.svelte +9 -7
- package/dist/components/link/Link.svelte.d.ts +4 -1
- package/dist/components/markdown/Markdown.svelte +714 -0
- package/dist/components/markdown/Markdown.svelte.d.ts +80 -0
- package/dist/components/markdown/MarkdownBlock.svelte +231 -0
- package/dist/components/markdown/MarkdownBlock.svelte.d.ts +11 -0
- package/dist/components/markdown/MarkdownBlocks.svelte +115 -0
- package/dist/components/markdown/MarkdownBlocks.svelte.d.ts +15 -0
- package/dist/components/markdown/MarkdownCode.svelte +583 -0
- package/dist/components/markdown/MarkdownCode.svelte.d.ts +23 -0
- package/dist/components/markdown/MarkdownDiagram.svelte +310 -0
- package/dist/components/markdown/MarkdownDiagram.svelte.d.ts +6 -0
- package/dist/components/markdown/MarkdownFile.svelte +134 -0
- package/dist/components/markdown/MarkdownFile.svelte.d.ts +19 -0
- package/dist/components/markdown/MarkdownFootnotes.svelte +61 -0
- package/dist/components/markdown/MarkdownFootnotes.svelte.d.ts +8 -0
- package/dist/components/markdown/MarkdownFresh.svelte +69 -0
- package/dist/components/markdown/MarkdownFresh.svelte.d.ts +6 -0
- package/dist/components/markdown/MarkdownHtml.svelte +72 -0
- package/dist/components/markdown/MarkdownHtml.svelte.d.ts +7 -0
- package/dist/components/markdown/MarkdownImage.svelte +150 -0
- package/dist/components/markdown/MarkdownImage.svelte.d.ts +8 -0
- package/dist/components/markdown/MarkdownInlines.svelte +225 -0
- package/dist/components/markdown/MarkdownInlines.svelte.d.ts +7 -0
- package/dist/components/markdown/MarkdownLink.svelte +120 -0
- package/dist/components/markdown/MarkdownLink.svelte.d.ts +25 -0
- package/dist/components/markdown/MarkdownMath.svelte +138 -0
- package/dist/components/markdown/MarkdownMath.svelte.d.ts +7 -0
- package/dist/components/markdown/MarkdownTable.svelte +265 -0
- package/dist/components/markdown/MarkdownTable.svelte.d.ts +17 -0
- package/dist/components/markdown/caret.d.ts +14 -0
- package/dist/components/markdown/caret.js +67 -0
- package/dist/components/markdown/context.d.ts +93 -0
- package/dist/components/markdown/context.js +128 -0
- package/dist/components/markdown/copy.d.ts +13 -0
- package/dist/components/markdown/copy.js +74 -0
- package/dist/components/markdown/hidden.d.ts +12 -0
- package/dist/components/markdown/hidden.js +31 -0
- package/dist/components/markdown/kept.d.ts +32 -0
- package/dist/components/markdown/kept.js +71 -0
- package/dist/components/markdown/labels.d.ts +46 -0
- package/dist/components/markdown/labels.js +35 -0
- package/dist/components/markdown/save.d.ts +11 -0
- package/dist/components/markdown/save.js +58 -0
- package/dist/components/markdown/scrollable.d.ts +24 -0
- package/dist/components/markdown/scrollable.js +152 -0
- package/dist/components/markdown/static.d.ts +37 -0
- package/dist/components/markdown/static.js +233 -0
- package/dist/components/markdown/styles.d.ts +328 -0
- package/dist/components/markdown/styles.js +302 -0
- package/dist/components/menu/MenuRadioItem.svelte +3 -3
- package/dist/components/menu/index.d.ts +23 -0
- package/dist/components/menu/index.js +3 -1
- package/dist/components/message/MessageAction.svelte +24 -5
- package/dist/components/message/MessageAction.svelte.d.ts +9 -0
- package/dist/components/message/MessageActions.svelte +2 -3
- package/dist/components/message/MessageContent.svelte +2 -3
- package/dist/components/message/MessageCopy.svelte +66 -8
- package/dist/components/message/MessageCopy.svelte.d.ts +17 -1
- package/dist/components/message/MessageHeader.svelte +3 -3
- package/dist/components/message/MessagePending.svelte +1 -1
- package/dist/components/message/MessageRoot.svelte +3 -4
- package/dist/components/message/MessageTime.svelte +3 -4
- package/dist/components/notice/Notice.svelte +14 -10
- package/dist/components/plan/Plan.svelte +25 -21
- package/dist/components/progress/Progress.svelte +34 -38
- package/dist/components/questionnaire/Questionnaire.svelte +19 -22
- package/dist/components/queued-message/QueuedMessage.svelte +14 -7
- package/dist/components/rail/RailItem.svelte +43 -40
- package/dist/components/rail/RailItem.svelte.d.ts +3 -1
- package/dist/components/rail/RailRoot.svelte +18 -4
- package/dist/components/rail/RailRoot.svelte.d.ts +1 -1
- package/dist/components/rail/RailSeparator.svelte +17 -0
- package/dist/components/rail/RailSeparator.svelte.d.ts +18 -0
- package/dist/components/rail/index.d.ts +2 -1
- package/dist/components/rail/index.js +2 -1
- package/dist/components/reasoning/ReasoningContent.svelte +4 -8
- package/dist/components/reasoning/ReasoningTrigger.svelte +4 -5
- package/dist/components/resize-handle/ResizeHandle.svelte +4 -7
- package/dist/components/reveal/Reveal.svelte +89 -0
- package/dist/components/reveal/Reveal.svelte.d.ts +17 -0
- package/dist/components/reveal/revealed.d.ts +38 -0
- package/dist/components/reveal/revealed.js +79 -0
- package/dist/components/segmented/SegmentedControl.svelte +11 -16
- package/dist/components/select/Select.svelte +1 -1
- package/dist/components/separator/Separator.svelte +1 -1
- package/dist/components/settings-row/SettingsRow.svelte +5 -5
- package/dist/components/sheet/SheetContent.svelte +63 -0
- package/dist/components/sheet/SheetContent.svelte.d.ts +18 -0
- package/dist/components/sheet/index.d.ts +12 -0
- package/dist/components/sheet/index.js +12 -0
- package/dist/components/sheet/styles.d.ts +51 -0
- package/dist/components/sheet/styles.js +65 -0
- package/dist/components/shimmer/Shimmer.svelte +41 -26
- package/dist/components/sidebar/SidebarContent.svelte +1 -1
- package/dist/components/sidebar/SidebarFolder.svelte +142 -0
- package/dist/components/sidebar/SidebarFolder.svelte.d.ts +19 -0
- package/dist/components/sidebar/SidebarFooter.svelte +1 -1
- package/dist/components/sidebar/SidebarGroup.svelte +41 -35
- package/dist/components/sidebar/SidebarGroup.svelte.d.ts +3 -3
- package/dist/components/sidebar/SidebarHeader.svelte +12 -6
- package/dist/components/sidebar/SidebarHeader.svelte.d.ts +4 -1
- package/dist/components/sidebar/SidebarItem.svelte +34 -38
- package/dist/components/sidebar/SidebarRoot.svelte +62 -0
- package/dist/components/sidebar/SidebarRoot.svelte.d.ts +14 -0
- package/dist/components/sidebar/index.d.ts +5 -1
- package/dist/components/sidebar/index.js +3 -1
- package/dist/components/skeleton/Skeleton.svelte +26 -15
- package/dist/components/slider/Slider.svelte +200 -0
- package/dist/components/slider/Slider.svelte.d.ts +55 -0
- package/dist/components/spinner/Spinner.svelte +4 -11
- package/dist/components/stack/Stack.svelte +37 -44
- package/dist/components/stack/Stack.svelte.d.ts +12 -6
- package/dist/components/status-indicator/StatusIndicator.svelte +1 -1
- package/dist/components/suggestions/SuggestionsItem.svelte +11 -13
- package/dist/components/switch/Switch.svelte +16 -25
- package/dist/components/tab-strip/TabStrip.svelte +340 -0
- package/dist/components/tab-strip/TabStrip.svelte.d.ts +31 -0
- package/dist/components/tabs/Tabs.svelte +15 -14
- package/dist/components/tabs/Tabs.svelte.d.ts +4 -0
- package/dist/components/text/Text.svelte +64 -14
- package/dist/components/text/Text.svelte.d.ts +13 -3
- package/dist/components/toast/Toaster.svelte +12 -10
- package/dist/components/toggle/Toggle.svelte +40 -0
- package/dist/components/toggle/Toggle.svelte.d.ts +15 -0
- package/dist/components/toggle-group/ToggleGroupItem.svelte +37 -0
- package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +12 -0
- package/dist/components/toggle-group/ToggleGroupRoot.svelte +95 -0
- package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +33 -0
- package/dist/components/toggle-group/context.d.ts +6 -0
- package/dist/components/toggle-group/context.js +11 -0
- package/dist/components/toggle-group/index.d.ts +5 -0
- package/dist/components/toggle-group/index.js +3 -0
- package/dist/components/tool/ToolContent.svelte +3 -8
- package/dist/components/tool/ToolSection.svelte +4 -5
- package/dist/components/tool/ToolTrigger.svelte +14 -15
- package/dist/components/tooltip/TooltipContent.svelte +9 -6
- package/dist/components/work-fold/WorkFold.svelte +17 -34
- package/dist/components/work-fold/WorkFold.svelte.d.ts +1 -1
- package/dist/index.d.ts +38 -10
- package/dist/index.js +38 -12
- package/dist/internal/Chevron.svelte +2 -3
- package/dist/internal/Code.svelte +3 -4
- package/dist/internal/Collapse.svelte +6 -5
- package/dist/internal/Collapse.svelte.d.ts +2 -1
- package/dist/internal/Glyph.svelte +16 -0
- package/dist/internal/Glyph.svelte.d.ts +6 -0
- package/dist/internal/Tile.svelte +17 -37
- package/dist/internal/control.d.ts +4 -4
- package/dist/internal/control.js +21 -18
- package/dist/internal/layer.d.ts +3 -5
- package/dist/internal/layer.js +14 -18
- package/dist/internal/layout.d.ts +13 -0
- package/dist/internal/layout.js +453 -0
- package/dist/internal/markers.stylex.d.ts +8 -0
- package/dist/internal/markers.stylex.js +4 -0
- package/dist/internal/plugin-order.d.ts +8 -0
- package/dist/internal/plugin-order.js +16 -0
- package/dist/internal/responsive.d.ts +45 -0
- package/dist/internal/responsive.js +42 -0
- package/dist/internal/roving.js +5 -2
- package/dist/internal/shared.d.ts +8 -1
- package/dist/internal/shared.js +21 -5
- package/dist/internal/sx.d.ts +31 -4
- package/dist/internal/sx.js +17 -0
- package/dist/internal/toggle.d.ts +73 -0
- package/dist/internal/toggle.js +83 -0
- package/dist/internal/visible.d.ts +32 -0
- package/dist/internal/visible.js +44 -0
- package/dist/markdown/ast.d.ts +209 -0
- package/dist/markdown/ast.js +10 -0
- package/dist/markdown/blocks.d.ts +177 -0
- package/dist/markdown/blocks.js +1489 -0
- package/dist/markdown/code-info.d.ts +10 -0
- package/dist/markdown/code-info.js +16 -0
- package/dist/markdown/common.d.ts +25 -0
- package/dist/markdown/common.js +107 -0
- package/dist/markdown/diagrams.d.ts +2 -0
- package/dist/markdown/diagrams.js +18 -0
- package/dist/markdown/file-paths.d.ts +29 -0
- package/dist/markdown/file-paths.js +80 -0
- package/dist/markdown/files.d.ts +16 -0
- package/dist/markdown/files.js +133 -0
- package/dist/markdown/highlight.d.ts +30 -0
- package/dist/markdown/highlight.js +127 -0
- package/dist/markdown/html.d.ts +23 -0
- package/dist/markdown/html.js +289 -0
- package/dist/markdown/images.d.ts +15 -0
- package/dist/markdown/images.js +45 -0
- package/dist/markdown/index.d.ts +12 -0
- package/dist/markdown/index.js +5 -0
- package/dist/markdown/inlines.d.ts +48 -0
- package/dist/markdown/inlines.js +1714 -0
- package/dist/markdown/math.d.ts +2 -0
- package/dist/markdown/math.js +22 -0
- package/dist/markdown/parse.d.ts +81 -0
- package/dist/markdown/parse.js +204 -0
- package/dist/markdown/plugin.d.ts +178 -0
- package/dist/markdown/plugin.js +160 -0
- package/dist/markdown/sanitize.d.ts +78 -0
- package/dist/markdown/sanitize.js +522 -0
- package/dist/markdown/share.d.ts +12 -0
- package/dist/markdown/share.js +59 -0
- package/dist/markdown/table.d.ts +13 -0
- package/dist/markdown/table.js +60 -0
- package/dist/media.stylex.d.ts +52 -0
- package/dist/media.stylex.js +53 -0
- package/dist/preset.d.ts +40 -16
- package/dist/preset.js +169 -51
- package/dist/tokens.stylex.d.ts +70 -37
- package/dist/tokens.stylex.js +127 -62
- package/dist/typography.d.ts +48 -0
- package/dist/typography.js +55 -0
- package/dist/vite.d.ts +9 -1
- package/dist/vite.js +37 -4
- package/package.json +58 -6
- package/skills/building-ui/SKILL.md +242 -0
- package/skills/building-ui/references/components.md +207 -0
- package/skills/markdown/SKILL.md +452 -0
- package/skills/markdown/references/plugins.md +103 -0
- package/skills/setup/SKILL.md +191 -0
- package/skills/styling/SKILL.md +269 -0
- package/skills/theming/SKILL.md +184 -0
- package/dist/internal/loop.d.ts +0 -35
- package/dist/internal/loop.js +0 -72
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
import type { ListItem } from '../../markdown/ast.js';
|
|
3
|
+
import { type MarkdownLabels } from './labels.js';
|
|
4
|
+
import type { MarkdownPlugin } from '../../markdown/plugin.js';
|
|
5
|
+
import { type Sx } from '../../internal/sx.js';
|
|
6
|
+
export type MarkdownProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
7
|
+
/** The Markdown text: all of it so far, while it streams. */
|
|
8
|
+
value: string;
|
|
9
|
+
/** Whether the text is still being written. */
|
|
10
|
+
streaming?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to tidy the unfinished end while streaming: close emphasis that has started,
|
|
13
|
+
* show a link waiting for its address as text, and hold back what is still ambiguous.
|
|
14
|
+
* On by default.
|
|
15
|
+
*/
|
|
16
|
+
tidy?: boolean;
|
|
17
|
+
/** GitHub Flavored Markdown: tables, task lists, strikethrough, autolinks, footnotes. On by default. */
|
|
18
|
+
gfm?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a line ending inside a paragraph breaks the line, as GitHub does in comments
|
|
21
|
+
* and as chat messages are usually meant. Off by default, as Markdown has it.
|
|
22
|
+
*/
|
|
23
|
+
breaks?: boolean;
|
|
24
|
+
/** Whether `~text~` strikes through, as `~~text~~` does. Off by default: see the docs. */
|
|
25
|
+
singleTilde?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether YAML front matter at the top of a file is read and left out, where it would
|
|
28
|
+
* otherwise be drawn as a rule and a heading. Off by default: turn it on for files, not
|
|
29
|
+
* for replies.
|
|
30
|
+
*/
|
|
31
|
+
frontmatter?: boolean;
|
|
32
|
+
/** Plugins, in order: later ones win where they overlap. */
|
|
33
|
+
plugins?: ReadonlyArray<MarkdownPlugin>;
|
|
34
|
+
/**
|
|
35
|
+
* Makes task items tickable. It is called with the item, which says where its box is
|
|
36
|
+
* in the text (`checkedAt`), and the new state; change the text and pass it back as
|
|
37
|
+
* `value`. Return `false`, or reject, and the box goes back.
|
|
38
|
+
*/
|
|
39
|
+
ontaskchange?: (item: ListItem, checked: boolean) => unknown;
|
|
40
|
+
/**
|
|
41
|
+
* Whether code blocks number their lines. Off by default. A block with no language,
|
|
42
|
+
* whose lines wrap, has none.
|
|
43
|
+
*/
|
|
44
|
+
lineNumbers?: boolean;
|
|
45
|
+
/** Whether a code block has a button that saves it as a file. Off by default. */
|
|
46
|
+
download?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Shows a caret at the end of the text while it streams: `true` or `'block'` for a
|
|
49
|
+
* block, `'circle'` for a dot. Off by default.
|
|
50
|
+
*/
|
|
51
|
+
caret?: boolean | 'block' | 'circle';
|
|
52
|
+
/**
|
|
53
|
+
* Fades text in a few words at a time as it arrives, where a new block otherwise fades
|
|
54
|
+
* in whole. Off by default. Code is not faded.
|
|
55
|
+
*/
|
|
56
|
+
animated?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether finished blocks are written as markup, not built from parts: about twice as
|
|
59
|
+
* fast to show and a fifth of the memory. Text, lists, tasks, quotes, code blocks, tables
|
|
60
|
+
* and file chips are written so; images, formulas, diagrams, footnotes, alerts, raw HTML
|
|
61
|
+
* and a plugin's node that has no writer of its own are drawn by their parts as ever,
|
|
62
|
+
* with the block they are in. Left out, it is on for text that was whole when the
|
|
63
|
+
* component was made and has not changed since, and off for text that streams or is
|
|
64
|
+
* edited here, whose parts change in place. `true` writes markup whenever nothing
|
|
65
|
+
* streams, `false` never does. Don't turn it on for a reply the moment it finishes
|
|
66
|
+
* streaming: it would be drawn again.
|
|
67
|
+
*/
|
|
68
|
+
static?: boolean;
|
|
69
|
+
/** The words the controls show, to translate or reword. */
|
|
70
|
+
labels?: Partial<MarkdownLabels>;
|
|
71
|
+
/**
|
|
72
|
+
* How many levels to move headings down, so they sit under the page's own: with 2, `#`
|
|
73
|
+
* is an `h3`. They keep the size they are written with.
|
|
74
|
+
*/
|
|
75
|
+
headingOffset?: number;
|
|
76
|
+
sx?: Sx;
|
|
77
|
+
};
|
|
78
|
+
declare const Markdown: import("svelte").Component<MarkdownProps, {}, "">;
|
|
79
|
+
type Markdown = ReturnType<typeof Markdown>;
|
|
80
|
+
export default Markdown;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
One block. Keyed by its id, so a block that is finished is drawn once: the parser hands
|
|
3
|
+
back the same object for it on every update, and Svelte leaves it alone.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts" module>
|
|
6
|
+
import { attrs } from '../../internal/sx.js';
|
|
7
|
+
import Glyph from '../../internal/Glyph.svelte';
|
|
8
|
+
import type { AlertKind, Block, List, ListItem, Paragraph } from '../../markdown/ast.js';
|
|
9
|
+
import { groupInlineHtml } from '../../markdown/sanitize.js';
|
|
10
|
+
import Checkbox from '../checkbox/Checkbox.svelte';
|
|
11
|
+
import { getMarkdownContext } from './context.js';
|
|
12
|
+
import MarkdownCode from './MarkdownCode.svelte';
|
|
13
|
+
import MarkdownBlocks from './MarkdownBlocks.svelte';
|
|
14
|
+
import MarkdownInlines from './MarkdownInlines.svelte';
|
|
15
|
+
import MarkdownTable from './MarkdownTable.svelte';
|
|
16
|
+
import { taskName } from './static.js';
|
|
17
|
+
import { prose } from './styles.js';
|
|
18
|
+
|
|
19
|
+
export type MarkdownBlockProps = {
|
|
20
|
+
node: Block;
|
|
21
|
+
/** Inside a tight list, whose paragraphs are not set apart. */
|
|
22
|
+
tight?: boolean;
|
|
23
|
+
/** How deep in lists it is, for the bullet. */
|
|
24
|
+
depth?: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const alertStyles = {
|
|
28
|
+
note: prose.alertNote,
|
|
29
|
+
tip: prose.alertTip,
|
|
30
|
+
important: prose.alertImportant,
|
|
31
|
+
warning: prose.alertWarning,
|
|
32
|
+
caution: prose.alertCaution
|
|
33
|
+
} satisfies Record<AlertKind, unknown>;
|
|
34
|
+
|
|
35
|
+
const alertGlyphs = {
|
|
36
|
+
note: 'alert',
|
|
37
|
+
tip: 'bulb',
|
|
38
|
+
important: 'sparkle',
|
|
39
|
+
warning: 'alert',
|
|
40
|
+
caution: 'alert'
|
|
41
|
+
} as const;
|
|
42
|
+
|
|
43
|
+
const headingSizes = {
|
|
44
|
+
1: prose.h1,
|
|
45
|
+
2: prose.h2,
|
|
46
|
+
3: prose.h3,
|
|
47
|
+
4: prose.h4,
|
|
48
|
+
5: prose.h5,
|
|
49
|
+
6: prose.h6
|
|
50
|
+
};
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<script lang="ts">
|
|
54
|
+
let { node, tight = false, depth = 0 }: MarkdownBlockProps = $props();
|
|
55
|
+
|
|
56
|
+
const md = getMarkdownContext();
|
|
57
|
+
// Only blocks that appear while the document streams fade in, not the ones there from the
|
|
58
|
+
// start. And only once: an element made later for the same block (a list item's text gaining
|
|
59
|
+
// a paragraph when its list turns loose) must not fade in again. This is read when an
|
|
60
|
+
// element is made and is not reactive, so turning it off touches nothing already drawn.
|
|
61
|
+
const first = { enter: md.animate() };
|
|
62
|
+
$effect(() => {
|
|
63
|
+
first.enter = false;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const Override = $derived(md.component(node.type));
|
|
67
|
+
|
|
68
|
+
/** The paragraphs of items drawn as a line of text, by item: they are on the page already. */
|
|
69
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- a note to itself, never read by the page
|
|
70
|
+
const direct = new Map<number, number>();
|
|
71
|
+
|
|
72
|
+
/** The text of a tight list's item that holds one paragraph and nothing else, or null. */
|
|
73
|
+
function onlyText(list: List, item: ListItem): Paragraph | null {
|
|
74
|
+
const only = list.tight && item.children.length === 1 ? item.children[0]! : null;
|
|
75
|
+
if (!only || only.type !== 'paragraph' || only.children.length === 0) return null;
|
|
76
|
+
if (md.component('paragraph')) return null;
|
|
77
|
+
direct.set(item.id, only.id);
|
|
78
|
+
return only;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Hands a ticked box to the app, and puts it back if the app says the change did not take. */
|
|
82
|
+
function tick(item: ListItem, input: HTMLInputElement) {
|
|
83
|
+
const revert = () => (input.checked = item.checked === true);
|
|
84
|
+
try {
|
|
85
|
+
Promise.resolve(md.task()?.(item, input.checked)).then((kept) => {
|
|
86
|
+
if (kept === false) revert();
|
|
87
|
+
}, revert);
|
|
88
|
+
} catch {
|
|
89
|
+
revert();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
{#snippet inlines(nodes: Parameters<typeof groupInlineHtml>[0])}
|
|
95
|
+
<MarkdownInlines nodes={groupInlineHtml(nodes, md.urls)} />
|
|
96
|
+
{/snippet}
|
|
97
|
+
|
|
98
|
+
{#snippet blocks(children: Block[], tightChildren = false, nextDepth = depth)}
|
|
99
|
+
<MarkdownBlocks blocks={children} tight={tightChildren} depth={nextDepth} />
|
|
100
|
+
{/snippet}
|
|
101
|
+
|
|
102
|
+
<!-- Narvi's own drawing of the block: what shows when no plugin takes it, or when a plugin's component fails -->
|
|
103
|
+
{#snippet standard()}
|
|
104
|
+
{#if node.type === 'paragraph'}
|
|
105
|
+
{#if node.children.length > 0}
|
|
106
|
+
{#if tight}
|
|
107
|
+
{@render inlines(node.children)}
|
|
108
|
+
{:else}
|
|
109
|
+
<p dir="auto" {...attrs([prose.block, prose.paragraph, first.enter && prose.enter])}>
|
|
110
|
+
{@render inlines(node.children)}
|
|
111
|
+
</p>
|
|
112
|
+
{/if}
|
|
113
|
+
{/if}
|
|
114
|
+
{:else if node.type === 'heading'}
|
|
115
|
+
{@const anchor = md.anchor(node)}
|
|
116
|
+
<svelte:element
|
|
117
|
+
this={`h${md.headingLevel(node.depth)}`}
|
|
118
|
+
dir="auto"
|
|
119
|
+
id={anchor ? `${md.id}-h-${anchor}` : undefined}
|
|
120
|
+
data-anchor={anchor}
|
|
121
|
+
tabindex={anchor ? -1 : undefined}
|
|
122
|
+
{...attrs([prose.block, prose.heading, headingSizes[node.depth], first.enter && prose.enter])}
|
|
123
|
+
>
|
|
124
|
+
{@render inlines(node.children)}
|
|
125
|
+
</svelte:element>
|
|
126
|
+
{:else if node.type === 'thematicBreak'}
|
|
127
|
+
<hr {...attrs([prose.block, prose.rule])} />
|
|
128
|
+
{:else if node.type === 'blockquote'}
|
|
129
|
+
{#if node.alert}
|
|
130
|
+
<div
|
|
131
|
+
role="note"
|
|
132
|
+
data-markdown-alert={node.alert}
|
|
133
|
+
{...attrs([prose.block, prose.alert, alertStyles[node.alert], first.enter && prose.enter])}
|
|
134
|
+
>
|
|
135
|
+
<p {...attrs([prose.alertTitle])}>
|
|
136
|
+
<Glyph name={alertGlyphs[node.alert]} size={14} />
|
|
137
|
+
{md.labels[node.alert]}
|
|
138
|
+
</p>
|
|
139
|
+
{@render blocks(node.children)}
|
|
140
|
+
</div>
|
|
141
|
+
{:else}
|
|
142
|
+
<blockquote
|
|
143
|
+
dir="auto"
|
|
144
|
+
{...attrs([prose.block, prose.blockquote, first.enter && prose.enter])}
|
|
145
|
+
>
|
|
146
|
+
{@render blocks(node.children)}
|
|
147
|
+
</blockquote>
|
|
148
|
+
{/if}
|
|
149
|
+
{:else if node.type === 'list'}
|
|
150
|
+
<svelte:element
|
|
151
|
+
this={node.ordered ? 'ol' : 'ul'}
|
|
152
|
+
start={node.ordered && node.start !== 1 ? node.start : undefined}
|
|
153
|
+
{...attrs([
|
|
154
|
+
prose.block,
|
|
155
|
+
prose.list,
|
|
156
|
+
node.ordered ? prose.ordered : depth > 0 ? prose.bulletNested : prose.bullet,
|
|
157
|
+
depth > 0 && prose.nestedList,
|
|
158
|
+
first.enter && prose.enter
|
|
159
|
+
])}
|
|
160
|
+
>
|
|
161
|
+
{#each node.children as item (item.id)}
|
|
162
|
+
{@const text = onlyText(node, item)}
|
|
163
|
+
<li
|
|
164
|
+
dir="auto"
|
|
165
|
+
{...attrs([
|
|
166
|
+
prose.item,
|
|
167
|
+
node.ordered && prose.orderedItem,
|
|
168
|
+
item.checked !== null && prose.task
|
|
169
|
+
])}
|
|
170
|
+
>
|
|
171
|
+
{#if item.checked !== null}
|
|
172
|
+
<Checkbox
|
|
173
|
+
checked={item.checked}
|
|
174
|
+
disabled={md.task() === undefined}
|
|
175
|
+
aria-label={taskName(item, md.labels)}
|
|
176
|
+
onchange={(event) => tick(item, event.currentTarget)}
|
|
177
|
+
sx={[prose.taskBox, md.task() === undefined && prose.taskReadOnly]}
|
|
178
|
+
/>
|
|
179
|
+
{/if}
|
|
180
|
+
<!-- In a tight list an item's text is not set in a paragraph. When more follows
|
|
181
|
+
it (code, a table, a nested list), it is, so that what follows keeps its gap. -->
|
|
182
|
+
{#if text}
|
|
183
|
+
<!-- Most items are a line of text: drawn here, with nothing in between -->
|
|
184
|
+
<MarkdownInlines nodes={groupInlineHtml(text.children, md.urls)} />
|
|
185
|
+
{:else}
|
|
186
|
+
<MarkdownBlocks
|
|
187
|
+
blocks={item.children}
|
|
188
|
+
tight={node.tight && item.children.length === 1}
|
|
189
|
+
depth={depth + 1}
|
|
190
|
+
drawn={direct.get(item.id)}
|
|
191
|
+
/>
|
|
192
|
+
{/if}
|
|
193
|
+
</li>
|
|
194
|
+
{/each}
|
|
195
|
+
</svelte:element>
|
|
196
|
+
{:else if node.type === 'code'}
|
|
197
|
+
<MarkdownCode {node} enter={first.enter} />
|
|
198
|
+
{:else if node.type === 'math'}
|
|
199
|
+
<!-- Without a math plugin, a formula shows as its source -->
|
|
200
|
+
<pre
|
|
201
|
+
dir="ltr"
|
|
202
|
+
{...attrs([prose.block, prose.mathSource, first.enter && prose.enter])}>{node.value}</pre>
|
|
203
|
+
{:else if node.type === 'table'}
|
|
204
|
+
<MarkdownTable {node} enter={first.enter} />
|
|
205
|
+
{:else if node.type === 'listItem' || node.type === 'footnoteDefinition'}
|
|
206
|
+
{@render blocks(node.children)}
|
|
207
|
+
{/if}
|
|
208
|
+
{/snippet}
|
|
209
|
+
|
|
210
|
+
<!-- A plugin's component for a code block's language takes over once the fence has closed -->
|
|
211
|
+
{#if node.type === 'code' && !(node.open && md.streaming()) && md.language(node.lang)}
|
|
212
|
+
{@const Language = md.language(node.lang)!}
|
|
213
|
+
<svelte:boundary>
|
|
214
|
+
<Language.component node={node as never} {...Language.props} />
|
|
215
|
+
{#snippet failed()}<MarkdownCode {node} enter={first.enter} />{/snippet}
|
|
216
|
+
</svelte:boundary>
|
|
217
|
+
{:else if Override}
|
|
218
|
+
<!-- A plugin's component that throws takes down its own block, not the message -->
|
|
219
|
+
<svelte:boundary>
|
|
220
|
+
<Override.component node={node as never} {...Override.props}>
|
|
221
|
+
{#if node.type === 'paragraph' || node.type === 'heading'}
|
|
222
|
+
{@render inlines(node.children)}
|
|
223
|
+
{:else if 'children' in node && node.type !== 'table' && node.type !== 'list'}
|
|
224
|
+
{@render blocks(node.children)}
|
|
225
|
+
{/if}
|
|
226
|
+
</Override.component>
|
|
227
|
+
{#snippet failed()}{@render standard()}{/snippet}
|
|
228
|
+
</svelte:boundary>
|
|
229
|
+
{:else}
|
|
230
|
+
{@render standard()}
|
|
231
|
+
{/if}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Block } from '../../markdown/ast.js';
|
|
2
|
+
export type MarkdownBlockProps = {
|
|
3
|
+
node: Block;
|
|
4
|
+
/** Inside a tight list, whose paragraphs are not set apart. */
|
|
5
|
+
tight?: boolean;
|
|
6
|
+
/** How deep in lists it is, for the bullet. */
|
|
7
|
+
depth?: number;
|
|
8
|
+
};
|
|
9
|
+
declare const MarkdownBlock: import("svelte").Component<MarkdownBlockProps, {}, "">;
|
|
10
|
+
type MarkdownBlock = ReturnType<typeof MarkdownBlock>;
|
|
11
|
+
export default MarkdownBlock;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The blocks of a container, in order. Raw HTML blocks are joined with the Markdown they wrap,
|
|
3
|
+
so the body of a `<details>` is drawn inside it.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts" module>
|
|
6
|
+
import { untrack } from 'svelte';
|
|
7
|
+
import { attrs, classes } from '../../internal/sx.js';
|
|
8
|
+
import type { Block } from '../../markdown/ast.js';
|
|
9
|
+
import { groupBlockHtml, groupInlineHtml } from '../../markdown/sanitize.js';
|
|
10
|
+
import { getMarkdownContext } from './context.js';
|
|
11
|
+
import type { Run } from './kept.js';
|
|
12
|
+
import MarkdownBlock from './MarkdownBlock.svelte';
|
|
13
|
+
import MarkdownHtml from './MarkdownHtml.svelte';
|
|
14
|
+
import MarkdownInlines from './MarkdownInlines.svelte';
|
|
15
|
+
import { prose } from './styles.js';
|
|
16
|
+
|
|
17
|
+
export type MarkdownBlocksProps = {
|
|
18
|
+
blocks: Block[];
|
|
19
|
+
/** Inside a tight list, whose paragraphs are not set apart. */
|
|
20
|
+
tight?: boolean;
|
|
21
|
+
/** How deep in lists they are, for the bullet. */
|
|
22
|
+
depth?: number;
|
|
23
|
+
/** A block that is on the page already, drawn another way, and so does not fade in. */
|
|
24
|
+
drawn?: number;
|
|
25
|
+
/** The blocks of the document itself, not of something in it. */
|
|
26
|
+
top?: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Worked out once: an element that takes one of these needs nothing to keep it up to date
|
|
30
|
+
const paragraphClass = classes(prose.block, prose.paragraph);
|
|
31
|
+
const paragraphEnterClass = classes(prose.block, prose.paragraph, prose.enter);
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<script lang="ts">
|
|
35
|
+
let { blocks, tight = false, depth = 0, drawn, top = false }: MarkdownBlocksProps = $props();
|
|
36
|
+
|
|
37
|
+
const md = getMarkdownContext();
|
|
38
|
+
const items = $derived(groupBlockHtml(blocks, md.urls));
|
|
39
|
+
|
|
40
|
+
// Under `static`, what is drawn is runs of markup, with the blocks that are parts between
|
|
41
|
+
// them. A reply of prose and code is then one piece of markup, which the browser reads
|
|
42
|
+
// once: reading it block by block costs twice as much. Without `static` the blocks are
|
|
43
|
+
// drawn as they are, and nothing is made here.
|
|
44
|
+
const entries = $derived.by(() => {
|
|
45
|
+
if (!md.static()) return items;
|
|
46
|
+
// A document drawn before is its markup from then: its blocks are not asked for, and
|
|
47
|
+
// so its text is not read (`kept.ts`)
|
|
48
|
+
const before = top ? md.kept() : null;
|
|
49
|
+
if (before) return before;
|
|
50
|
+
const list: Array<(typeof items)[number] | Run> = [];
|
|
51
|
+
let open: Run | null = null;
|
|
52
|
+
for (const item of items) {
|
|
53
|
+
const html = item.type === 'htmlGroup' ? null : md.staticHtml(item, tight, depth);
|
|
54
|
+
if (html === null) {
|
|
55
|
+
open = null;
|
|
56
|
+
list.push(item);
|
|
57
|
+
} else if (item.type === 'table') {
|
|
58
|
+
// A table can be asked for as a part (its menu), and then it alone is drawn again:
|
|
59
|
+
// what is written around it stays as it is, with the reader's selection in it
|
|
60
|
+
open = null;
|
|
61
|
+
list.push({ type: 'run', id: item.id, html });
|
|
62
|
+
} else if (open) {
|
|
63
|
+
open.html += html;
|
|
64
|
+
} else {
|
|
65
|
+
list.push((open = { type: 'run', id: item.id, html }));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (top && list.every((entry) => entry.type === 'run')) md.keep(list as Run[]);
|
|
69
|
+
return list;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// A block fades in when it arrives while the document streams, and only once: a paragraph
|
|
73
|
+
// made again for the same block, as when its list turns loose, is already there to the reader
|
|
74
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- a note to itself, never read by the page
|
|
75
|
+
const seen = new Set<number>();
|
|
76
|
+
// svelte-ignore state_referenced_locally
|
|
77
|
+
if (drawn !== undefined) seen.add(drawn);
|
|
78
|
+
function entering(id: number): boolean {
|
|
79
|
+
if (seen.has(id)) return false;
|
|
80
|
+
seen.add(id);
|
|
81
|
+
return md.animate();
|
|
82
|
+
}
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<!--
|
|
86
|
+
A paragraph is drawn here, without a component of its own: most of a reply is paragraphs,
|
|
87
|
+
and each component in the way of one is memory a long thread pays for a thousand times.
|
|
88
|
+
-->
|
|
89
|
+
{#each entries as item (item.type === 'htmlGroup' ? `html-${item.id}` : item.type === 'run' ? `run-${item.id}` : item.id)}
|
|
90
|
+
{#if item.type === 'run'}
|
|
91
|
+
<!-- Finished blocks with nothing in them to press: markup Narvi writes itself (`static.ts`) -->
|
|
92
|
+
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
|
93
|
+
{@html md.own(item.html)}
|
|
94
|
+
{:else if item.type === 'htmlGroup'}
|
|
95
|
+
<div data-markdown-html {...attrs([prose.block])}>
|
|
96
|
+
<MarkdownHtml nodes={item.nodes} />
|
|
97
|
+
</div>
|
|
98
|
+
{:else if item.type === 'paragraph' && !md.component('paragraph')}
|
|
99
|
+
{#if item.children.length > 0}
|
|
100
|
+
{#if tight}
|
|
101
|
+
<MarkdownInlines nodes={groupInlineHtml(item.children, md.urls)} />
|
|
102
|
+
{:else}
|
|
103
|
+
<!-- Read once, when the paragraph is made: it keeps its class while its text grows -->
|
|
104
|
+
<p
|
|
105
|
+
dir="auto"
|
|
106
|
+
class={untrack(() => (entering(item.id) ? paragraphEnterClass : paragraphClass))}
|
|
107
|
+
>
|
|
108
|
+
<MarkdownInlines nodes={groupInlineHtml(item.children, md.urls)} />
|
|
109
|
+
</p>
|
|
110
|
+
{/if}
|
|
111
|
+
{/if}
|
|
112
|
+
{:else}
|
|
113
|
+
<MarkdownBlock node={item} {tight} {depth} />
|
|
114
|
+
{/if}
|
|
115
|
+
{/each}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Block } from '../../markdown/ast.js';
|
|
2
|
+
export type MarkdownBlocksProps = {
|
|
3
|
+
blocks: Block[];
|
|
4
|
+
/** Inside a tight list, whose paragraphs are not set apart. */
|
|
5
|
+
tight?: boolean;
|
|
6
|
+
/** How deep in lists they are, for the bullet. */
|
|
7
|
+
depth?: number;
|
|
8
|
+
/** A block that is on the page already, drawn another way, and so does not fade in. */
|
|
9
|
+
drawn?: number;
|
|
10
|
+
/** The blocks of the document itself, not of something in it. */
|
|
11
|
+
top?: boolean;
|
|
12
|
+
};
|
|
13
|
+
declare const MarkdownBlocks: import("svelte").Component<MarkdownBlocksProps, {}, "">;
|
|
14
|
+
type MarkdownBlocks = ReturnType<typeof MarkdownBlocks>;
|
|
15
|
+
export default MarkdownBlocks;
|