@diegopluna/narvi 0.1.0 → 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 +102 -41
- package/dist/base.css +2 -2
- 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 +3 -3
- 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 -16
- 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 +37 -61
- 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 +91 -19
- 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 +219 -40
- package/dist/components/button/Button.svelte.d.ts +38 -2
- package/dist/components/card/Card.svelte +15 -26
- package/dist/components/change-stats/ChangeStats.svelte +1 -2
- package/dist/components/changes-summary/ChangesSummary.svelte +14 -15
- package/dist/components/checkbox/Checkbox.svelte +18 -15
- package/dist/components/checkbox/Checkbox.svelte.d.ts +5 -0
- package/dist/components/code/Code.svelte +1 -2
- package/dist/components/collapsible/CollapsibleTrigger.svelte +2 -2
- package/dist/components/command/CommandItem.svelte +1 -1
- package/dist/components/command/styles.d.ts +3 -2
- package/dist/components/command/styles.js +13 -10
- package/dist/components/composer/ComposerAttachButton.svelte +1 -1
- package/dist/components/composer/ComposerAttachment.svelte +9 -12
- package/dist/components/composer/ComposerModelPicker.svelte +18 -20
- package/dist/components/composer/ComposerRoot.svelte +8 -7
- package/dist/components/composer/ComposerSubmit.svelte +8 -15
- package/dist/components/composer/ComposerTextarea.svelte +1 -1
- package/dist/components/composer/ComposerToggle.svelte +9 -11
- 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 +3 -3
- package/dist/components/dialog/ConfirmDialog.svelte +1 -1
- package/dist/components/dialog/styles.d.ts +2 -3
- package/dist/components/dialog/styles.js +5 -6
- 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/heading/Heading.svelte +2 -2
- package/dist/components/kbd/Kbd.svelte +12 -7
- package/dist/components/link/Link.svelte +7 -3
- 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 +22 -2
- package/dist/components/message/MessageAction.svelte.d.ts +9 -0
- package/dist/components/message/MessageContent.svelte +2 -3
- package/dist/components/message/MessageCopy.svelte +62 -3
- 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/MessageTime.svelte +1 -1
- package/dist/components/notice/Notice.svelte +14 -10
- package/dist/components/plan/Plan.svelte +22 -17
- package/dist/components/progress/Progress.svelte +31 -33
- package/dist/components/questionnaire/Questionnaire.svelte +19 -22
- package/dist/components/queued-message/QueuedMessage.svelte +14 -7
- package/dist/components/rail/RailItem.svelte +37 -34
- 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 +2 -2
- package/dist/components/resize-handle/ResizeHandle.svelte +2 -3
- package/dist/components/segmented/SegmentedControl.svelte +7 -8
- 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/shimmer/Shimmer.svelte +34 -21
- 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 +36 -32
- 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 +26 -32
- 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 +11 -10
- package/dist/components/spinner/Spinner.svelte +4 -11
- package/dist/components/status-indicator/StatusIndicator.svelte +1 -1
- package/dist/components/suggestions/SuggestionsItem.svelte +5 -5
- package/dist/components/switch/Switch.svelte +9 -14
- 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 +13 -9
- package/dist/components/tabs/Tabs.svelte.d.ts +4 -0
- package/dist/components/text/Text.svelte +31 -23
- package/dist/components/text/Text.svelte.d.ts +8 -4
- package/dist/components/toast/Toaster.svelte +5 -5
- package/dist/components/tool/ToolContent.svelte +3 -8
- package/dist/components/tool/ToolSection.svelte +4 -5
- package/dist/components/tool/ToolTrigger.svelte +10 -9
- package/dist/components/tooltip/TooltipContent.svelte +3 -3
- package/dist/components/work-fold/WorkFold.svelte +5 -9
- package/dist/index.d.ts +16 -8
- package/dist/index.js +17 -10
- package/dist/internal/Code.svelte +3 -4
- 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 +20 -17
- package/dist/internal/layer.d.ts +3 -5
- package/dist/internal/layer.js +10 -12
- 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/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 +1 -1
- package/dist/internal/toggle.d.ts +1 -2
- package/dist/internal/toggle.js +8 -12
- 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/preset.d.ts +40 -16
- package/dist/preset.js +169 -51
- package/dist/tokens.stylex.d.ts +55 -37
- package/dist/tokens.stylex.js +107 -62
- package/dist/typography.d.ts +48 -0
- package/dist/typography.js +55 -0
- package/dist/vite.d.ts +7 -1
- package/dist/vite.js +27 -2
- package/package.json +53 -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,138 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A formula, typeset with KaTeX. KaTeX and its stylesheet load the first time a formula is
|
|
3
|
+
shown; until then, and when a formula cannot be typeset, its TeX source shows instead. A
|
|
4
|
+
block formula is typeset once its closing delimiter has arrived.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts" module>
|
|
7
|
+
import { onDestroy } from 'svelte';
|
|
8
|
+
import { attrs } from '../../internal/sx.js';
|
|
9
|
+
import type { CodeBlock, InlineMath, MathBlock } from '../../markdown/ast.js';
|
|
10
|
+
import type { NodeProps } from '../../markdown/plugin.js';
|
|
11
|
+
import { getMarkdownContext } from './context.js';
|
|
12
|
+
import { scrollable } from './scrollable.js';
|
|
13
|
+
import { prose } from './styles.js';
|
|
14
|
+
|
|
15
|
+
type Katex = typeof import('katex').default;
|
|
16
|
+
|
|
17
|
+
let katex: Katex | null = null;
|
|
18
|
+
let loading: Promise<Katex | null> | null = null;
|
|
19
|
+
|
|
20
|
+
function load(): Promise<Katex | null> {
|
|
21
|
+
loading ??= Promise.all([import('katex'), import('katex/dist/katex.min.css')]).then(
|
|
22
|
+
([module]) => (katex = module.default),
|
|
23
|
+
() => {
|
|
24
|
+
// Let the next formula try again
|
|
25
|
+
loading = null;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
return loading;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Typeset formulas, by display mode and source. An empty string records one that failed. */
|
|
33
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- a cache the page never reads
|
|
34
|
+
const cache = new Map<string, string>();
|
|
35
|
+
const CACHE_SIZE = 1000;
|
|
36
|
+
// KaTeX works in time and output that grow fast with a formula's length: one of 100,000
|
|
37
|
+
// characters takes seconds, and 85 KB of nested braces make 12 MB of markup. No formula a
|
|
38
|
+
// person reads is this long; a longer one shows as its source.
|
|
39
|
+
const MAX_TEX = 10_000;
|
|
40
|
+
const MAX_MARKUP = 200_000;
|
|
41
|
+
// Many formulas, each within those limits, could still fill the page with millions of
|
|
42
|
+
// elements. A document's formulas share this much markup; past it, they show as source.
|
|
43
|
+
const DOCUMENT_MARKUP = 2_000_000;
|
|
44
|
+
const CACHE_BYTES = 4_000_000;
|
|
45
|
+
let cached = 0;
|
|
46
|
+
|
|
47
|
+
function typeset(tex: string, display: boolean): string {
|
|
48
|
+
const key = (display ? 'd|' : 'i|') + tex;
|
|
49
|
+
let html = cache.get(key);
|
|
50
|
+
if (html === undefined) {
|
|
51
|
+
if (tex.length > MAX_TEX) return '';
|
|
52
|
+
try {
|
|
53
|
+
html = katex!.renderToString(tex, {
|
|
54
|
+
displayMode: display,
|
|
55
|
+
output: 'htmlAndMathml',
|
|
56
|
+
throwOnError: true,
|
|
57
|
+
// No \href, \includegraphics or raw HTML, whoever wrote the formula
|
|
58
|
+
trust: false,
|
|
59
|
+
strict: 'ignore',
|
|
60
|
+
maxSize: 20,
|
|
61
|
+
maxExpand: 1000
|
|
62
|
+
});
|
|
63
|
+
} catch {
|
|
64
|
+
html = '';
|
|
65
|
+
}
|
|
66
|
+
if (html.length > MAX_MARKUP) html = '';
|
|
67
|
+
while (cache.size >= CACHE_SIZE || (cached + html.length > CACHE_BYTES && cache.size > 0)) {
|
|
68
|
+
const oldest = cache.keys().next().value!;
|
|
69
|
+
cached -= cache.get(oldest)!.length;
|
|
70
|
+
cache.delete(oldest);
|
|
71
|
+
}
|
|
72
|
+
cached += html.length;
|
|
73
|
+
cache.set(key, html);
|
|
74
|
+
}
|
|
75
|
+
return html;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A formula, or a fenced code block in the language `math`. */
|
|
79
|
+
export type MarkdownMathProps = NodeProps<MathBlock | InlineMath | CodeBlock>;
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<script lang="ts">
|
|
83
|
+
let { node }: MarkdownMathProps = $props();
|
|
84
|
+
|
|
85
|
+
const md = getMarkdownContext();
|
|
86
|
+
|
|
87
|
+
let ready = $state(katex !== null);
|
|
88
|
+
$effect(() => {
|
|
89
|
+
if (!ready) void load().then((loaded) => (ready = loaded !== null));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const block = $derived(node.type !== 'inlineMath');
|
|
93
|
+
// A formula in a line of text: the document clips the block it is in (see `Markdown.svelte`)
|
|
94
|
+
$effect(() => {
|
|
95
|
+
if (!block) md.math.drawn();
|
|
96
|
+
});
|
|
97
|
+
const display = $derived(node.type !== 'inlineMath' || node.display);
|
|
98
|
+
const open = $derived(node.type === 'math' && node.open);
|
|
99
|
+
const tex = $derived(node.value.trim());
|
|
100
|
+
// What this formula holds of the document's share of markup
|
|
101
|
+
let held = 0;
|
|
102
|
+
const html = $derived.by(() => {
|
|
103
|
+
const markup = ready && !open ? typeset(tex, display) : '';
|
|
104
|
+
md.math.used += markup.length - held;
|
|
105
|
+
held = markup.length;
|
|
106
|
+
if (md.math.used <= DOCUMENT_MARKUP) return markup;
|
|
107
|
+
md.math.used -= held;
|
|
108
|
+
held = 0;
|
|
109
|
+
return '';
|
|
110
|
+
});
|
|
111
|
+
onDestroy(() => (md.math.used -= held));
|
|
112
|
+
// What a copy of the formula holds: its TeX, in the delimiters it would be written with
|
|
113
|
+
const source = $derived(block ? `$$\n${tex}\n$$` : display ? `$$${tex}$$` : `$${tex}$`);
|
|
114
|
+
</script>
|
|
115
|
+
|
|
116
|
+
<!-- KaTeX's own markup, made with `trust: false`: it holds nothing the formula's author chose but glyphs -->
|
|
117
|
+
<!-- eslint-disable svelte/no-at-html-tags -->
|
|
118
|
+
{#if html && display}
|
|
119
|
+
<svelte:element
|
|
120
|
+
this={block ? 'div' : 'span'}
|
|
121
|
+
use:scrollable
|
|
122
|
+
data-markdown-math
|
|
123
|
+
data-markdown-copy={source}
|
|
124
|
+
role="group"
|
|
125
|
+
aria-label={md.labels.formula}
|
|
126
|
+
{...attrs([block && prose.block, prose.mathDisplay])}
|
|
127
|
+
>
|
|
128
|
+
{@html html}
|
|
129
|
+
</svelte:element>
|
|
130
|
+
{:else if html}
|
|
131
|
+
<span data-markdown-math="inline" data-markdown-copy={source} {...attrs([prose.mathInline])}
|
|
132
|
+
>{@html html}</span
|
|
133
|
+
>
|
|
134
|
+
{:else if block}
|
|
135
|
+
<pre {...attrs([prose.block, prose.mathSource])}>{tex}</pre>
|
|
136
|
+
{:else}
|
|
137
|
+
<code {...attrs([prose.code])}>{tex}</code>
|
|
138
|
+
{/if}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CodeBlock, InlineMath, MathBlock } from '../../markdown/ast.js';
|
|
2
|
+
import type { NodeProps } from '../../markdown/plugin.js';
|
|
3
|
+
/** A formula, or a fenced code block in the language `math`. */
|
|
4
|
+
export type MarkdownMathProps = NodeProps<MathBlock | InlineMath | CodeBlock>;
|
|
5
|
+
declare const MarkdownMath: import("svelte").Component<MarkdownMathProps, {}, "">;
|
|
6
|
+
type MarkdownMath = ReturnType<typeof MarkdownMath>;
|
|
7
|
+
export default MarkdownMath;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A table, in a frame that scrolls sideways when it is wide. A button at its corner, shown
|
|
3
|
+
on hover or focus, copies it as Markdown or CSV, or saves it as a CSV file.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts" module>
|
|
6
|
+
import * as stylex from '@stylexjs/stylex';
|
|
7
|
+
import Glyph, { glyphHtml } from '../../internal/Glyph.svelte';
|
|
8
|
+
import { markdownTableMarker } from '../../internal/markers.stylex.js';
|
|
9
|
+
import { attrs, classes } from '../../internal/sx.js';
|
|
10
|
+
import { escapeHtml } from '../../markdown/html.js';
|
|
11
|
+
import type { Table } from '../../markdown/ast.js';
|
|
12
|
+
import { groupInlineHtml } from '../../markdown/sanitize.js';
|
|
13
|
+
import { tableToCsv, tableToMarkdown } from '../../markdown/table.js';
|
|
14
|
+
import { colors, motion, radius } from '../../tokens.stylex.js';
|
|
15
|
+
import { media } from '../../media.stylex.js';
|
|
16
|
+
import Button, { buttonClass, buttonHtml } from '../button/Button.svelte';
|
|
17
|
+
import * as Menu from '../menu/index.js';
|
|
18
|
+
import { getMarkdownContext } from './context.js';
|
|
19
|
+
import { saveFile } from './save.js';
|
|
20
|
+
import MarkdownInlines from './MarkdownInlines.svelte';
|
|
21
|
+
import { scrollable } from './scrollable.js';
|
|
22
|
+
import { prose } from './styles.js';
|
|
23
|
+
|
|
24
|
+
export type MarkdownTableProps = { node: Table; enter?: boolean };
|
|
25
|
+
|
|
26
|
+
const alignment = { left: prose.alignLeft, center: prose.alignCenter, right: prose.alignRight };
|
|
27
|
+
|
|
28
|
+
const styles = stylex.create({
|
|
29
|
+
wrap: { position: 'relative', minWidth: 0 },
|
|
30
|
+
// Over the corner of the header, out of the way until the table is pointed at or focused.
|
|
31
|
+
// A touch screen has no hover, so there it is always shown.
|
|
32
|
+
controls: {
|
|
33
|
+
position: 'absolute',
|
|
34
|
+
insetBlockStart: '0.25rem',
|
|
35
|
+
insetInlineEnd: '0.25rem',
|
|
36
|
+
opacity: {
|
|
37
|
+
default: 0,
|
|
38
|
+
[stylex.when.ancestor(':hover', markdownTableMarker)]: 1,
|
|
39
|
+
[stylex.when.ancestor(':focus-within', markdownTableMarker)]: 1,
|
|
40
|
+
[media.coarse]: 1
|
|
41
|
+
},
|
|
42
|
+
// While it cannot be seen it cannot be pressed: a click on the header goes to the text
|
|
43
|
+
pointerEvents: {
|
|
44
|
+
default: 'none',
|
|
45
|
+
[stylex.when.ancestor(':hover', markdownTableMarker)]: 'auto',
|
|
46
|
+
[stylex.when.ancestor(':focus-within', markdownTableMarker)]: 'auto',
|
|
47
|
+
[media.coarse]: 'auto'
|
|
48
|
+
},
|
|
49
|
+
transitionProperty: 'opacity',
|
|
50
|
+
transitionDuration: { default: '0s', [media.motion]: motion.fast }
|
|
51
|
+
},
|
|
52
|
+
shown: { opacity: 1, pointerEvents: 'auto' },
|
|
53
|
+
button: {
|
|
54
|
+
borderRadius: radius.item,
|
|
55
|
+
backgroundColor: colors.bgRaised,
|
|
56
|
+
boxShadow: `inset 0 0 0 1px ${colors.border}`,
|
|
57
|
+
color: {
|
|
58
|
+
default: colors.textMuted,
|
|
59
|
+
':hover': { default: null, [media.hover]: colors.text }
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
status: {
|
|
63
|
+
position: 'absolute',
|
|
64
|
+
width: '1px',
|
|
65
|
+
height: '1px',
|
|
66
|
+
overflow: 'hidden',
|
|
67
|
+
clipPath: 'inset(50%)',
|
|
68
|
+
whiteSpace: 'nowrap'
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
/** The button of a table whose menu has not been asked for: worked out once. */
|
|
73
|
+
const idleButtonClass = buttonClass({
|
|
74
|
+
variant: 'ghost',
|
|
75
|
+
size: 'sm',
|
|
76
|
+
iconOnly: true,
|
|
77
|
+
sx: styles.button
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- class names, worked out once
|
|
81
|
+
const cellClass = new Map<string, string>();
|
|
82
|
+
function classOf(head: boolean, align: 'left' | 'right' | 'center' | null): string {
|
|
83
|
+
const key = `${head}:${align}`;
|
|
84
|
+
let name = cellClass.get(key);
|
|
85
|
+
if (name === undefined) {
|
|
86
|
+
name = classes(prose.cell, head && prose.headCell, align && alignment[align]);
|
|
87
|
+
cellClass.set(key, name);
|
|
88
|
+
}
|
|
89
|
+
return name;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A finished table as markup, as this component draws it: for `static`. `cell` writes a
|
|
94
|
+
* cell's text. The button carries `data-markdown-action`: pressed, it has the document
|
|
95
|
+
* draw this table by its component, which holds the menu.
|
|
96
|
+
*/
|
|
97
|
+
export function tableHtml(
|
|
98
|
+
node: Table,
|
|
99
|
+
options: {
|
|
100
|
+
label: string;
|
|
101
|
+
cell: (cell: Table['children'][number]['children'][number]) => string;
|
|
102
|
+
}
|
|
103
|
+
): string {
|
|
104
|
+
const [head, ...body] = node.children;
|
|
105
|
+
const row = (cells: NonNullable<typeof head>, tag: 'th' | 'td') =>
|
|
106
|
+
'<tr>' +
|
|
107
|
+
cells.children
|
|
108
|
+
.map(
|
|
109
|
+
(cell, i) =>
|
|
110
|
+
`<${tag}${tag === 'th' ? ' scope="col"' : ''} dir="auto" class="${classOf(tag === 'th', node.align[i] ?? null)}">${options.cell(cell)}</${tag}>`
|
|
111
|
+
)
|
|
112
|
+
.join('') +
|
|
113
|
+
'</tr>';
|
|
114
|
+
return (
|
|
115
|
+
`<div data-markdown-table="true" data-markdown-block="${node.id}" class="${classes(prose.block, styles.wrap, markdownTableMarker)}">` +
|
|
116
|
+
`<div data-markdown-scroll class="${classes(prose.tableFrame)}"><table class="${classes(prose.table)}">` +
|
|
117
|
+
(head ? `<thead>${row(head, 'th')}</thead>` : '') +
|
|
118
|
+
(body.length > 0 ? `<tbody>${body.map((cells) => row(cells, 'td')).join('')}</tbody>` : '') +
|
|
119
|
+
'</table></div>' +
|
|
120
|
+
`<div data-markdown-chrome="true" class="${classes(styles.controls)}">` +
|
|
121
|
+
buttonHtml({
|
|
122
|
+
variant: 'ghost',
|
|
123
|
+
size: 'sm',
|
|
124
|
+
iconOnly: true,
|
|
125
|
+
sx: styles.button,
|
|
126
|
+
attributes: ` aria-label="${escapeHtml(options.label)}" aria-haspopup="menu" aria-expanded="false" data-markdown-action="table"`,
|
|
127
|
+
bare: true,
|
|
128
|
+
inner: glyphHtml('copy')
|
|
129
|
+
}) +
|
|
130
|
+
`</div><span role="status" class="${classes(styles.status)}"></span></div>`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<script lang="ts">
|
|
136
|
+
let { node, enter = false }: MarkdownTableProps = $props();
|
|
137
|
+
|
|
138
|
+
const md = getMarkdownContext();
|
|
139
|
+
const head = $derived(node.children[0]);
|
|
140
|
+
const body = $derived(node.children.slice(1));
|
|
141
|
+
|
|
142
|
+
// svelte-ignore state_referenced_locally
|
|
143
|
+
let open = $state(md.woken(node.id));
|
|
144
|
+
/** Whether the menu has been asked for, and so made. */
|
|
145
|
+
// A table that `static` wrote, and whose button was pressed, is drawn here with its menu open
|
|
146
|
+
// svelte-ignore state_referenced_locally
|
|
147
|
+
let armed = $state(md.woken(node.id));
|
|
148
|
+
function arm() {
|
|
149
|
+
armed = true;
|
|
150
|
+
open = true;
|
|
151
|
+
}
|
|
152
|
+
let copied = $state(false);
|
|
153
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
154
|
+
|
|
155
|
+
async function copy(text: string) {
|
|
156
|
+
try {
|
|
157
|
+
await navigator.clipboard.writeText(text);
|
|
158
|
+
} catch {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
copied = true;
|
|
162
|
+
clearTimeout(timer);
|
|
163
|
+
timer = setTimeout(() => (copied = false), 2000);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function download() {
|
|
167
|
+
// The byte order mark tells a spreadsheet the file is UTF-8
|
|
168
|
+
saveFile('table.csv', '\uFEFF' + tableToCsv(node), 'text/csv');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
$effect(() => () => clearTimeout(timer));
|
|
172
|
+
</script>
|
|
173
|
+
|
|
174
|
+
<div
|
|
175
|
+
data-markdown-table
|
|
176
|
+
{...attrs([prose.block, styles.wrap, markdownTableMarker, enter && prose.enter])}
|
|
177
|
+
>
|
|
178
|
+
<div use:scrollable {...attrs([prose.tableFrame])}>
|
|
179
|
+
<table {...attrs([prose.table])}>
|
|
180
|
+
{#if head}
|
|
181
|
+
<thead>
|
|
182
|
+
<tr>
|
|
183
|
+
{#each head.children as cell, i (i)}
|
|
184
|
+
{@const align = node.align[i]}
|
|
185
|
+
<th
|
|
186
|
+
scope="col"
|
|
187
|
+
dir="auto"
|
|
188
|
+
{...attrs([prose.cell, prose.headCell, align && alignment[align]])}
|
|
189
|
+
>
|
|
190
|
+
<MarkdownInlines nodes={groupInlineHtml(cell.children, md.urls)} />
|
|
191
|
+
</th>
|
|
192
|
+
{/each}
|
|
193
|
+
</tr>
|
|
194
|
+
</thead>
|
|
195
|
+
{/if}
|
|
196
|
+
{#if body.length > 0}
|
|
197
|
+
<tbody>
|
|
198
|
+
{#each body as row (row.id)}
|
|
199
|
+
<tr>
|
|
200
|
+
{#each row.children as cell, i (i)}
|
|
201
|
+
{@const align = node.align[i]}
|
|
202
|
+
<td dir="auto" {...attrs([prose.cell, align && alignment[align]])}>
|
|
203
|
+
<MarkdownInlines nodes={groupInlineHtml(cell.children, md.urls)} />
|
|
204
|
+
</td>
|
|
205
|
+
{/each}
|
|
206
|
+
</tr>
|
|
207
|
+
{/each}
|
|
208
|
+
</tbody>
|
|
209
|
+
{/if}
|
|
210
|
+
</table>
|
|
211
|
+
</div>
|
|
212
|
+
<!-- A table still being written has nothing whole to copy; one that is whole can be copied
|
|
213
|
+
while the rest of the reply is still arriving -->
|
|
214
|
+
{#if !(node.open && md.streaming())}
|
|
215
|
+
<div data-markdown-chrome {...attrs([styles.controls, (open || copied) && styles.shown])}>
|
|
216
|
+
<!-- The menu is made when it is first asked for: a table that nobody copies, which is
|
|
217
|
+
most of them, then carries a button and nothing more -->
|
|
218
|
+
{#if !armed}
|
|
219
|
+
<!-- A button and its icon, as `tableHtml` writes it: no component until it is pressed -->
|
|
220
|
+
<!-- eslint-disable svelte/no-at-html-tags -->
|
|
221
|
+
<button
|
|
222
|
+
type="button"
|
|
223
|
+
aria-label={md.labels.tableActions}
|
|
224
|
+
aria-haspopup="menu"
|
|
225
|
+
aria-expanded="false"
|
|
226
|
+
class={idleButtonClass}
|
|
227
|
+
onclick={arm}
|
|
228
|
+
onkeydown={(event: KeyboardEvent) => {
|
|
229
|
+
// As a menu's own button does: the arrow opens it too
|
|
230
|
+
if (event.key !== 'ArrowDown') return;
|
|
231
|
+
event.preventDefault();
|
|
232
|
+
arm();
|
|
233
|
+
}}>{@html glyphHtml(copied ? 'check' : 'copy')}</button
|
|
234
|
+
>
|
|
235
|
+
<!-- eslint-enable svelte/no-at-html-tags -->
|
|
236
|
+
{:else}
|
|
237
|
+
<Menu.Root bind:open>
|
|
238
|
+
<Menu.Trigger>
|
|
239
|
+
{#snippet child({ props })}
|
|
240
|
+
<Button
|
|
241
|
+
{...props}
|
|
242
|
+
variant="ghost"
|
|
243
|
+
size="sm"
|
|
244
|
+
iconOnly
|
|
245
|
+
aria-label={md.labels.tableActions}
|
|
246
|
+
sx={styles.button}
|
|
247
|
+
>
|
|
248
|
+
<Glyph name={copied ? 'check' : 'copy'} />
|
|
249
|
+
</Button>
|
|
250
|
+
{/snippet}
|
|
251
|
+
</Menu.Trigger>
|
|
252
|
+
<Menu.Content align="end">
|
|
253
|
+
<Menu.Item onSelect={() => copy(tableToMarkdown(node))}
|
|
254
|
+
>{md.labels.copyAsMarkdown}</Menu.Item
|
|
255
|
+
>
|
|
256
|
+
<Menu.Item onSelect={() => copy(tableToCsv(node))}>{md.labels.copyAsCsv}</Menu.Item>
|
|
257
|
+
<Menu.Item onSelect={download}>{md.labels.saveAsCsv}</Menu.Item>
|
|
258
|
+
</Menu.Content>
|
|
259
|
+
</Menu.Root>
|
|
260
|
+
{/if}
|
|
261
|
+
</div>
|
|
262
|
+
<!-- Outside the button: a button's contents are not read out as they change -->
|
|
263
|
+
<span role="status" {...attrs([styles.status])}>{copied ? md.labels.copied : ''}</span>
|
|
264
|
+
{/if}
|
|
265
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Table } from '../../markdown/ast.js';
|
|
2
|
+
export type MarkdownTableProps = {
|
|
3
|
+
node: Table;
|
|
4
|
+
enter?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A finished table as markup, as this component draws it: for `static`. `cell` writes a
|
|
8
|
+
* cell's text. The button carries `data-markdown-action`: pressed, it has the document
|
|
9
|
+
* draw this table by its component, which holds the menu.
|
|
10
|
+
*/
|
|
11
|
+
export declare function tableHtml(node: Table, options: {
|
|
12
|
+
label: string;
|
|
13
|
+
cell: (cell: Table['children'][number]['children'][number]) => string;
|
|
14
|
+
}): string;
|
|
15
|
+
declare const MarkdownTable: import("svelte").Component<MarkdownTableProps, {}, "">;
|
|
16
|
+
type MarkdownTable = ReturnType<typeof MarkdownTable>;
|
|
17
|
+
export default MarkdownTable;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The caret at the end of a reply that is being written.
|
|
3
|
+
*
|
|
4
|
+
* It is one element, moved to the end of the text after every update: inside the last
|
|
5
|
+
* paragraph, list item, table cell or line of code, wherever the writing has got to. It is
|
|
6
|
+
* put there by hand, not drawn by the parts themselves, so that no part carries the cost of
|
|
7
|
+
* asking "am I the last?". It always goes at the very end of the element it is in, after
|
|
8
|
+
* anything the parts keep there, so what they add later lands before it.
|
|
9
|
+
*
|
|
10
|
+
* It holds no text (its shape is a shadow), so it is not copied, not read out, and adds
|
|
11
|
+
* nothing to the width of a line. (Placing one element by hand is how Pierre's Words does it.)
|
|
12
|
+
*/
|
|
13
|
+
/** Puts `caret` at the end of the last text under `root`. */
|
|
14
|
+
export declare function placeCaret(root: HTMLElement, caret: HTMLElement): void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The caret at the end of a reply that is being written.
|
|
3
|
+
*
|
|
4
|
+
* It is one element, moved to the end of the text after every update: inside the last
|
|
5
|
+
* paragraph, list item, table cell or line of code, wherever the writing has got to. It is
|
|
6
|
+
* put there by hand, not drawn by the parts themselves, so that no part carries the cost of
|
|
7
|
+
* asking "am I the last?". It always goes at the very end of the element it is in, after
|
|
8
|
+
* anything the parts keep there, so what they add later lands before it.
|
|
9
|
+
*
|
|
10
|
+
* It holds no text (its shape is a shadow), so it is not copied, not read out, and adds
|
|
11
|
+
* nothing to the width of a line. (Placing one element by hand is how Pierre's Words does it.)
|
|
12
|
+
*/
|
|
13
|
+
// What the caret goes inside: the elements that hold text or other blocks
|
|
14
|
+
const BLOCKS = new Set([
|
|
15
|
+
'P',
|
|
16
|
+
'H1',
|
|
17
|
+
'H2',
|
|
18
|
+
'H3',
|
|
19
|
+
'H4',
|
|
20
|
+
'H5',
|
|
21
|
+
'H6',
|
|
22
|
+
'UL',
|
|
23
|
+
'OL',
|
|
24
|
+
'LI',
|
|
25
|
+
'BLOCKQUOTE',
|
|
26
|
+
'DIV',
|
|
27
|
+
'SECTION',
|
|
28
|
+
'DETAILS',
|
|
29
|
+
'PRE',
|
|
30
|
+
'CODE',
|
|
31
|
+
'TABLE',
|
|
32
|
+
'THEAD',
|
|
33
|
+
'TBODY',
|
|
34
|
+
'TR',
|
|
35
|
+
'TD',
|
|
36
|
+
'TH'
|
|
37
|
+
]);
|
|
38
|
+
/** Parts the caret goes after, never into: controls, and what is drawn as one piece. */
|
|
39
|
+
const WHOLE = '[data-markdown-chrome], [data-markdown-copy], [data-markdown-diagram], [data-markdown-math], [role="status"], button';
|
|
40
|
+
/** Puts `caret` at the end of the last text under `root`. */
|
|
41
|
+
export function placeCaret(root, caret) {
|
|
42
|
+
let parent = root;
|
|
43
|
+
for (let node = root.lastChild; node !== null;) {
|
|
44
|
+
// Nothing to see: the caret itself, the marks the parts keep, white space, footnotes
|
|
45
|
+
if (node === caret ||
|
|
46
|
+
node.nodeType === 8 ||
|
|
47
|
+
(node.nodeType === 3 && node.data.trim() === '') ||
|
|
48
|
+
(node.nodeType === 1 && node.matches('[data-markdown-chrome], [role="status"]'))) {
|
|
49
|
+
node = node.previousSibling;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (node.nodeType !== 1)
|
|
53
|
+
break;
|
|
54
|
+
const element = node;
|
|
55
|
+
const group = element.hasAttribute('data-markdown-lines');
|
|
56
|
+
// Inline code is a `<code>` too: only the one inside a `<pre>` holds lines
|
|
57
|
+
const block = group ||
|
|
58
|
+
(BLOCKS.has(element.tagName) &&
|
|
59
|
+
(element.tagName !== 'CODE' || element.parentElement?.tagName === 'PRE'));
|
|
60
|
+
if (!block || element.matches(WHOLE))
|
|
61
|
+
break;
|
|
62
|
+
parent = element;
|
|
63
|
+
node = element.lastChild;
|
|
64
|
+
}
|
|
65
|
+
if (caret.parentNode !== parent || caret.nextSibling !== null)
|
|
66
|
+
parent.appendChild(caret);
|
|
67
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Run } from './kept.js';
|
|
2
|
+
import type { Block, Document, FootnoteReference, Heading, ListItem } from '../../markdown/ast.js';
|
|
3
|
+
import type { MarkdownLabels } from './labels.js';
|
|
4
|
+
import { type Highlighter, type ResolvedLinkPolicy, type MarkdownPlugin, type PluginComponent, type StaticPart } from '../../markdown/plugin.js';
|
|
5
|
+
import type { UrlPolicy } from '../../markdown/sanitize.js';
|
|
6
|
+
export type MarkdownContext = {
|
|
7
|
+
/** Components that replace Narvi's, by node type. */
|
|
8
|
+
component: (type: string) => PluginComponent | undefined;
|
|
9
|
+
/** The component that draws a finished code block in a language, if a plugin gave one. */
|
|
10
|
+
language: (lang: string | null) => PluginComponent | undefined;
|
|
11
|
+
highlight: Highlighter | null;
|
|
12
|
+
highlightStream: NonNullable<MarkdownPlugin['highlightStream']> | null;
|
|
13
|
+
links: ResolvedLinkPolicy;
|
|
14
|
+
/** The same policy, for addresses in raw HTML. */
|
|
15
|
+
urls: UrlPolicy;
|
|
16
|
+
/** Whether a block that appears now should fade in. */
|
|
17
|
+
animate: () => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* A footnote reference's number, from the order of first reference, or 0 when it has none,
|
|
20
|
+
* and whether this reference is the first to that footnote, which the footnote links back to.
|
|
21
|
+
*/
|
|
22
|
+
footnote: (node: FootnoteReference) => {
|
|
23
|
+
number: number;
|
|
24
|
+
first: boolean;
|
|
25
|
+
};
|
|
26
|
+
/** Scrolls to an element of this document by its id, and moves focus there. */
|
|
27
|
+
reveal: (id: string) => boolean;
|
|
28
|
+
/** The heading element for a depth, after the document's offset: `h3` for `#` at offset 2. */
|
|
29
|
+
headingLevel: (depth: number) => number;
|
|
30
|
+
/** Prefixes ids, so two documents on one page do not share them. */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Whether the document is still being written. */
|
|
33
|
+
streaming: () => boolean;
|
|
34
|
+
/** Whether a line ending inside a paragraph breaks the line. */
|
|
35
|
+
breaks: () => boolean;
|
|
36
|
+
/** The words the controls show. */
|
|
37
|
+
labels: MarkdownLabels;
|
|
38
|
+
/** Called when a task item's box is ticked or cleared, when the app takes that. */
|
|
39
|
+
task: () => ((item: ListItem, checked: boolean) => unknown) | undefined;
|
|
40
|
+
/** Whether a block that `static` wrote has been asked for as parts: a table whose menu is wanted. */
|
|
41
|
+
woken: (id: number) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* A finished block as markup, when the document is `static` and the block holds nothing a
|
|
44
|
+
* component must draw; null otherwise. See `static.ts`.
|
|
45
|
+
*/
|
|
46
|
+
/** Whether finished blocks are written as markup now: `static` is in force and nothing streams. */
|
|
47
|
+
static: () => boolean;
|
|
48
|
+
/** The whole document as markup written before, when this text has been drawn already (`kept.ts`). */
|
|
49
|
+
kept: () => Run[] | null;
|
|
50
|
+
/** Keeps the whole document's markup for the next time this text is drawn. */
|
|
51
|
+
keep: (runs: Run[]) => void;
|
|
52
|
+
/** Markup `static` wrote, with this document's id where an id goes. */
|
|
53
|
+
own: (html: string) => string;
|
|
54
|
+
staticHtml: (block: Block, tight: boolean, depth: number) => string | null;
|
|
55
|
+
/** Whether text made now fades in as it arrives: the reply streams, with `animated`. */
|
|
56
|
+
fade: () => boolean;
|
|
57
|
+
/** What a code block shows beside its code. */
|
|
58
|
+
code: () => {
|
|
59
|
+
lineNumbers: boolean;
|
|
60
|
+
download: boolean;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* How much formula markup the document holds, which its formulas share a limit on, and
|
|
64
|
+
* what a formula in a line of text calls once it is on the page.
|
|
65
|
+
*/
|
|
66
|
+
math: {
|
|
67
|
+
used: number;
|
|
68
|
+
drawn: () => void;
|
|
69
|
+
};
|
|
70
|
+
/** A heading's anchor: the name a `#name` link in the same document goes to. */
|
|
71
|
+
anchor: (heading: Heading) => string | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* The address of a heading in this document, for a `#name` link to it: the heading's real
|
|
74
|
+
* id, so the link works before the page's script runs, in a new tab, and for a build that
|
|
75
|
+
* checks every `#` link has a target. Null when the document has no heading by that name.
|
|
76
|
+
*/
|
|
77
|
+
anchorHref: (name: string) => string | null;
|
|
78
|
+
/** Scrolls to a heading by its anchor; false when the document has none by that name. */
|
|
79
|
+
goto: (name: string) => boolean;
|
|
80
|
+
};
|
|
81
|
+
export declare function setMarkdownContext(context: MarkdownContext): void;
|
|
82
|
+
export declare function getMarkdownContext(): MarkdownContext;
|
|
83
|
+
/** Merges plugins: later ones win, one component or policy function at a time. */
|
|
84
|
+
export declare function resolvePlugins(plugins: ReadonlyArray<MarkdownPlugin>): {
|
|
85
|
+
components: Map<string, PluginComponent>;
|
|
86
|
+
languages: Map<string, PluginComponent>;
|
|
87
|
+
statics: Map<string, StaticPart<never>>;
|
|
88
|
+
highlight: Highlighter | null;
|
|
89
|
+
highlightStream: ((lang: string | null) => import("../../markdown/plugin.js").HighlightStream | null) | null;
|
|
90
|
+
links: ResolvedLinkPolicy;
|
|
91
|
+
urls: UrlPolicy;
|
|
92
|
+
transform: (block: Block, document: Document) => Block;
|
|
93
|
+
};
|