@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,128 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
import { defaultHref, defaultLinkPolicy, readUrl } from '../../markdown/plugin.js';
|
|
3
|
+
const KEY = Symbol('narvi.markdown');
|
|
4
|
+
export function setMarkdownContext(context) {
|
|
5
|
+
setContext(KEY, context);
|
|
6
|
+
}
|
|
7
|
+
export function getMarkdownContext() {
|
|
8
|
+
const context = getContext(KEY);
|
|
9
|
+
if (!context)
|
|
10
|
+
throw new Error('Markdown parts must be placed inside <Markdown>.');
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
/** Merges plugins: later ones win, one component or policy function at a time. */
|
|
14
|
+
export function resolvePlugins(plugins) {
|
|
15
|
+
const components = new Map();
|
|
16
|
+
// How to write a plugin's node as markup, kept only while that plugin's component is the
|
|
17
|
+
// one that draws it: a later plugin that takes the node over takes this over too
|
|
18
|
+
const statics = new Map();
|
|
19
|
+
const languages = new Map();
|
|
20
|
+
const normalize = (c) => typeof c === 'object' && 'component' in c ? c : { component: c, props: {} };
|
|
21
|
+
let highlight = null;
|
|
22
|
+
let highlightStream = null;
|
|
23
|
+
const links = { ...defaultLinkPolicy };
|
|
24
|
+
const transforms = [];
|
|
25
|
+
for (const plugin of plugins) {
|
|
26
|
+
for (const [type, component] of Object.entries(plugin.components ?? {})) {
|
|
27
|
+
components.set(type, normalize(component));
|
|
28
|
+
const part = plugin.static?.[type];
|
|
29
|
+
if (part)
|
|
30
|
+
statics.set(type, part);
|
|
31
|
+
else
|
|
32
|
+
statics.delete(type);
|
|
33
|
+
}
|
|
34
|
+
for (const [lang, component] of Object.entries(plugin.languages ?? {}))
|
|
35
|
+
languages.set(lang.toLowerCase(), normalize(component));
|
|
36
|
+
if (plugin.highlight)
|
|
37
|
+
highlight = plugin.highlight;
|
|
38
|
+
if (plugin.highlightStream)
|
|
39
|
+
highlightStream = plugin.highlightStream;
|
|
40
|
+
if (plugin.links)
|
|
41
|
+
Object.assign(links, plugin.links);
|
|
42
|
+
if (plugin.transform)
|
|
43
|
+
transforms.push(plugin.transform);
|
|
44
|
+
}
|
|
45
|
+
const urls = {
|
|
46
|
+
href: (url) => links.href(url, {
|
|
47
|
+
type: 'link',
|
|
48
|
+
url,
|
|
49
|
+
title: null,
|
|
50
|
+
kind: 'inline',
|
|
51
|
+
children: []
|
|
52
|
+
}),
|
|
53
|
+
src: (url) => links.image(url, { type: 'image', url, title: null, alt: '', children: [] })
|
|
54
|
+
};
|
|
55
|
+
// An app that opens links itself decides where a relative one goes, so it may be followed
|
|
56
|
+
// off the web too
|
|
57
|
+
if (links.open && links.href === defaultLinkPolicy.href)
|
|
58
|
+
links.href = (url) => defaultHref(url, true);
|
|
59
|
+
// A plugin's policy that throws must not take the message with it: what it could not
|
|
60
|
+
// decide is refused. A policy is handed the address as a browser will read it, so a test
|
|
61
|
+
// it makes is made on what gets rendered. And whatever a policy returns, an address that
|
|
62
|
+
// runs script is never rendered: an app may allow schemes of its own, never these.
|
|
63
|
+
const guarded = { ...links };
|
|
64
|
+
const runsScript = (url) => {
|
|
65
|
+
const scheme = readUrl(url).scheme;
|
|
66
|
+
return scheme === 'javascript' || scheme === 'vbscript';
|
|
67
|
+
};
|
|
68
|
+
links.href = (url, node) => {
|
|
69
|
+
try {
|
|
70
|
+
const href = guarded.href(readUrl(url).url, node);
|
|
71
|
+
return href === null || runsScript(href) ? null : href;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
links.image = (url, node) => {
|
|
78
|
+
try {
|
|
79
|
+
const src = guarded.image(readUrl(url).url, node);
|
|
80
|
+
return src === null || runsScript(src) ? null : src;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
links.external = (href) => {
|
|
87
|
+
try {
|
|
88
|
+
return guarded.external(href);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// Transforms see the blocks that hold text or code: paragraphs, headings, tables, code.
|
|
95
|
+
// Lists, quotes and footnotes are rebuilt from their transformed children. Every finished
|
|
96
|
+
// block keeps its object, at any depth, so each is transformed once however long the
|
|
97
|
+
// document grows; only the blocks still being written are done again.
|
|
98
|
+
const cache = new WeakMap();
|
|
99
|
+
const transform = (block, document) => {
|
|
100
|
+
if (transforms.length === 0)
|
|
101
|
+
return block;
|
|
102
|
+
const cached = cache.get(block);
|
|
103
|
+
if (cached)
|
|
104
|
+
return cached;
|
|
105
|
+
let out = block;
|
|
106
|
+
if (block.type === 'list' ||
|
|
107
|
+
block.type === 'listItem' ||
|
|
108
|
+
block.type === 'blockquote' ||
|
|
109
|
+
block.type === 'footnoteDefinition') {
|
|
110
|
+
const children = block.children.map((child) => transform(child, document));
|
|
111
|
+
if (children.some((child, i) => child !== block.children[i]))
|
|
112
|
+
out = { ...block, children };
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
for (const t of transforms) {
|
|
116
|
+
try {
|
|
117
|
+
out = t(out, document);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// A transform that throws is skipped for this block
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
cache.set(block, out);
|
|
125
|
+
return out;
|
|
126
|
+
};
|
|
127
|
+
return { components, languages, statics, highlight, highlightStream, links, urls, transform };
|
|
128
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copying what was written, not what was drawn.
|
|
3
|
+
*
|
|
4
|
+
* A formula is drawn as dozens of glyphs, and a file chip shows only a file's name; a copy
|
|
5
|
+
* should hold the formula's TeX and the file's path. Anything inside Markdown that carries
|
|
6
|
+
* `data-markdown-copy` is copied as that text, and the controls (copy buttons, labels) are
|
|
7
|
+
* left out.
|
|
8
|
+
*
|
|
9
|
+
* `<Markdown>` listens for copies that start inside it. A selection that starts above a reply
|
|
10
|
+
* and runs into it begins somewhere else, so to cover those, put the same handler on what
|
|
11
|
+
* holds the whole conversation: `<div oncopy={copyAsWritten}>`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function copyAsWritten(event: ClipboardEvent): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copying what was written, not what was drawn.
|
|
3
|
+
*
|
|
4
|
+
* A formula is drawn as dozens of glyphs, and a file chip shows only a file's name; a copy
|
|
5
|
+
* should hold the formula's TeX and the file's path. Anything inside Markdown that carries
|
|
6
|
+
* `data-markdown-copy` is copied as that text, and the controls (copy buttons, labels) are
|
|
7
|
+
* left out.
|
|
8
|
+
*
|
|
9
|
+
* `<Markdown>` listens for copies that start inside it. A selection that starts above a reply
|
|
10
|
+
* and runs into it begins somewhere else, so to cover those, put the same handler on what
|
|
11
|
+
* holds the whole conversation: `<div oncopy={copyAsWritten}>`.
|
|
12
|
+
*/
|
|
13
|
+
export function copyAsWritten(event) {
|
|
14
|
+
if (event.defaultPrevented || !event.clipboardData)
|
|
15
|
+
return;
|
|
16
|
+
// Text copied out of a field is the field's own business
|
|
17
|
+
const target = event.target;
|
|
18
|
+
if (target instanceof HTMLInputElement ||
|
|
19
|
+
target instanceof HTMLTextAreaElement ||
|
|
20
|
+
(target instanceof HTMLElement && target.isContentEditable))
|
|
21
|
+
return;
|
|
22
|
+
const selection = getSelection();
|
|
23
|
+
if (!selection || selection.isCollapsed || selection.rangeCount === 0)
|
|
24
|
+
return;
|
|
25
|
+
const range = selection.getRangeAt(0);
|
|
26
|
+
const around = range.commonAncestorContainer;
|
|
27
|
+
const within = (around instanceof Element ? around : around.parentElement)?.closest('[data-markdown-copy]');
|
|
28
|
+
// A selection inside one formula copies all of it: half of one is no use
|
|
29
|
+
if (within) {
|
|
30
|
+
event.clipboardData.setData('text/plain', within.getAttribute('data-markdown-copy') ?? '');
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const fragment = range.cloneContents();
|
|
35
|
+
const marked = fragment.querySelectorAll('[data-markdown-copy]');
|
|
36
|
+
// Nothing to put right: the browser's own copy is the best one
|
|
37
|
+
if (marked.length === 0)
|
|
38
|
+
return;
|
|
39
|
+
for (const element of marked) {
|
|
40
|
+
element.replaceWith(element.getAttribute('data-markdown-copy') ?? '');
|
|
41
|
+
}
|
|
42
|
+
// What a closed `<details>` hides is not in the selection the reader sees
|
|
43
|
+
for (const details of fragment.querySelectorAll('details:not([open])')) {
|
|
44
|
+
for (const child of [...details.childNodes]) {
|
|
45
|
+
if (!(child instanceof Element && child.tagName === 'SUMMARY'))
|
|
46
|
+
child.remove();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const chrome of fragment.querySelectorAll('[data-markdown-chrome], button, [role="status"]')) {
|
|
50
|
+
chrome.remove();
|
|
51
|
+
}
|
|
52
|
+
// Laid out off screen, so paragraphs and code come out as they would from the page
|
|
53
|
+
const holder = document.createElement('div');
|
|
54
|
+
holder.style.cssText = 'position:fixed;left:-9999px;top:0;width:60rem';
|
|
55
|
+
holder.append(fragment);
|
|
56
|
+
// Code that is off the screen is not laid out, and text that is not laid out is not in
|
|
57
|
+
// `innerText`: here every block is asked for, whatever its place
|
|
58
|
+
const blocks = [...holder.querySelectorAll('pre')].map((pre) => {
|
|
59
|
+
const style = pre.getAttribute('style');
|
|
60
|
+
pre.style.contentVisibility = 'visible';
|
|
61
|
+
return { pre, style };
|
|
62
|
+
});
|
|
63
|
+
document.body.append(holder);
|
|
64
|
+
event.clipboardData.setData('text/plain', holder.innerText);
|
|
65
|
+
for (const { pre, style } of blocks) {
|
|
66
|
+
if (style === null)
|
|
67
|
+
pre.removeAttribute('style');
|
|
68
|
+
else
|
|
69
|
+
pre.setAttribute('style', style);
|
|
70
|
+
}
|
|
71
|
+
event.clipboardData.setData('text/html', holder.innerHTML);
|
|
72
|
+
holder.remove();
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Characters in code that cannot be seen and change what the code does or how it reads.
|
|
3
|
+
*
|
|
4
|
+
* Control characters, among them the escape sequences that drive a terminal, do their work
|
|
5
|
+
* when code is pasted into one. Direction overrides make code read in another order than it
|
|
6
|
+
* runs in ("Trojan Source"). In a code block both are drawn as what they are, so the reader
|
|
7
|
+
* sees them, and the copy button leaves the control characters out.
|
|
8
|
+
*/
|
|
9
|
+
/** Code with its unseen characters drawn: `␛` for escape, `⟨U+202E⟩` for a direction override. */
|
|
10
|
+
export declare function showHidden(text: string): string;
|
|
11
|
+
/** Code as it is safe to paste: without control characters, but for tabs and line endings. */
|
|
12
|
+
export declare function withoutControls(text: string): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Characters in code that cannot be seen and change what the code does or how it reads.
|
|
3
|
+
*
|
|
4
|
+
* Control characters, among them the escape sequences that drive a terminal, do their work
|
|
5
|
+
* when code is pasted into one. Direction overrides make code read in another order than it
|
|
6
|
+
* runs in ("Trojan Source"). In a code block both are drawn as what they are, so the reader
|
|
7
|
+
* sees them, and the copy button leaves the control characters out.
|
|
8
|
+
*/
|
|
9
|
+
// eslint-disable-next-line no-control-regex
|
|
10
|
+
const reHidden = /[\x00-\x08\x0b-\x1f\x7f-\x9f--]/;
|
|
11
|
+
const reHiddenAll = new RegExp(reHidden.source, 'g');
|
|
12
|
+
// eslint-disable-next-line no-control-regex
|
|
13
|
+
const reControls = /[\x00-\x08\x0b-\x1f\x7f-\x9f]/g;
|
|
14
|
+
/** Code with its unseen characters drawn: `␛` for escape, `⟨U+202E⟩` for a direction override. */
|
|
15
|
+
export function showHidden(text) {
|
|
16
|
+
if (!reHidden.test(text))
|
|
17
|
+
return text;
|
|
18
|
+
return text.replace(reHiddenAll, (ch) => {
|
|
19
|
+
const code = ch.charCodeAt(0);
|
|
20
|
+
// Unicode has a picture for each of the first 32 control characters, and for delete
|
|
21
|
+
if (code < 0x20)
|
|
22
|
+
return String.fromCharCode(0x2400 + code);
|
|
23
|
+
if (code === 0x7f)
|
|
24
|
+
return '␡';
|
|
25
|
+
return `⟨U+${code.toString(16).toUpperCase().padStart(4, '0')}⟩`;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** Code as it is safe to paste: without control characters, but for tabs and line endings. */
|
|
29
|
+
export function withoutControls(text) {
|
|
30
|
+
return text.replace(reControls, '');
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `static` wrote, kept by the text it was written from.
|
|
3
|
+
*
|
|
4
|
+
* A thread that draws its rows only while they are on screen shows the same reply again
|
|
5
|
+
* every time it scrolls back into view. Reading the Markdown and writing the markup is then
|
|
6
|
+
* done once: the second time, the markup is taken from here and put on the page, and the
|
|
7
|
+
* text is not read at all until something in it is pressed that needs to know what it is
|
|
8
|
+
* (a copy button, a table's menu, a task).
|
|
9
|
+
*
|
|
10
|
+
* Only a document that is markup from end to end is kept, with no part in it and no
|
|
11
|
+
* footnotes. What is kept is found again only by the same text with the same settings and
|
|
12
|
+
* the same plugins, so nothing drawn for one reply can show up in another.
|
|
13
|
+
*/
|
|
14
|
+
/** Blocks that follow one another and are all written as markup: put on the page in one piece. */
|
|
15
|
+
export type Run = {
|
|
16
|
+
type: 'run';
|
|
17
|
+
id: number;
|
|
18
|
+
html: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Stands in the kept markup for the id of the document it is put into, which is different
|
|
22
|
+
* each time. No text can hold it: text is escaped, and an escaped `<` is not a `<`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const OWN_ID = "<#>";
|
|
25
|
+
/** Kept markup as one document's own: with that document's id in the places that carry it. */
|
|
26
|
+
export declare function own(html: string, id: string): string;
|
|
27
|
+
/** A number for an object, the same each time: for telling settings apart by which object they are. */
|
|
28
|
+
export declare function serialOf(object: object | null | undefined): number;
|
|
29
|
+
export declare function kept(text: string, settings: string): Run[] | null;
|
|
30
|
+
export declare function keep(text: string, settings: string, runs: Run[]): void;
|
|
31
|
+
/** Forgets everything kept: for tests. */
|
|
32
|
+
export declare function forget(): void;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `static` wrote, kept by the text it was written from.
|
|
3
|
+
*
|
|
4
|
+
* A thread that draws its rows only while they are on screen shows the same reply again
|
|
5
|
+
* every time it scrolls back into view. Reading the Markdown and writing the markup is then
|
|
6
|
+
* done once: the second time, the markup is taken from here and put on the page, and the
|
|
7
|
+
* text is not read at all until something in it is pressed that needs to know what it is
|
|
8
|
+
* (a copy button, a table's menu, a task).
|
|
9
|
+
*
|
|
10
|
+
* Only a document that is markup from end to end is kept, with no part in it and no
|
|
11
|
+
* footnotes. What is kept is found again only by the same text with the same settings and
|
|
12
|
+
* the same plugins, so nothing drawn for one reply can show up in another.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Stands in the kept markup for the id of the document it is put into, which is different
|
|
16
|
+
* each time. No text can hold it: text is escaped, and an escaped `<` is not a `<`.
|
|
17
|
+
*/
|
|
18
|
+
export const OWN_ID = '<#>';
|
|
19
|
+
/** Kept markup as one document's own: with that document's id in the places that carry it. */
|
|
20
|
+
export function own(html, id) {
|
|
21
|
+
return html.includes(OWN_ID) ? html.replaceAll(OWN_ID, id) : html;
|
|
22
|
+
}
|
|
23
|
+
const serials = new WeakMap();
|
|
24
|
+
let serial = 0;
|
|
25
|
+
/** A number for an object, the same each time: for telling settings apart by which object they are. */
|
|
26
|
+
export function serialOf(object) {
|
|
27
|
+
if (!object)
|
|
28
|
+
return 0;
|
|
29
|
+
let number = serials.get(object);
|
|
30
|
+
if (number === undefined)
|
|
31
|
+
serials.set(object, (number = ++serial));
|
|
32
|
+
return number;
|
|
33
|
+
}
|
|
34
|
+
/** How much text, in characters, markup is kept for. The markup is about ten times that. */
|
|
35
|
+
const BUDGET = 400_000;
|
|
36
|
+
// By text, then by settings. Texts are in the order they were last used, oldest first
|
|
37
|
+
const texts = new Map();
|
|
38
|
+
let held = 0;
|
|
39
|
+
export function kept(text, settings) {
|
|
40
|
+
const bySettings = texts.get(text);
|
|
41
|
+
const runs = bySettings?.get(settings);
|
|
42
|
+
if (!bySettings || !runs)
|
|
43
|
+
return null;
|
|
44
|
+
// Used now: the last to go
|
|
45
|
+
texts.delete(text);
|
|
46
|
+
texts.set(text, bySettings);
|
|
47
|
+
return runs;
|
|
48
|
+
}
|
|
49
|
+
export function keep(text, settings, runs) {
|
|
50
|
+
// A document on the server is drawn once, and what one reader was sent is not held for the next
|
|
51
|
+
if (typeof window === 'undefined' || text.length === 0 || text.length > BUDGET / 4)
|
|
52
|
+
return;
|
|
53
|
+
let bySettings = texts.get(text);
|
|
54
|
+
if (bySettings?.has(settings))
|
|
55
|
+
return;
|
|
56
|
+
if (!bySettings)
|
|
57
|
+
texts.set(text, (bySettings = new Map()));
|
|
58
|
+
bySettings.set(settings, runs);
|
|
59
|
+
held += text.length;
|
|
60
|
+
for (const [oldest, variants] of texts) {
|
|
61
|
+
if (held <= BUDGET || oldest === text)
|
|
62
|
+
break;
|
|
63
|
+
held -= oldest.length * variants.size;
|
|
64
|
+
texts.delete(oldest);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Forgets everything kept: for tests. */
|
|
68
|
+
export function forget() {
|
|
69
|
+
texts.clear();
|
|
70
|
+
held = 0;
|
|
71
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words Markdown's own controls show and say. Pass `labels` to `<Markdown>` to translate
|
|
3
|
+
* or reword any of them; the rest keep these defaults.
|
|
4
|
+
*/
|
|
5
|
+
export type MarkdownLabels = {
|
|
6
|
+
copyCode: string;
|
|
7
|
+
downloadCode: string;
|
|
8
|
+
copied: string;
|
|
9
|
+
/** Names the table's menu button. */
|
|
10
|
+
tableActions: string;
|
|
11
|
+
copyAsMarkdown: string;
|
|
12
|
+
copyAsCsv: string;
|
|
13
|
+
saveAsCsv: string;
|
|
14
|
+
diagram: string;
|
|
15
|
+
showCode: string;
|
|
16
|
+
showDiagram: string;
|
|
17
|
+
expand: string;
|
|
18
|
+
tryAgain: string;
|
|
19
|
+
zoomIn: string;
|
|
20
|
+
zoomOut: string;
|
|
21
|
+
resetZoom: string;
|
|
22
|
+
/** Says a diagram could not be drawn, with the reason. */
|
|
23
|
+
diagramFailed: (reason: string) => string;
|
|
24
|
+
diagramNotLoaded: string;
|
|
25
|
+
diagramInvalid: string;
|
|
26
|
+
formula: string;
|
|
27
|
+
footnotes: string;
|
|
28
|
+
backToReference: (number: number) => string;
|
|
29
|
+
taskDone: string;
|
|
30
|
+
taskToDo: string;
|
|
31
|
+
/** The image button's words before the host: "Load image from". */
|
|
32
|
+
loadImage: string;
|
|
33
|
+
/** The same for a video: "Load video from". */
|
|
34
|
+
loadVideo: string;
|
|
35
|
+
/** Names a video that has no words of its own. */
|
|
36
|
+
video: string;
|
|
37
|
+
anotherSite: string;
|
|
38
|
+
/** Names where an image with no host comes from, in an app that is not on the web. */
|
|
39
|
+
thisApp: string;
|
|
40
|
+
note: string;
|
|
41
|
+
tip: string;
|
|
42
|
+
important: string;
|
|
43
|
+
warning: string;
|
|
44
|
+
caution: string;
|
|
45
|
+
};
|
|
46
|
+
export declare const defaultLabels: MarkdownLabels;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const defaultLabels = {
|
|
2
|
+
copyCode: 'Copy code',
|
|
3
|
+
downloadCode: 'Download code',
|
|
4
|
+
copied: 'Copied',
|
|
5
|
+
tableActions: 'Copy or save this table',
|
|
6
|
+
copyAsMarkdown: 'Copy as Markdown',
|
|
7
|
+
copyAsCsv: 'Copy as CSV',
|
|
8
|
+
saveAsCsv: 'Save as CSV',
|
|
9
|
+
diagram: 'Diagram',
|
|
10
|
+
showCode: 'Show code',
|
|
11
|
+
showDiagram: 'Show diagram',
|
|
12
|
+
expand: 'Expand',
|
|
13
|
+
tryAgain: 'Try again',
|
|
14
|
+
zoomIn: 'Zoom in',
|
|
15
|
+
zoomOut: 'Zoom out',
|
|
16
|
+
resetZoom: 'Reset zoom',
|
|
17
|
+
diagramFailed: (reason) => `This diagram could not be drawn: ${reason}`,
|
|
18
|
+
diagramNotLoaded: 'What draws diagrams could not be loaded.',
|
|
19
|
+
diagramInvalid: 'It is not a diagram that can be drawn.',
|
|
20
|
+
formula: 'Formula',
|
|
21
|
+
footnotes: 'Footnotes',
|
|
22
|
+
backToReference: (number) => `Back to reference ${number}`,
|
|
23
|
+
taskDone: 'Done',
|
|
24
|
+
taskToDo: 'To do',
|
|
25
|
+
loadImage: 'Load image from',
|
|
26
|
+
loadVideo: 'Load video from',
|
|
27
|
+
video: 'Video',
|
|
28
|
+
anotherSite: 'another site',
|
|
29
|
+
thisApp: 'this app',
|
|
30
|
+
note: 'Note',
|
|
31
|
+
tip: 'Tip',
|
|
32
|
+
important: 'Important',
|
|
33
|
+
warning: 'Warning',
|
|
34
|
+
caution: 'Caution'
|
|
35
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Saving text as a file the person downloads: a table as CSV, a code block as its source.
|
|
3
|
+
*/
|
|
4
|
+
/** Hands the browser a file to save. */
|
|
5
|
+
export declare function saveFile(name: string, text: string, type?: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* The name a code block is saved under: the file its fence names, without the folders and
|
|
8
|
+
* the place in it, or `code` with an ending for its language. Only letters and digits make
|
|
9
|
+
* an ending, and nothing that could name a folder gets into the name.
|
|
10
|
+
*/
|
|
11
|
+
export declare function codeFileName(title: string | null, lang: string | null): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Saving text as a file the person downloads: a table as CSV, a code block as its source.
|
|
3
|
+
*/
|
|
4
|
+
/** Hands the browser a file to save. */
|
|
5
|
+
export function saveFile(name, text, type = 'text/plain') {
|
|
6
|
+
const url = URL.createObjectURL(new Blob([text], { type: `${type};charset=utf-8` }));
|
|
7
|
+
const link = document.createElement('a');
|
|
8
|
+
link.href = url;
|
|
9
|
+
link.download = name;
|
|
10
|
+
link.click();
|
|
11
|
+
// Some browsers start the download after the click returns, and drop it if its address
|
|
12
|
+
// is gone by then
|
|
13
|
+
setTimeout(() => URL.revokeObjectURL(url), 30_000);
|
|
14
|
+
}
|
|
15
|
+
// The endings of the languages a reply names most often, where the name is not the ending
|
|
16
|
+
const EXTENSIONS = {
|
|
17
|
+
javascript: 'js',
|
|
18
|
+
typescript: 'ts',
|
|
19
|
+
python: 'py',
|
|
20
|
+
ruby: 'rb',
|
|
21
|
+
rust: 'rs',
|
|
22
|
+
golang: 'go',
|
|
23
|
+
kotlin: 'kt',
|
|
24
|
+
csharp: 'cs',
|
|
25
|
+
'c#': 'cs',
|
|
26
|
+
'c++': 'cpp',
|
|
27
|
+
shell: 'sh',
|
|
28
|
+
bash: 'sh',
|
|
29
|
+
zsh: 'sh',
|
|
30
|
+
shellscript: 'sh',
|
|
31
|
+
powershell: 'ps1',
|
|
32
|
+
markdown: 'md',
|
|
33
|
+
yaml: 'yml',
|
|
34
|
+
dockerfile: 'dockerfile',
|
|
35
|
+
plaintext: 'txt',
|
|
36
|
+
text: 'txt'
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The name a code block is saved under: the file its fence names, without the folders and
|
|
40
|
+
* the place in it, or `code` with an ending for its language. Only letters and digits make
|
|
41
|
+
* an ending, and nothing that could name a folder gets into the name.
|
|
42
|
+
*/
|
|
43
|
+
export function codeFileName(title, lang) {
|
|
44
|
+
if (title) {
|
|
45
|
+
const base = title
|
|
46
|
+
.replace(/:\d+(?:-\d+)?$/, '')
|
|
47
|
+
.split(/[\\/]/)
|
|
48
|
+
.pop()
|
|
49
|
+
// eslint-disable-next-line no-control-regex
|
|
50
|
+
.replace(/[\x00-\x1f\x7f<>:"|?*]/g, '')
|
|
51
|
+
.replace(/^\.+/, '');
|
|
52
|
+
if (base)
|
|
53
|
+
return base.slice(0, 120);
|
|
54
|
+
}
|
|
55
|
+
const name = (lang ?? '').toLowerCase();
|
|
56
|
+
const ending = EXTENSIONS[name] ?? (/^[a-z0-9]{1,10}$/.test(name) ? name : 'txt');
|
|
57
|
+
return `code.${ending}`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For an element that scrolls sideways when its content is too wide: a code block, a table, a
|
|
3
|
+
* formula. It takes keyboard focus only while it actually overflows, so a keyboard can scroll
|
|
4
|
+
* it, and a page of short code blocks does not add a tab stop for each.
|
|
5
|
+
*
|
|
6
|
+
* Telling whether it overflows means asking the browser for a layout, and of all that is in
|
|
7
|
+
* the element: a code block that is off the screen, which the browser has not laid out yet
|
|
8
|
+
* (`content-visibility`), would be laid out to answer. So an element is measured when it
|
|
9
|
+
* comes near the screen, and not before. One thing cannot wait for that: the Tab key goes to
|
|
10
|
+
* the next element that takes focus, wherever on the page it is, so when Tab is pressed
|
|
11
|
+
* everything still waiting is measured first.
|
|
12
|
+
*
|
|
13
|
+
* Elements are measured together, once a frame, all of them read before any is written: a
|
|
14
|
+
* reply that streams is laid out once per frame for this, not once per change to each block.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The same for what `static` wrote as markup, which has no part to look after it: every
|
|
18
|
+
* element under `root` marked as one that may scroll is looked after until the function
|
|
19
|
+
* this returns is called.
|
|
20
|
+
*/
|
|
21
|
+
export declare function measureScrollables(root: HTMLElement): () => void;
|
|
22
|
+
export declare function scrollable(node: HTMLElement): {
|
|
23
|
+
destroy(): void;
|
|
24
|
+
};
|