markstream-svelte 0.0.6 → 0.1.0-beta.2
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 +14 -17
- package/dist/components/CodeBlockNode.svelte +235 -266
- package/dist/components/CodeBlockNode.svelte.d.ts +6 -5
- package/dist/components/NodeOutlet.svelte +13 -2
- package/dist/components/NodeRenderer.svelte +16 -5
- package/dist/components/PreCodeNode.svelte +1 -1
- package/dist/components/shared/node-helpers.d.ts +14 -13
- package/dist/components/shared/node-helpers.js +1 -1
- package/dist/enhanceRenderedHtml.d.ts +5 -2
- package/dist/enhanceRenderedHtml.js +134 -40
- package/dist/index.css +10 -69
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -3
- package/dist/index.px.css +10 -69
- package/dist/index.tailwind.css +10 -69
- package/dist/optional/{monaco.d.ts → streamDiffs.d.ts} +5 -6
- package/dist/optional/streamDiffs.js +66 -0
- package/dist/types/codeBlock.d.ts +66 -0
- package/dist/utils/languageIcon.d.ts +1 -1
- package/dist/utils/languageIcon.js +7 -5
- package/package.json +6 -10
- package/dist/components/MarkdownCodeBlockNode.svelte +0 -15
- package/dist/components/MarkdownCodeBlockNode.svelte.d.ts +0 -8
- package/dist/optional/monaco.js +0 -84
- package/dist/types/monaco.d.ts +0 -65
- /package/dist/types/{monaco.js → codeBlock.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CodeBlockOptions, CodeBlockTheme, CodeBlockThemeProp, CodeBlockThemes } from '../types/codeBlock';
|
|
2
2
|
import type { SvelteRenderableNode, SvelteRenderContext } from './shared/node-helpers';
|
|
3
3
|
type Props = {
|
|
4
4
|
node: SvelteRenderableNode;
|
|
@@ -6,10 +6,11 @@ type Props = {
|
|
|
6
6
|
isDark?: boolean | undefined;
|
|
7
7
|
loading?: boolean | undefined;
|
|
8
8
|
stream?: boolean | undefined;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
codeBlockOptions?: CodeBlockOptions | undefined;
|
|
10
|
+
theme?: CodeBlockThemeProp | undefined;
|
|
11
|
+
darkTheme?: CodeBlockTheme | undefined;
|
|
12
|
+
lightTheme?: CodeBlockTheme | undefined;
|
|
13
|
+
themes?: CodeBlockThemes | undefined;
|
|
13
14
|
minWidth?: string | number | undefined;
|
|
14
15
|
maxWidth?: string | number | undefined;
|
|
15
16
|
isShowPreview?: boolean;
|
|
@@ -71,6 +71,16 @@
|
|
|
71
71
|
let shouldEscapeHtmlTag = $derived(resolveShouldEscapeHtmlTag())
|
|
72
72
|
let htmlRenderNode = $derived(coerceBuiltinHtmlNode(node, resolvedType))
|
|
73
73
|
let codeBlockInstanceKey = $derived(`${String(indexKey ?? 'code-block')}:${String((node as any)?.language ?? '')}:${(node as any)?.diff ? 'diff' : 'code'}`)
|
|
74
|
+
let preShowLineNumbers = $derived(
|
|
75
|
+
typeof context?.codeBlockProps?.showLineNumbers === 'boolean'
|
|
76
|
+
? context.codeBlockProps.showLineNumbers
|
|
77
|
+
: typeof context?.codeBlockOptions?.disableLineNumbers === 'boolean'
|
|
78
|
+
? !context.codeBlockOptions.disableLineNumbers
|
|
79
|
+
: false,
|
|
80
|
+
)
|
|
81
|
+
let preStyle = $derived(context?.codeBlockOptions?.overflow
|
|
82
|
+
? `white-space: ${context.codeBlockOptions.overflow === 'scroll' ? 'pre' : 'pre-wrap'}`
|
|
83
|
+
: undefined)
|
|
74
84
|
let escapedTextNode = $derived({
|
|
75
85
|
type: 'text',
|
|
76
86
|
content: String((node as any)?.content ?? (node as any)?.raw ?? ''),
|
|
@@ -105,6 +115,7 @@
|
|
|
105
115
|
typewriter={context?.typewriter}
|
|
106
116
|
fade={context?.fade}
|
|
107
117
|
{...customInputs}
|
|
118
|
+
codeBlockOptions={context?.codeBlockOptions}
|
|
108
119
|
/>
|
|
109
120
|
{:else if resolvedType === 'text' || resolvedType === 'text_special'}
|
|
110
121
|
<TextNode {node} {context} {indexKey} typewriter={context?.typewriter} />
|
|
@@ -186,10 +197,10 @@
|
|
|
186
197
|
{:else if codeMode === 'infographic'}
|
|
187
198
|
<InfographicBlockNode {node} {context} {...customInputs} />
|
|
188
199
|
{:else if codeMode === 'pre'}
|
|
189
|
-
<PreCodeNode {node} />
|
|
200
|
+
<PreCodeNode {node} showLineNumbers={preShowLineNumbers} style={preStyle} />
|
|
190
201
|
{:else}
|
|
191
202
|
{#key codeBlockInstanceKey}
|
|
192
|
-
<CodeBlockNode {node} {context} {...customInputs} />
|
|
203
|
+
<CodeBlockNode {node} {context} {...customInputs} codeBlockOptions={context?.codeBlockOptions} />
|
|
193
204
|
{/key}
|
|
194
205
|
{/if}
|
|
195
206
|
{:else if resolvedType === 'label_open' || resolvedType === 'label_close'}
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
codeBlockStream = true,
|
|
35
35
|
codeBlockDarkTheme = undefined,
|
|
36
36
|
codeBlockLightTheme = undefined,
|
|
37
|
-
codeBlockMonacoOptions = undefined,
|
|
38
37
|
renderCodeBlocksAsPre = false,
|
|
39
38
|
codeBlockMinWidth = undefined,
|
|
40
39
|
codeBlockMaxWidth = undefined,
|
|
40
|
+
codeBlockOptions = undefined,
|
|
41
41
|
codeBlockProps = undefined,
|
|
42
42
|
mermaidProps = undefined,
|
|
43
43
|
d2Props = undefined,
|
|
@@ -167,10 +167,10 @@
|
|
|
167
167
|
codeBlockStream,
|
|
168
168
|
codeBlockDarkTheme,
|
|
169
169
|
codeBlockLightTheme,
|
|
170
|
-
codeBlockMonacoOptions,
|
|
171
170
|
renderCodeBlocksAsPre,
|
|
172
171
|
codeBlockMinWidth,
|
|
173
172
|
codeBlockMaxWidth,
|
|
173
|
+
codeBlockOptions,
|
|
174
174
|
codeBlockProps,
|
|
175
175
|
mermaidProps,
|
|
176
176
|
d2Props,
|
|
@@ -259,8 +259,11 @@
|
|
|
259
259
|
void renderedNodes
|
|
260
260
|
void isDark
|
|
261
261
|
void renderCodeBlocksAsPre
|
|
262
|
-
void
|
|
262
|
+
void codeBlockOptions
|
|
263
263
|
void codeBlockProps
|
|
264
|
+
void codeBlockDarkTheme
|
|
265
|
+
void codeBlockLightTheme
|
|
266
|
+
void themes
|
|
264
267
|
void mermaidProps
|
|
265
268
|
void d2Props
|
|
266
269
|
void infographicProps
|
|
@@ -388,12 +391,15 @@
|
|
|
388
391
|
if (token !== enhancementToken || !rootEl)
|
|
389
392
|
return
|
|
390
393
|
enhancementHandle?.dispose()
|
|
391
|
-
|
|
394
|
+
const handle = await enhanceRenderedHtml(rootEl, {
|
|
392
395
|
final: enhancementFinal,
|
|
393
396
|
isDark,
|
|
394
397
|
renderCodeBlocksAsPre,
|
|
395
|
-
|
|
398
|
+
codeBlockOptions,
|
|
396
399
|
codeBlockProps,
|
|
400
|
+
codeBlockDarkTheme,
|
|
401
|
+
codeBlockLightTheme,
|
|
402
|
+
themes,
|
|
397
403
|
mermaidProps,
|
|
398
404
|
d2Props,
|
|
399
405
|
infographicProps,
|
|
@@ -401,6 +407,11 @@
|
|
|
401
407
|
onCopy,
|
|
402
408
|
isCancelled: () => token !== enhancementToken,
|
|
403
409
|
})
|
|
410
|
+
if (token !== enhancementToken) {
|
|
411
|
+
handle.dispose()
|
|
412
|
+
return
|
|
413
|
+
}
|
|
414
|
+
enhancementHandle = handle
|
|
404
415
|
}
|
|
405
416
|
|
|
406
417
|
function hasLoadingNodes(nodes: SvelteRenderableNode[]): boolean {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
let lineNumbersText = $derived(buildLineNumbersText(lineCount))
|
|
31
31
|
let lineNumberLayoutStyle = $derived(
|
|
32
32
|
showLineGutter
|
|
33
|
-
? `--markstream-pre-line-number-width: ${Math.max(
|
|
33
|
+
? `--markstream-pre-line-number-width: ${Math.max(2, String(lineCount).length)}ch; --markstream-pre-diff-line-number-width: ${Math.max(2, String(lineCount).length)}ch; --markstream-code-padding-left: calc(var(--markstream-pre-line-number-padding-left, 2ch) + var(--markstream-pre-line-number-width, 2ch) + var(--markstream-pre-line-number-padding-right, 1ch) + var(--markstream-pre-line-number-separator-width, 2px) + var(--markstream-pre-line-number-gap-to-code, 1ch));`
|
|
34
34
|
: '',
|
|
35
35
|
)
|
|
36
36
|
let mergedStyle = $derived([lineNumberLayoutStyle, style].filter(Boolean).join(' '))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SmoothMarkdownStreamOptions } from 'markstream-core';
|
|
2
2
|
import type { BaseNode, HtmlPolicy, MarkdownIt, ParsedNode, ParseOptions } from 'stream-markdown-parser';
|
|
3
3
|
import type { CustomComponentMap } from '../../customComponents';
|
|
4
|
-
import type {
|
|
4
|
+
import type { CodeBlockOptions, CodeBlockTheme, CodeBlockThemeProp, CodeBlockThemes } from '../../types/codeBlock';
|
|
5
5
|
import { getHtmlTagFromContent, hasCompleteHtmlTagContent, normalizeCustomHtmlTags, normalizeCustomHtmlTagName as normalizeTagName, stripCustomHtmlWrapper } from 'stream-markdown-parser';
|
|
6
6
|
export { getHtmlTagFromContent, hasCompleteHtmlTagContent, normalizeCustomHtmlTags, normalizeTagName, stripCustomHtmlWrapper, };
|
|
7
7
|
export type SvelteRenderableNode = (ParsedNode | BaseNode) & Record<string, unknown>;
|
|
@@ -13,10 +13,10 @@ export interface CodeBlockPreviewPayload {
|
|
|
13
13
|
}
|
|
14
14
|
export type NodeRendererCodeBlockProps = Partial<{
|
|
15
15
|
stream: boolean;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
theme: CodeBlockThemeProp;
|
|
17
|
+
darkTheme: CodeBlockTheme;
|
|
18
|
+
lightTheme: CodeBlockTheme;
|
|
19
|
+
themes: CodeBlockThemes;
|
|
20
20
|
minWidth: string | number;
|
|
21
21
|
maxWidth: string | number;
|
|
22
22
|
isShowPreview: boolean;
|
|
@@ -30,6 +30,7 @@ export type NodeRendererCodeBlockProps = Partial<{
|
|
|
30
30
|
showLineNumbers: boolean;
|
|
31
31
|
htmlPreviewAllowScripts: boolean;
|
|
32
32
|
htmlPreviewSandbox: string;
|
|
33
|
+
codeBlockOptions?: never;
|
|
33
34
|
}> & Record<string, unknown>;
|
|
34
35
|
export type NodeRendererMermaidProps = Partial<{
|
|
35
36
|
maxHeight: string | null;
|
|
@@ -85,19 +86,19 @@ export interface NodeRendererProps {
|
|
|
85
86
|
htmlPolicy?: HtmlPolicy;
|
|
86
87
|
viewportPriority?: boolean;
|
|
87
88
|
codeBlockStream?: boolean;
|
|
88
|
-
codeBlockDarkTheme?:
|
|
89
|
-
codeBlockLightTheme?:
|
|
90
|
-
codeBlockMonacoOptions?: CodeBlockMonacoOptions;
|
|
89
|
+
codeBlockDarkTheme?: CodeBlockTheme;
|
|
90
|
+
codeBlockLightTheme?: CodeBlockTheme;
|
|
91
91
|
renderCodeBlocksAsPre?: boolean;
|
|
92
92
|
codeBlockMinWidth?: string | number;
|
|
93
93
|
codeBlockMaxWidth?: string | number;
|
|
94
|
+
codeBlockOptions?: CodeBlockOptions;
|
|
94
95
|
codeBlockProps?: NodeRendererCodeBlockProps;
|
|
95
96
|
mermaidProps?: NodeRendererMermaidProps;
|
|
96
97
|
d2Props?: NodeRendererD2Props;
|
|
97
98
|
infographicProps?: NodeRendererInfographicProps;
|
|
98
99
|
customComponents?: CustomComponentMap;
|
|
99
100
|
showTooltips?: boolean;
|
|
100
|
-
themes?:
|
|
101
|
+
themes?: CodeBlockThemes;
|
|
101
102
|
isDark?: boolean;
|
|
102
103
|
customId?: string;
|
|
103
104
|
indexKey?: number | string;
|
|
@@ -133,16 +134,16 @@ export interface SvelteRenderContext {
|
|
|
133
134
|
customHtmlTags?: readonly string[];
|
|
134
135
|
parseOptions?: ParseOptions;
|
|
135
136
|
customMarkdownIt?: (md: MarkdownIt) => MarkdownIt;
|
|
137
|
+
codeBlockOptions?: CodeBlockOptions;
|
|
136
138
|
codeBlockProps?: NodeRendererCodeBlockProps;
|
|
137
139
|
mermaidProps?: NodeRendererMermaidProps;
|
|
138
140
|
d2Props?: NodeRendererD2Props;
|
|
139
141
|
infographicProps?: NodeRendererInfographicProps;
|
|
140
142
|
customComponents?: CustomComponentMap;
|
|
141
143
|
codeBlockThemes?: {
|
|
142
|
-
themes?:
|
|
143
|
-
darkTheme?:
|
|
144
|
-
lightTheme?:
|
|
145
|
-
monacoOptions?: CodeBlockMonacoOptions;
|
|
144
|
+
themes?: CodeBlockThemes;
|
|
145
|
+
darkTheme?: CodeBlockTheme;
|
|
146
|
+
lightTheme?: CodeBlockTheme;
|
|
146
147
|
minWidth?: string | number;
|
|
147
148
|
maxWidth?: string | number;
|
|
148
149
|
};
|
|
@@ -40,6 +40,7 @@ export function buildRenderContext(props, events = {}, textStreamState, streamRe
|
|
|
40
40
|
customHtmlTags,
|
|
41
41
|
parseOptions: props.parseOptions,
|
|
42
42
|
customMarkdownIt: props.customMarkdownIt,
|
|
43
|
+
codeBlockOptions: props.codeBlockOptions,
|
|
43
44
|
codeBlockProps: props.codeBlockProps,
|
|
44
45
|
mermaidProps: props.mermaidProps,
|
|
45
46
|
d2Props: props.d2Props,
|
|
@@ -49,7 +50,6 @@ export function buildRenderContext(props, events = {}, textStreamState, streamRe
|
|
|
49
50
|
themes: props.themes,
|
|
50
51
|
darkTheme: props.codeBlockDarkTheme,
|
|
51
52
|
lightTheme: props.codeBlockLightTheme,
|
|
52
|
-
monacoOptions: props.codeBlockMonacoOptions,
|
|
53
53
|
minWidth: props.codeBlockMinWidth,
|
|
54
54
|
maxWidth: props.codeBlockMaxWidth,
|
|
55
55
|
},
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { NodeRendererCodeBlockProps, NodeRendererD2Props, NodeRendererInfographicProps, NodeRendererMermaidProps } from './components/shared/node-helpers';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CodeBlockOptions, CodeBlockTheme, CodeBlockThemes } from './types/codeBlock';
|
|
3
3
|
export interface EnhanceRenderedHtmlOptions {
|
|
4
4
|
final?: boolean;
|
|
5
5
|
isDark?: boolean;
|
|
6
6
|
renderCodeBlocksAsPre?: boolean;
|
|
7
|
-
monacoOptions?: CodeBlockMonacoOptions;
|
|
8
7
|
d2ThemeId?: number | null;
|
|
9
8
|
d2DarkThemeId?: number | null;
|
|
10
9
|
showTooltips?: boolean;
|
|
10
|
+
codeBlockOptions?: CodeBlockOptions;
|
|
11
11
|
codeBlockProps?: NodeRendererCodeBlockProps;
|
|
12
|
+
codeBlockDarkTheme?: CodeBlockTheme;
|
|
13
|
+
codeBlockLightTheme?: CodeBlockTheme;
|
|
14
|
+
themes?: CodeBlockThemes;
|
|
12
15
|
mermaidProps?: NodeRendererMermaidProps;
|
|
13
16
|
d2Props?: NodeRendererD2Props;
|
|
14
17
|
infographicProps?: NodeRendererInfographicProps;
|
|
@@ -3,7 +3,7 @@ import { getD2 } from './optional/d2';
|
|
|
3
3
|
import { getInfographic } from './optional/infographic';
|
|
4
4
|
import { getKatex } from './optional/katex';
|
|
5
5
|
import { getMermaid } from './optional/mermaid';
|
|
6
|
-
import {
|
|
6
|
+
import { getStreamDiffsRuntime } from './optional/streamDiffs';
|
|
7
7
|
import { extractRenderedSvg, toSafeSvgMarkup } from './sanitizeSvg';
|
|
8
8
|
import { hideTooltip, showTooltipForAnchor } from './tooltip/singletonTooltip';
|
|
9
9
|
import { normalizeKaTeXRenderInput } from './utils/normalizeKaTeXRenderInput';
|
|
@@ -31,7 +31,7 @@ const DARK_THEME_OVERRIDES = {
|
|
|
31
31
|
AB4: '#FBBF24',
|
|
32
32
|
AB5: '#F59E0B',
|
|
33
33
|
};
|
|
34
|
-
const
|
|
34
|
+
const LANGUAGE_ALIASES = {
|
|
35
35
|
cjs: 'javascript',
|
|
36
36
|
cts: 'typescript',
|
|
37
37
|
d2lang: 'plaintext',
|
|
@@ -88,9 +88,15 @@ export async function enhanceRenderedHtml(root, options = {}) {
|
|
|
88
88
|
if (!isActive())
|
|
89
89
|
return handle;
|
|
90
90
|
if (!options.renderCodeBlocksAsPre)
|
|
91
|
-
await
|
|
91
|
+
await renderCodeBlock(root, cleanupFns, options, isActive);
|
|
92
|
+
if (!isActive())
|
|
93
|
+
return handle;
|
|
92
94
|
}
|
|
95
|
+
if (!isActive())
|
|
96
|
+
return handle;
|
|
93
97
|
enhanceFootnotes(root, cleanupFns);
|
|
98
|
+
if (!isActive())
|
|
99
|
+
return handle;
|
|
94
100
|
enhanceTooltips(root, cleanupFns, options);
|
|
95
101
|
return handle;
|
|
96
102
|
}
|
|
@@ -489,12 +495,27 @@ async function renderD2(root, cleanupFns, options, isActive) {
|
|
|
489
495
|
}
|
|
490
496
|
}
|
|
491
497
|
}
|
|
492
|
-
async function
|
|
493
|
-
var _a, _b;
|
|
494
|
-
const monacoModule = await getUseMonaco();
|
|
495
|
-
if (!monacoModule || typeof monacoModule.useMonaco !== 'function' || !isActive())
|
|
496
|
-
return;
|
|
498
|
+
async function renderCodeBlock(root, cleanupFns, options, isActive) {
|
|
499
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23;
|
|
497
500
|
const preNodes = Array.from(root.querySelectorAll('pre[data-markstream-code-block="1"]'));
|
|
501
|
+
const fallbackWhiteSpace = ((_a = options.codeBlockOptions) === null || _a === void 0 ? void 0 : _a.overflow) === 'scroll' ? 'pre' : 'pre-wrap';
|
|
502
|
+
const maxHeight = (_b = options.codeBlockOptions) === null || _b === void 0 ? void 0 : _b.maxHeight;
|
|
503
|
+
for (const pre of preNodes) {
|
|
504
|
+
const codeNode = pre.querySelector('code');
|
|
505
|
+
if (!codeNode)
|
|
506
|
+
continue;
|
|
507
|
+
const normalizedLanguage = resolveCodeLanguage(pre, codeNode).trim().toLowerCase();
|
|
508
|
+
if (normalizedLanguage === 'mermaid' || normalizedLanguage === 'infographic' || normalizedLanguage === 'd2' || normalizedLanguage === 'd2lang')
|
|
509
|
+
continue;
|
|
510
|
+
pre.style.whiteSpace = fallbackWhiteSpace;
|
|
511
|
+
if (typeof maxHeight === 'number') {
|
|
512
|
+
pre.style.maxHeight = `${maxHeight}px`;
|
|
513
|
+
pre.style.overflow = 'auto';
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const streamDiffsModule = await getStreamDiffsRuntime();
|
|
517
|
+
if (!streamDiffsModule || typeof streamDiffsModule.createCodeBlockRuntime !== 'function' || !isActive())
|
|
518
|
+
return;
|
|
498
519
|
for (const pre of preNodes) {
|
|
499
520
|
if (!isActive())
|
|
500
521
|
return;
|
|
@@ -507,14 +528,19 @@ async function renderMonaco(root, cleanupFns, options, isActive) {
|
|
|
507
528
|
continue;
|
|
508
529
|
const source = codeNode.textContent || '';
|
|
509
530
|
const diff = pre.dataset.markstreamDiff === '1';
|
|
531
|
+
const originalCode = decodeDataPayload(pre.dataset.markstreamOriginal);
|
|
510
532
|
const updatedCode = decodeDataPayload(pre.dataset.markstreamUpdated);
|
|
511
|
-
const
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
showHeader: ((_a = options.codeBlockProps) === null || _a === void 0 ? void 0 : _a.showHeader) !== false,
|
|
533
|
+
const runtimeLanguage = resolveLanguage(rawLanguage);
|
|
534
|
+
const shell = createEnhancedBlockShell('code', diff ? `Diff / ${runtimeLanguage}` : `Code / ${runtimeLanguage}`, source, false, options, {
|
|
535
|
+
showHeader: ((_c = options.codeBlockProps) === null || _c === void 0 ? void 0 : _c.showHeader) !== false,
|
|
515
536
|
});
|
|
516
537
|
shell.body.classList.add('markstream-svelte-enhanced-block__body--code');
|
|
517
|
-
|
|
538
|
+
const estimatedHeight = estimateCodeBlockHeight(diff ? updatedCode || source : source, diff);
|
|
539
|
+
shell.body.style.minHeight = `${typeof maxHeight === 'number' ? Math.min(estimatedHeight, maxHeight) : estimatedHeight}px`;
|
|
540
|
+
if (typeof maxHeight === 'number') {
|
|
541
|
+
shell.body.style.maxHeight = `${maxHeight}px`;
|
|
542
|
+
shell.body.style.overflow = 'auto';
|
|
543
|
+
}
|
|
518
544
|
const originalPre = pre.cloneNode(true);
|
|
519
545
|
let helpers = null;
|
|
520
546
|
let restored = false;
|
|
@@ -529,45 +555,108 @@ async function renderMonaco(root, cleanupFns, options, isActive) {
|
|
|
529
555
|
catch {
|
|
530
556
|
// Ignore cleanup failures during fallback.
|
|
531
557
|
}
|
|
532
|
-
if (shell.wrapper.
|
|
558
|
+
if (shell.wrapper.parentNode)
|
|
533
559
|
shell.wrapper.replaceWith(originalPre.cloneNode(true));
|
|
534
560
|
};
|
|
535
561
|
pre.replaceWith(shell.wrapper);
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
562
|
+
const userOptions = { ...((_d = options.codeBlockOptions) !== null && _d !== void 0 ? _d : {}) };
|
|
563
|
+
for (const key of [
|
|
564
|
+
'maxHeight',
|
|
565
|
+
'padding',
|
|
566
|
+
'tabSize',
|
|
567
|
+
'theme',
|
|
568
|
+
'themes',
|
|
569
|
+
'themeType',
|
|
570
|
+
'language',
|
|
571
|
+
'languages',
|
|
572
|
+
'stream',
|
|
573
|
+
'disableFileHeader',
|
|
574
|
+
'onThemeChange',
|
|
575
|
+
'renderCustomHeader',
|
|
576
|
+
'renderHeaderMetadata',
|
|
577
|
+
'renderHeaderPrefix',
|
|
578
|
+
])
|
|
579
|
+
delete userOptions[key];
|
|
580
|
+
const parseDiffOptions = userOptions.parseDiffOptions && typeof userOptions.parseDiffOptions === 'object'
|
|
581
|
+
? userOptions.parseDiffOptions
|
|
582
|
+
: {};
|
|
583
|
+
const nativeOptions = diff
|
|
584
|
+
? {
|
|
585
|
+
diffStyle: 'split',
|
|
586
|
+
expandUnchanged: false,
|
|
587
|
+
collapsedContextThreshold: 5,
|
|
588
|
+
hunkSeparators: 'line-info',
|
|
589
|
+
...userOptions,
|
|
590
|
+
parseDiffOptions: { context: 2, ...parseDiffOptions },
|
|
591
|
+
}
|
|
592
|
+
: userOptions;
|
|
593
|
+
const configuredTheme = (_e = options.codeBlockProps) === null || _e === void 0 ? void 0 : _e.theme;
|
|
594
|
+
const runtimeThemes = [
|
|
595
|
+
(_o = (_l = (_k = (_g = (_f = options.codeBlockProps) === null || _f === void 0 ? void 0 : _f.darkTheme) !== null && _g !== void 0 ? _g : (_j = (_h = options.codeBlockProps) === null || _h === void 0 ? void 0 : _h.themes) === null || _j === void 0 ? void 0 : _j[0]) !== null && _k !== void 0 ? _k : options.codeBlockDarkTheme) !== null && _l !== void 0 ? _l : (_m = options.themes) === null || _m === void 0 ? void 0 : _m[0]) !== null && _o !== void 0 ? _o : 'vitesse-dark',
|
|
596
|
+
(_w = (_u = (_t = (_q = (_p = options.codeBlockProps) === null || _p === void 0 ? void 0 : _p.lightTheme) !== null && _q !== void 0 ? _q : (_s = (_r = options.codeBlockProps) === null || _r === void 0 ? void 0 : _r.themes) === null || _s === void 0 ? void 0 : _s[1]) !== null && _t !== void 0 ? _t : options.codeBlockLightTheme) !== null && _u !== void 0 ? _u : (_v = options.themes) === null || _v === void 0 ? void 0 : _v[1]) !== null && _w !== void 0 ? _w : 'vitesse-light',
|
|
597
|
+
];
|
|
598
|
+
const requestedTheme = typeof configuredTheme === 'string'
|
|
599
|
+
? configuredTheme
|
|
600
|
+
: configuredTheme && typeof configuredTheme === 'object'
|
|
601
|
+
? (options.isDark ? configuredTheme.dark : configuredTheme.light)
|
|
602
|
+
: options.isDark
|
|
603
|
+
? (_4 = (_2 = (_1 = (_y = (_x = options.codeBlockProps) === null || _x === void 0 ? void 0 : _x.darkTheme) !== null && _y !== void 0 ? _y : (_0 = (_z = options.codeBlockProps) === null || _z === void 0 ? void 0 : _z.themes) === null || _0 === void 0 ? void 0 : _0[0]) !== null && _1 !== void 0 ? _1 : options.codeBlockDarkTheme) !== null && _2 !== void 0 ? _2 : (_3 = options.themes) === null || _3 === void 0 ? void 0 : _3[0]) !== null && _4 !== void 0 ? _4 : 'vitesse-dark'
|
|
604
|
+
: (_12 = (_10 = (_9 = (_6 = (_5 = options.codeBlockProps) === null || _5 === void 0 ? void 0 : _5.lightTheme) !== null && _6 !== void 0 ? _6 : (_8 = (_7 = options.codeBlockProps) === null || _7 === void 0 ? void 0 : _7.themes) === null || _8 === void 0 ? void 0 : _8[1]) !== null && _9 !== void 0 ? _9 : options.codeBlockLightTheme) !== null && _10 !== void 0 ? _10 : (_11 = options.themes) === null || _11 === void 0 ? void 0 : _11[1]) !== null && _12 !== void 0 ? _12 : 'vitesse-light';
|
|
605
|
+
const configuredUnsafeCSS = typeof nativeOptions.unsafeCSS === 'string' ? nativeOptions.unsafeCSS : '';
|
|
606
|
+
const showLineNumbers = (_14 = (_13 = options.codeBlockProps) === null || _13 === void 0 ? void 0 : _13.showLineNumbers) !== null && _14 !== void 0 ? _14 : ((_15 = options.codeBlockOptions) === null || _15 === void 0 ? void 0 : _15.disableLineNumbers) !== true;
|
|
607
|
+
const syncGeometry = () => {
|
|
608
|
+
var _a, _b, _c;
|
|
609
|
+
shell.body.style.setProperty('--diffs-tab-size', String((_b = (_a = options.codeBlockOptions) === null || _a === void 0 ? void 0 : _a.tabSize) !== null && _b !== void 0 ? _b : 4));
|
|
610
|
+
if (typeof ((_c = options.codeBlockOptions) === null || _c === void 0 ? void 0 : _c.padding) === 'number')
|
|
611
|
+
shell.body.style.setProperty('--diffs-gap-block', `${options.codeBlockOptions.padding}px`);
|
|
612
|
+
else
|
|
613
|
+
shell.body.style.removeProperty('--diffs-gap-block');
|
|
614
|
+
};
|
|
615
|
+
syncGeometry();
|
|
616
|
+
helpers = streamDiffsModule.createCodeBlockRuntime({
|
|
617
|
+
overflow: 'wrap',
|
|
618
|
+
...nativeOptions,
|
|
619
|
+
themes: runtimeThemes,
|
|
620
|
+
theme: requestedTheme,
|
|
621
|
+
themeType: options.isDark ? 'dark' : 'light',
|
|
622
|
+
disableLineNumbers: !showLineNumbers,
|
|
623
|
+
MAX_HEIGHT: (_17 = (_16 = options.codeBlockOptions) === null || _16 === void 0 ? void 0 : _16.maxHeight) !== null && _17 !== void 0 ? _17 : 500,
|
|
624
|
+
fontSize: (_19 = (_18 = options.codeBlockOptions) === null || _18 === void 0 ? void 0 : _18.fontSize) !== null && _19 !== void 0 ? _19 : 13,
|
|
625
|
+
lineHeight: (_20 = options.codeBlockOptions) === null || _20 === void 0 ? void 0 : _20.lineHeight,
|
|
626
|
+
fontFamily: (_21 = options.codeBlockOptions) === null || _21 === void 0 ? void 0 : _21.fontFamily,
|
|
627
|
+
unsafeCSS: `[data-file], [data-diff] { --diffs-min-number-column-width-default: 2ch !important; }
|
|
628
|
+
${configuredUnsafeCSS}`.trim(),
|
|
629
|
+
disableFileHeader: true,
|
|
630
|
+
stream: false,
|
|
631
|
+
onThemeChange: syncGeometry,
|
|
547
632
|
});
|
|
548
633
|
cleanupFns.push(restoreOriginalPre);
|
|
549
634
|
try {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
635
|
+
if (diff && typeof helpers.createDiffEditor === 'function') {
|
|
636
|
+
await helpers.createDiffEditor(shell.body, originalCode, updatedCode || source, runtimeLanguage);
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
await ((_22 = helpers.createEditor) === null || _22 === void 0 ? void 0 : _22.call(helpers, shell.body, source, runtimeLanguage));
|
|
640
|
+
}
|
|
556
641
|
if (!isActive()) {
|
|
557
642
|
restoreOriginalPre();
|
|
558
643
|
return;
|
|
559
644
|
}
|
|
560
|
-
await ((
|
|
645
|
+
await ((_23 = helpers.setTheme) === null || _23 === void 0 ? void 0 : _23.call(helpers, requestedTheme));
|
|
561
646
|
if (!isActive()) {
|
|
562
647
|
restoreOriginalPre();
|
|
563
648
|
return;
|
|
564
649
|
}
|
|
565
650
|
await waitForRenderFrame();
|
|
566
|
-
if (!
|
|
567
|
-
|
|
568
|
-
|
|
651
|
+
if (!isActive()) {
|
|
652
|
+
restoreOriginalPre();
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
if (!hasVisibleCodeContent(shell.body, source))
|
|
656
|
+
throw new Error('Code editor rendered no visible code content.');
|
|
657
|
+
shell.wrapper.dataset.markstreamEnhanced = '1';
|
|
569
658
|
if (diff)
|
|
570
|
-
shell.wrapper.dataset.
|
|
659
|
+
shell.wrapper.dataset.markstreamEnhancedDiff = '1';
|
|
571
660
|
}
|
|
572
661
|
catch {
|
|
573
662
|
restoreOriginalPre();
|
|
@@ -596,9 +685,9 @@ function resolveCodeLanguage(pre, codeNode) {
|
|
|
596
685
|
const languageClass = Array.from(codeNode.classList).find(className => className.startsWith('language-'));
|
|
597
686
|
return languageClass ? languageClass.slice('language-'.length) : 'plaintext';
|
|
598
687
|
}
|
|
599
|
-
function
|
|
688
|
+
function resolveLanguage(language) {
|
|
600
689
|
const normalized = language.trim().toLowerCase();
|
|
601
|
-
return
|
|
690
|
+
return LANGUAGE_ALIASES[normalized] || normalized || 'plaintext';
|
|
602
691
|
}
|
|
603
692
|
function estimateCodeBlockHeight(source, diff) {
|
|
604
693
|
const lineCount = Math.max(1, source.split('\n').length);
|
|
@@ -606,9 +695,14 @@ function estimateCodeBlockHeight(source, diff) {
|
|
|
606
695
|
const base = diff ? 180 : 96;
|
|
607
696
|
return Math.min(520, base + lineCount * perLine);
|
|
608
697
|
}
|
|
609
|
-
function
|
|
698
|
+
function hasVisibleCodeContent(body, source) {
|
|
610
699
|
var _a;
|
|
611
|
-
|
|
700
|
+
// stream-diffs renders its surface inside these containers.
|
|
701
|
+
const editor = body.querySelector([
|
|
702
|
+
'diffs-container',
|
|
703
|
+
'.stream-diffs-shell',
|
|
704
|
+
'[data-stream-diffs-state]',
|
|
705
|
+
].join(','));
|
|
612
706
|
if (!editor)
|
|
613
707
|
return false;
|
|
614
708
|
const rect = editor.getBoundingClientRect();
|
package/dist/index.css
CHANGED
|
@@ -1299,8 +1299,8 @@ body > div[id^="dmermaid-"] {
|
|
|
1299
1299
|
background: #0b1220;
|
|
1300
1300
|
}
|
|
1301
1301
|
|
|
1302
|
-
.markstream-svelte .markstream-svelte-enhanced-block__body--code .
|
|
1303
|
-
.markstream-svelte .markstream-svelte-enhanced-block__body--code
|
|
1302
|
+
.markstream-svelte .markstream-svelte-enhanced-block__body--code .stream-diffs-shell,
|
|
1303
|
+
.markstream-svelte .markstream-svelte-enhanced-block__body--code diffs-container {
|
|
1304
1304
|
min-height: inherit;
|
|
1305
1305
|
}
|
|
1306
1306
|
|
|
@@ -1536,19 +1536,9 @@ body > div[id^="dmermaid-"] {
|
|
|
1536
1536
|
box-shadow: 0 22px 44px -30px rgba(2, 6, 23, 0.95);
|
|
1537
1537
|
}
|
|
1538
1538
|
|
|
1539
|
-
.markstream-svelte .code-block-container.is-plain-text .
|
|
1540
|
-
.markstream-svelte .code-block-container.is-plain-text
|
|
1541
|
-
.markstream-svelte .code-block-container.is-plain-text .monaco-editor .margin,
|
|
1542
|
-
.markstream-svelte .code-block-container.is-plain-text .monaco-editor .lines-content {
|
|
1539
|
+
.markstream-svelte .code-block-container.is-plain-text .stream-diffs-shell,
|
|
1540
|
+
.markstream-svelte .code-block-container.is-plain-text diffs-container {
|
|
1543
1541
|
background: var(--vscode-editor-background, var(--markstream-code-fallback-bg)) !important;
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
.markstream-svelte .code-block-container.is-plain-text .monaco-editor,
|
|
1547
|
-
.markstream-svelte .code-block-container.is-plain-text .monaco-editor .margin,
|
|
1548
|
-
.markstream-svelte .code-block-container.is-plain-text .monaco-editor .view-lines,
|
|
1549
|
-
.markstream-svelte .code-block-container.is-plain-text .monaco-editor .view-line,
|
|
1550
|
-
.markstream-svelte .code-block-container.is-plain-text .monaco-editor .view-line span,
|
|
1551
|
-
.markstream-svelte .code-block-container.is-plain-text .monaco-editor .line-numbers {
|
|
1552
1542
|
color: var(--vscode-editor-foreground, var(--markstream-code-fallback-fg)) !important;
|
|
1553
1543
|
}
|
|
1554
1544
|
|
|
@@ -1619,7 +1609,6 @@ body > div[id^="dmermaid-"] {
|
|
|
1619
1609
|
.markstream-svelte .code-block-body {
|
|
1620
1610
|
position: relative;
|
|
1621
1611
|
display: grid;
|
|
1622
|
-
min-height: 96px;
|
|
1623
1612
|
min-width: 0;
|
|
1624
1613
|
overflow: hidden;
|
|
1625
1614
|
background: var(--markstream-code-fallback-bg, var(--code-bg));
|
|
@@ -1686,10 +1675,6 @@ body > div[id^="dmermaid-"] {
|
|
|
1686
1675
|
background: transparent;
|
|
1687
1676
|
}
|
|
1688
1677
|
|
|
1689
|
-
.markstream-svelte .code-editor-container {
|
|
1690
|
-
min-height: 96px;
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
1678
|
.markstream-svelte .code-editor-container.is-hidden {
|
|
1694
1679
|
opacity: 0;
|
|
1695
1680
|
pointer-events: none;
|
|
@@ -1858,6 +1843,12 @@ body > div[id^="dmermaid-"] {
|
|
|
1858
1843
|
--vscode-editor-foreground: var(--markstream-diff-editor-fg);
|
|
1859
1844
|
--vscode-diffEditor-unchangedRegionForeground: var(--markstream-diff-unchanged-fg);
|
|
1860
1845
|
--vscode-diffEditor-unchangedRegionBackground: var(--markstream-diff-unchanged-bg);
|
|
1846
|
+
--vscode-diffEditor-insertedTextBackground: var(--markstream-diff-added-inline);
|
|
1847
|
+
--vscode-diffEditor-removedTextBackground: var(--markstream-diff-removed-inline);
|
|
1848
|
+
--vscode-diffEditor-insertedLineBackground: var(--markstream-diff-added-line);
|
|
1849
|
+
--vscode-diffEditor-removedLineBackground: var(--markstream-diff-removed-line);
|
|
1850
|
+
--vscode-diffEditor-insertedTextBorder: var(--markstream-diff-added-inline-border);
|
|
1851
|
+
--vscode-diffEditor-removedTextBorder: var(--markstream-diff-removed-inline-border);
|
|
1861
1852
|
--vscode-focusBorder: var(--markstream-diff-focus);
|
|
1862
1853
|
--vscode-widget-shadow: var(--markstream-diff-widget-shadow);
|
|
1863
1854
|
}
|
|
@@ -1867,56 +1858,6 @@ body > div[id^="dmermaid-"] {
|
|
|
1867
1858
|
background: var(--markstream-diff-editor-bg);
|
|
1868
1859
|
}
|
|
1869
1860
|
|
|
1870
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root {
|
|
1871
|
-
--stream-monaco-gutter-gap: var(--markstream-diff-gutter-gap) !important;
|
|
1872
|
-
--stream-monaco-line-number: var(--markstream-diff-line-number) !important;
|
|
1873
|
-
--stream-monaco-line-number-active: var(--markstream-diff-line-number-active) !important;
|
|
1874
|
-
--stream-monaco-added-fg: var(--markstream-diff-added-fg) !important;
|
|
1875
|
-
--stream-monaco-removed-fg: var(--markstream-diff-removed-fg) !important;
|
|
1876
|
-
--stream-monaco-added-line: var(--markstream-diff-added-line) !important;
|
|
1877
|
-
--stream-monaco-removed-line: var(--markstream-diff-removed-line) !important;
|
|
1878
|
-
--stream-monaco-added-inline: var(--markstream-diff-added-inline) !important;
|
|
1879
|
-
--stream-monaco-removed-inline: var(--markstream-diff-removed-inline) !important;
|
|
1880
|
-
--stream-monaco-added-inline-border: var(--markstream-diff-added-inline-border) !important;
|
|
1881
|
-
--stream-monaco-removed-inline-border: var(--markstream-diff-removed-inline-border) !important;
|
|
1882
|
-
--stream-monaco-added-line-fill: var(--markstream-diff-added-line-fill) !important;
|
|
1883
|
-
--stream-monaco-removed-line-fill: var(--markstream-diff-removed-line-fill) !important;
|
|
1884
|
-
--stream-monaco-unchanged-bg: var(--markstream-diff-unchanged-bg) !important;
|
|
1885
|
-
--stream-monaco-unchanged-fg: var(--markstream-diff-unchanged-fg) !important;
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .monaco-diff-editor .diffOverview,
|
|
1889
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .decorationsOverviewRuler {
|
|
1890
|
-
display: none !important;
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .monaco-editor .diff-hidden-lines .center:not(.stream-monaco-unchanged-bridge-source),
|
|
1894
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .stream-monaco-diff-unchanged-bridge {
|
|
1895
|
-
--stream-monaco-unchanged-bg: var(--markstream-diff-unchanged-bg) !important;
|
|
1896
|
-
--stream-monaco-unchanged-fg: var(--markstream-diff-unchanged-fg) !important;
|
|
1897
|
-
background: var(--stream-monaco-unchanged-bg) !important;
|
|
1898
|
-
color: var(--stream-monaco-unchanged-fg) !important;
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .stream-monaco-diff-unchanged-bridge .stream-monaco-unchanged-summary,
|
|
1902
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .stream-monaco-diff-unchanged-bridge .stream-monaco-unchanged-summary:hover,
|
|
1903
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .stream-monaco-diff-unchanged-bridge .stream-monaco-unchanged-summary:focus-visible {
|
|
1904
|
-
background: var(--stream-monaco-unchanged-bg) !important;
|
|
1905
|
-
color: var(--markstream-diff-unchanged-fg) !important;
|
|
1906
|
-
}
|
|
1907
|
-
|
|
1908
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .stream-monaco-diff-unchanged-bridge .stream-monaco-unchanged-rail,
|
|
1909
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .stream-monaco-diff-unchanged-bridge .stream-monaco-unchanged-reveal,
|
|
1910
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .stream-monaco-diff-unchanged-bridge .stream-monaco-unchanged-reveal:hover,
|
|
1911
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .stream-monaco-diff-unchanged-bridge .stream-monaco-unchanged-reveal:focus-visible {
|
|
1912
|
-
background: var(--stream-monaco-unchanged-bg) !important;
|
|
1913
|
-
color: var(--markstream-diff-unchanged-fg) !important;
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
.markstream-svelte .code-block-container .stream-monaco-diff-root .stream-monaco-diff-unchanged-bridge .stream-monaco-unchanged-rail {
|
|
1917
|
-
border-right-color: var(--markstream-diff-unchanged-divider) !important;
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
1861
|
.html-preview-frame__backdrop {
|
|
1921
1862
|
position: fixed;
|
|
1922
1863
|
inset: 0;
|