@king-design/vue 3.7.0 → 3.8.0-beta.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/__tests__/__snapshots__/Vue Next Demos.md +399 -0
- package/components/bubble/bubble.d.ts +61 -0
- package/components/bubble/bubble.js +81 -0
- package/components/bubble/bubble.vdt.js +85 -0
- package/components/bubble/index.d.ts +1 -0
- package/components/bubble/index.js +1 -0
- package/components/bubble/index.spec.d.ts +1 -0
- package/components/bubble/index.spec.js +771 -0
- package/components/bubble/styles.d.ts +5 -0
- package/components/bubble/styles.js +53 -0
- package/components/bubble/useBubbleDisplay.d.ts +18 -0
- package/components/bubble/useBubbleDisplay.js +300 -0
- package/components/bubbleList/bubbleList.d.ts +87 -0
- package/components/bubbleList/bubbleList.js +75 -0
- package/components/bubbleList/bubbleList.vdt.js +143 -0
- package/components/bubbleList/index.d.ts +1 -0
- package/components/bubbleList/index.js +1 -0
- package/components/bubbleList/index.spec.d.ts +1 -0
- package/components/bubbleList/index.spec.js +1268 -0
- package/components/bubbleList/item.d.ts +16 -0
- package/components/bubbleList/item.js +27 -0
- package/components/bubbleList/item.vdt.js +36 -0
- package/components/bubbleList/styles.d.ts +5 -0
- package/components/bubbleList/styles.js +33 -0
- package/components/bubbleList/useBubbleList.d.ts +28 -0
- package/components/bubbleList/useBubbleList.js +455 -0
- package/components/checkbox/index.d.ts +3 -3
- package/components/fileCard/fileCard.d.ts +65 -0
- package/components/fileCard/fileCard.js +72 -0
- package/components/fileCard/fileCard.vdt.js +161 -0
- package/components/fileCard/fileCardAssets.d.ts +1 -0
- package/components/fileCard/fileCardAssets.js +54 -0
- package/components/fileCard/fileCardUtils.d.ts +14 -0
- package/components/fileCard/fileCardUtils.js +94 -0
- package/components/fileCard/index.d.ts +2 -0
- package/components/fileCard/index.js +2 -0
- package/components/fileCard/index.spec.d.ts +1 -0
- package/components/fileCard/index.spec.js +1096 -0
- package/components/fileCard/list.d.ts +29 -0
- package/components/fileCard/list.js +46 -0
- package/components/fileCard/list.vdt.js +71 -0
- package/components/fileCard/styles.d.ts +5 -0
- package/components/fileCard/styles.js +83 -0
- package/components/fileCard/useFileCard.d.ts +45 -0
- package/components/fileCard/useFileCard.js +330 -0
- package/components/fileCard/useFileCardList.d.ts +14 -0
- package/components/fileCard/useFileCardList.js +49 -0
- package/components/form/form.js +2 -1
- package/components/media/context.d.ts +6 -0
- package/components/media/context.js +2 -0
- package/components/media/group.d.ts +12 -0
- package/components/media/group.js +32 -0
- package/components/media/group.vdt.js +50 -0
- package/components/media/index.d.ts +2 -0
- package/components/media/index.js +2 -0
- package/components/media/index.spec.d.ts +1 -0
- package/components/media/index.spec.js +1691 -0
- package/components/media/media.d.ts +37 -0
- package/components/media/media.js +67 -0
- package/components/media/media.vdt.js +202 -0
- package/components/media/mediaAssets.d.ts +4 -0
- package/components/media/mediaAssets.js +9 -0
- package/components/media/mediaUtils.d.ts +6 -0
- package/components/media/mediaUtils.js +66 -0
- package/components/media/styles.d.ts +13 -0
- package/components/media/styles.js +52 -0
- package/components/media/types.d.ts +37 -0
- package/components/media/types.js +1 -0
- package/components/media/useMedia.d.ts +70 -0
- package/components/media/useMedia.js +471 -0
- package/components/media/useMediaGroup.d.ts +15 -0
- package/components/media/useMediaGroup.js +136 -0
- package/components/media/useMediaViewer.d.ts +14 -0
- package/components/media/useMediaViewer.js +129 -0
- package/components/media/viewer.d.ts +24 -0
- package/components/media/viewer.js +54 -0
- package/components/media/viewer.vdt.js +100 -0
- package/components/radio/index.d.ts +3 -3
- package/components/sender/icons.d.ts +3 -0
- package/components/sender/icons.js +17 -0
- package/components/sender/index.d.ts +1 -0
- package/components/sender/index.js +1 -0
- package/components/sender/index.spec.d.ts +1 -0
- package/components/sender/index.spec.js +1597 -0
- package/components/sender/sender.d.ts +104 -0
- package/components/sender/sender.js +111 -0
- package/components/sender/sender.vdt.js +230 -0
- package/components/sender/styles.d.ts +5 -0
- package/components/sender/styles.js +56 -0
- package/components/sender/useAutoResize.d.ts +4 -0
- package/components/sender/useAutoResize.js +99 -0
- package/components/sender/useSenderDrag.d.ts +6 -0
- package/components/sender/useSenderDrag.js +320 -0
- package/components/sender/useSenderInput.d.ts +16 -0
- package/components/sender/useSenderInput.js +101 -0
- package/components/sender/useSenderPaste.d.ts +5 -0
- package/components/sender/useSenderPaste.js +36 -0
- package/components/sender/useSenderUpload.d.ts +11 -0
- package/components/sender/useSenderUpload.js +395 -0
- package/components/skeleton/skeleton.d.ts +2 -1
- package/components/skeleton/skeleton.js +1 -1
- package/components/think/index.d.ts +1 -0
- package/components/think/index.js +1 -0
- package/components/think/index.spec.d.ts +1 -0
- package/components/think/index.spec.js +345 -0
- package/components/think/index.vdt.js +82 -0
- package/components/think/styles.d.ts +5 -0
- package/components/think/styles.js +25 -0
- package/components/think/think.d.ts +28 -0
- package/components/think/think.js +48 -0
- package/components/think/useThinkExpand.d.ts +10 -0
- package/components/think/useThinkExpand.js +56 -0
- package/components/types.d.ts +4 -2
- package/components/upload/ajaxUploader.d.ts +1 -0
- package/components/upload/ajaxUploader.js +6 -0
- package/components/xmarkdown/index.d.ts +2 -0
- package/components/xmarkdown/index.js +1 -0
- package/components/xmarkdown/index.spec.d.ts +1 -0
- package/components/xmarkdown/index.spec.js +1666 -0
- package/components/xmarkdown/markdown/codeBlockRenderer.d.ts +8 -0
- package/components/xmarkdown/markdown/codeBlockRenderer.js +52 -0
- package/components/xmarkdown/markdown/codeblock.d.ts +8 -0
- package/components/xmarkdown/markdown/codeblock.js +74 -0
- package/components/xmarkdown/markdown/highlight.d.ts +17 -0
- package/components/xmarkdown/markdown/highlight.js +83 -0
- package/components/xmarkdown/markdown/index.d.ts +14 -0
- package/components/xmarkdown/markdown/index.js +14 -0
- package/components/xmarkdown/markdown/mermaid.d.ts +8 -0
- package/components/xmarkdown/markdown/mermaid.js +104 -0
- package/components/xmarkdown/markdown/renderTree.d.ts +54 -0
- package/components/xmarkdown/markdown/renderTree.js +386 -0
- package/components/xmarkdown/markdown/renderer.d.ts +18 -0
- package/components/xmarkdown/markdown/renderer.js +461 -0
- package/components/xmarkdown/markdown/streaming.d.ts +24 -0
- package/components/xmarkdown/markdown/streaming.js +513 -0
- package/components/xmarkdown/markdown/types.d.ts +124 -0
- package/components/xmarkdown/markdown/types.js +6 -0
- package/components/xmarkdown/markdown/utils.d.ts +7 -0
- package/components/xmarkdown/markdown/utils.js +9 -0
- package/components/xmarkdown/markdown.d.ts +1 -0
- package/components/xmarkdown/markdown.js +1 -0
- package/components/xmarkdown/styles.d.ts +5 -0
- package/components/xmarkdown/styles.js +50 -0
- package/components/xmarkdown/useMermaid.d.ts +27 -0
- package/components/xmarkdown/useMermaid.js +745 -0
- package/components/xmarkdown/useXMarkdownContent.d.ts +14 -0
- package/components/xmarkdown/useXMarkdownContent.js +218 -0
- package/components/xmarkdown/useXMarkdownDisplay.d.ts +26 -0
- package/components/xmarkdown/useXMarkdownDisplay.js +569 -0
- package/components/xmarkdown/xmarkdown.d.ts +61 -0
- package/components/xmarkdown/xmarkdown.js +109 -0
- package/components/xmarkdown/xmarkdown.vdt.js +43 -0
- package/dist/fonts/KaTeX_AMS-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_AMS-Regular.woff +0 -0
- package/dist/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_Fraktur-Bold.woff +0 -0
- package/dist/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Fraktur-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_Main-Bold.woff +0 -0
- package/dist/fonts/KaTeX_Main-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
- package/dist/fonts/KaTeX_Main-BoldItalic.woff +0 -0
- package/dist/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Italic.ttf +0 -0
- package/dist/fonts/KaTeX_Main-Italic.woff +0 -0
- package/dist/fonts/KaTeX_Main-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Main-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Main-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
- package/dist/fonts/KaTeX_Math-BoldItalic.woff +0 -0
- package/dist/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/dist/fonts/KaTeX_Math-Italic.ttf +0 -0
- package/dist/fonts/KaTeX_Math-Italic.woff +0 -0
- package/dist/fonts/KaTeX_Math-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_SansSerif-Bold.woff +0 -0
- package/dist/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
- package/dist/fonts/KaTeX_SansSerif-Italic.woff +0 -0
- package/dist/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_SansSerif-Regular.woff +0 -0
- package/dist/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Script-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Script-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Script-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size1-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size1-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size2-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size2-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size3-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size3-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size4-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size4-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Typewriter-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/dist/i18n/en-US.js +29 -1
- package/dist/i18n/en-US.js.map +1 -1
- package/dist/i18n/en-US.min.js +1 -1
- package/dist/index.js +100506 -37457
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1569 -1
- package/dist/kpc.css +4 -0
- package/dist/ksyun.css +4 -0
- package/i18n/en-US.d.ts +27 -0
- package/i18n/en-US.js +29 -1
- package/index.d.ts +9 -2
- package/index.js +9 -2
- package/package.json +8 -2
- package/styles/global.js +12 -6
- package/yarn-error.log +0 -1012
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
|
+
import _trimInstanceProperty from "@babel/runtime-corejs3/core-js/instance/trim";
|
|
3
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
|
|
4
|
+
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slice";
|
|
5
|
+
/**
|
|
6
|
+
* Markdown 渲染器
|
|
7
|
+
*
|
|
8
|
+
* 基于 markdown-it 生成 token,再转换为 Intact VNode。
|
|
9
|
+
*/
|
|
10
|
+
import MarkdownIt from 'markdown-it';
|
|
11
|
+
import { registerHighlightLanguages, normalizeLanguage } from './highlight';
|
|
12
|
+
import { renderCodeBlock } from './codeblock';
|
|
13
|
+
import { renderMermaidBlock } from './mermaid';
|
|
14
|
+
import { createElementNode, createKeyGenerator, createTextNode, parseHtmlFragment, parseSanitizedHtmlFragment, renderTreeNodes } from './renderTree';
|
|
15
|
+
// 初始化语法高亮语言
|
|
16
|
+
registerHighlightLanguages();
|
|
17
|
+
/**
|
|
18
|
+
* 创建 Markdown 渲染器
|
|
19
|
+
*/
|
|
20
|
+
export function createMarkdownRenderer(options) {
|
|
21
|
+
if (options === void 0) {
|
|
22
|
+
options = {};
|
|
23
|
+
}
|
|
24
|
+
var prefixCls = options.prefixCls || 'k';
|
|
25
|
+
// 创建 Markdown-it 实例
|
|
26
|
+
var markdown = new MarkdownIt({
|
|
27
|
+
html: !!options.allowHtml,
|
|
28
|
+
linkify: true,
|
|
29
|
+
breaks: true,
|
|
30
|
+
typographer: true,
|
|
31
|
+
langPrefix: 'language-'
|
|
32
|
+
});
|
|
33
|
+
// 启用数学公式渲染
|
|
34
|
+
if (options.enableFormula !== false && options.formulaRuntime) {
|
|
35
|
+
markdown.use(options.formulaRuntime.texmath, {
|
|
36
|
+
engine: options.formulaRuntime.katex,
|
|
37
|
+
delimiters: options.formulaDelimiters || ['dollars', 'beg_end'],
|
|
38
|
+
katexOptions: {
|
|
39
|
+
throwOnError: false,
|
|
40
|
+
strict: 'ignore',
|
|
41
|
+
macros: options.formulaMacros || {}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// 应用 Markdown 扩展插件
|
|
46
|
+
applyMarkdownPlugins(markdown, options.plugins);
|
|
47
|
+
return {
|
|
48
|
+
// 渲染整段 Markdown 源码
|
|
49
|
+
render: function render(source) {
|
|
50
|
+
return renderSource(source, createDocumentKey(source));
|
|
51
|
+
},
|
|
52
|
+
// 解析顶层块级源码片段
|
|
53
|
+
parseBlocks: function parseBlocks(source) {
|
|
54
|
+
return parseSourceBlocks(source);
|
|
55
|
+
},
|
|
56
|
+
// 渲染单个块级源码片段
|
|
57
|
+
renderBlock: function renderBlock(block, registerBlock) {
|
|
58
|
+
var result = renderSource(block.source, block.key, registerBlock);
|
|
59
|
+
return {
|
|
60
|
+
key: block.key,
|
|
61
|
+
source: block.source,
|
|
62
|
+
nodes: result.nodes,
|
|
63
|
+
blocks: result.blocks
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* 渲染整段 Markdown 源码
|
|
69
|
+
*/
|
|
70
|
+
function renderSource(source, keySeed, registerBlock) {
|
|
71
|
+
var nextKey = createKeyGenerator("xmarkdown-" + keySeed);
|
|
72
|
+
var _createRenderEnv = createRenderEnv(registerBlock),
|
|
73
|
+
env = _createRenderEnv.env,
|
|
74
|
+
blocks = _createRenderEnv.blocks;
|
|
75
|
+
// 解析 Markdown 源码
|
|
76
|
+
var tokens = markdown.parse(source || '', env);
|
|
77
|
+
// 将 tokens 转换为渲染树节点
|
|
78
|
+
var builtNodes = buildNodesFromTokens(tokens, options, nextKey, env);
|
|
79
|
+
// 应用渲染树转换插件
|
|
80
|
+
var nodes = applyRenderTreeTransforms(builtNodes, source, options);
|
|
81
|
+
return {
|
|
82
|
+
nodes: renderTreeNodes(nodes, options),
|
|
83
|
+
blocks: blocks
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 解析顶层块级源码片段
|
|
88
|
+
*/
|
|
89
|
+
function parseSourceBlocks(source) {
|
|
90
|
+
var normalized = normalizeSource(source);
|
|
91
|
+
if (!normalized) return [];
|
|
92
|
+
if (!_trimInstanceProperty(normalized).call(normalized)) return [];
|
|
93
|
+
var tokens = markdown.parse(normalized, {});
|
|
94
|
+
var ranges = collectTopLevelBlockRanges(tokens);
|
|
95
|
+
if (!ranges.length) {
|
|
96
|
+
return [{
|
|
97
|
+
key: createBlockKey('document', 0, normalized),
|
|
98
|
+
source: normalized
|
|
99
|
+
}];
|
|
100
|
+
}
|
|
101
|
+
var lines = normalized.split('\n');
|
|
102
|
+
return _mapInstanceProperty(ranges).call(ranges, function (_ref, index) {
|
|
103
|
+
var type = _ref.type,
|
|
104
|
+
start = _ref.start,
|
|
105
|
+
end = _ref.end;
|
|
106
|
+
var blockSource = _sliceInstanceProperty(lines).call(lines, start, end).join('\n');
|
|
107
|
+
return {
|
|
108
|
+
key: createBlockKey(type, index, blockSource),
|
|
109
|
+
source: blockSource
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 将 block token 转成渲染树节点
|
|
115
|
+
*/
|
|
116
|
+
function buildNodesFromTokens(tokens, rendererOptions, nextNodeKey, env) {
|
|
117
|
+
var root = createElementNode('div', {}, [], nextNodeKey('root'));
|
|
118
|
+
var stack = [root];
|
|
119
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
120
|
+
var token = tokens[i];
|
|
121
|
+
var parent = stack[stack.length - 1];
|
|
122
|
+
if (token.type === 'inline') {
|
|
123
|
+
var _parent$children;
|
|
124
|
+
(_parent$children = parent.children).push.apply(_parent$children, buildInlineNodes(token.children || [], rendererOptions, nextNodeKey));
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (token.type === 'fence' || token.type === 'code_block') {
|
|
128
|
+
var info = String(token.info || '');
|
|
129
|
+
var language = normalizeLanguage(info);
|
|
130
|
+
var source = String(token.content || '').replace(/\n$/, '');
|
|
131
|
+
parent.children.push(language === 'mermaid' && rendererOptions.enableMermaid !== false ? renderMermaidBlock(source, info, rendererOptions, env) : renderCodeBlock(source, info, rendererOptions, env));
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (token.type === 'math_block') {
|
|
135
|
+
var _parent$children2;
|
|
136
|
+
(_parent$children2 = parent.children).push.apply(_parent$children2, renderMathNodes(String(token.content || ''), true, rendererOptions, nextNodeKey));
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (token.type === 'html_block') {
|
|
140
|
+
var _parent$children3;
|
|
141
|
+
(_parent$children3 = parent.children).push.apply(_parent$children3, parseSanitizedHtmlFragment(String(token.content || ''), rendererOptions, nextNodeKey));
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (token.type === 'hr') {
|
|
145
|
+
parent.children.push(createElementNode('hr', tokenAttrsToObject(token), [], nextNodeKey('hr')));
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (token.nesting === 1) {
|
|
149
|
+
if (token.type === 'table_open') {
|
|
150
|
+
var wrapper = createElementNode('div', {
|
|
151
|
+
className: prefixCls + "-xmarkdown-table-wrap"
|
|
152
|
+
}, [], nextNodeKey('table-wrap'));
|
|
153
|
+
var table = createElementNode('table', tokenAttrsToObject(token), [], nextNodeKey('table'));
|
|
154
|
+
wrapper.children.push(table);
|
|
155
|
+
parent.children.push(wrapper);
|
|
156
|
+
stack.push(wrapper);
|
|
157
|
+
stack.push(table);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
var element = createElementNode(token.tag, tokenAttrsToObject(token), [], nextNodeKey(token.tag));
|
|
161
|
+
parent.children.push(element);
|
|
162
|
+
stack.push(element);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (token.nesting === -1) {
|
|
166
|
+
if (token.type === 'table_close') {
|
|
167
|
+
stack.pop();
|
|
168
|
+
stack.pop();
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
stack.pop();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return root.children;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* 将 inline token 转成渲染树节点
|
|
178
|
+
*/
|
|
179
|
+
function buildInlineNodes(tokens, rendererOptions, nextNodeKey) {
|
|
180
|
+
var root = createElementNode('span', {}, [], nextNodeKey('inline-root'));
|
|
181
|
+
var stack = [root];
|
|
182
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
183
|
+
var token = tokens[i];
|
|
184
|
+
var parent = stack[stack.length - 1];
|
|
185
|
+
if (token.type === 'text') {
|
|
186
|
+
parent.children.push(createTextNode(String(token.content || '')));
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (token.type === 'softbreak' || token.type === 'hardbreak') {
|
|
190
|
+
parent.children.push(createElementNode('br', {}, [], nextNodeKey('br')));
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (token.type === 'code_inline') {
|
|
194
|
+
parent.children.push(createElementNode('code', {
|
|
195
|
+
className: prefixCls + "-xmarkdown-inline-code"
|
|
196
|
+
}, [createTextNode(String(token.content || ''))], nextNodeKey('code-inline')));
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (token.type === 'image') {
|
|
200
|
+
parent.children.push(createElementNode('img', _extends({}, tokenAttrsToObject(token), {
|
|
201
|
+
alt: token.content || (token.attrGet == null ? void 0 : token.attrGet('alt')) || ''
|
|
202
|
+
}), [], nextNodeKey('image')));
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (token.type === 'math_inline' || token.type === 'math_inline_double') {
|
|
206
|
+
var _parent$children4;
|
|
207
|
+
(_parent$children4 = parent.children).push.apply(_parent$children4, renderMathNodes(String(token.content || ''), token.type !== 'math_inline', rendererOptions, nextNodeKey));
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (token.type === 'html_inline') {
|
|
211
|
+
var _parent$children6;
|
|
212
|
+
var collected = collectInlineHtmlFragment(tokens, i, rendererOptions, nextNodeKey);
|
|
213
|
+
if (collected) {
|
|
214
|
+
var _parent$children5;
|
|
215
|
+
(_parent$children5 = parent.children).push.apply(_parent$children5, collected.nodes);
|
|
216
|
+
i = collected.endIndex;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
(_parent$children6 = parent.children).push.apply(_parent$children6, parseSanitizedHtmlFragment(String(token.content || ''), rendererOptions, nextNodeKey));
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (token.nesting === 1) {
|
|
223
|
+
var element = createElementNode(token.tag, tokenAttrsToObject(token), [], nextNodeKey(token.tag || token.type));
|
|
224
|
+
parent.children.push(element);
|
|
225
|
+
stack.push(element);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (token.nesting === -1) {
|
|
229
|
+
stack.pop();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return root.children;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* 收集成对的 inline HTML 片段
|
|
236
|
+
*/
|
|
237
|
+
function collectInlineHtmlFragment(tokens, startIndex, rendererOptions, nextNodeKey) {
|
|
238
|
+
var current = parseHtmlToken(String(tokens[startIndex].content || ''));
|
|
239
|
+
if (!current || current.kind !== 'open') return null;
|
|
240
|
+
var depth = 1;
|
|
241
|
+
var fragment = String(tokens[startIndex].content || '');
|
|
242
|
+
for (var i = startIndex + 1; i < tokens.length; i++) {
|
|
243
|
+
var token = tokens[i];
|
|
244
|
+
fragment += getInlineTokenRawContent(token);
|
|
245
|
+
if (token.type === 'html_inline') {
|
|
246
|
+
var next = parseHtmlToken(String(token.content || ''));
|
|
247
|
+
if (next && next.tag === current.tag) {
|
|
248
|
+
if (next.kind === 'open') {
|
|
249
|
+
depth++;
|
|
250
|
+
} else if (next.kind === 'close') {
|
|
251
|
+
depth--;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (depth === 0) {
|
|
256
|
+
return {
|
|
257
|
+
endIndex: i,
|
|
258
|
+
nodes: parseSanitizedHtmlFragment(fragment, rendererOptions, nextNodeKey)
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* 应用 Markdown 扩展插件
|
|
267
|
+
*/
|
|
268
|
+
function applyMarkdownPlugins(markdown, plugins) {
|
|
269
|
+
if (!plugins || !plugins.length) return;
|
|
270
|
+
plugins.forEach(function (plugin) {
|
|
271
|
+
plugin.extendMarkdown == null || plugin.extendMarkdown(markdown);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* 应用渲染树转换插件
|
|
276
|
+
*/
|
|
277
|
+
function applyRenderTreeTransforms(nodes, source, options) {
|
|
278
|
+
var plugins = options.plugins;
|
|
279
|
+
if (!plugins || !plugins.length) return nodes;
|
|
280
|
+
var nextNodes = nodes;
|
|
281
|
+
plugins.forEach(function (plugin) {
|
|
282
|
+
if (!plugin.transformRenderTree) return;
|
|
283
|
+
var transformed = plugin.transformRenderTree(nextNodes, {
|
|
284
|
+
source: source,
|
|
285
|
+
options: options
|
|
286
|
+
});
|
|
287
|
+
if (transformed) {
|
|
288
|
+
nextNodes = transformed;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
return nextNodes;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* 创建渲染期上下文
|
|
295
|
+
*/
|
|
296
|
+
function createRenderEnv(_registerBlock) {
|
|
297
|
+
var blocks = {};
|
|
298
|
+
var blockId = 0;
|
|
299
|
+
return {
|
|
300
|
+
env: {
|
|
301
|
+
registerBlock: function registerBlock(type, blockSource, language) {
|
|
302
|
+
var id = _registerBlock ? _registerBlock(type, blockSource, language) : "xmarkdown-block-" + blockId++;
|
|
303
|
+
blocks[id] = {
|
|
304
|
+
id: id,
|
|
305
|
+
type: type,
|
|
306
|
+
source: blockSource,
|
|
307
|
+
language: language
|
|
308
|
+
};
|
|
309
|
+
return id;
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
blocks: blocks
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* 渲染数学公式节点
|
|
317
|
+
*/
|
|
318
|
+
function renderMathNodes(source, displayMode, options, nextKey) {
|
|
319
|
+
var runtime = options.formulaRuntime;
|
|
320
|
+
if (!runtime || !runtime.katex || typeof runtime.katex.renderToString !== 'function') {
|
|
321
|
+
return [createTextNode(source)];
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
var html = runtime.katex.renderToString(source, {
|
|
325
|
+
displayMode: displayMode,
|
|
326
|
+
throwOnError: false,
|
|
327
|
+
strict: 'ignore',
|
|
328
|
+
macros: options.formulaMacros || {}
|
|
329
|
+
});
|
|
330
|
+
return parseHtmlFragment(html, nextKey);
|
|
331
|
+
} catch (e) {
|
|
332
|
+
return [createTextNode(source)];
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* 提取 token 属性对象
|
|
337
|
+
*/
|
|
338
|
+
function tokenAttrsToObject(token) {
|
|
339
|
+
if (!token || !Array.isArray(token.attrs)) return {};
|
|
340
|
+
return token.attrs.reduce(function (result, _ref2) {
|
|
341
|
+
var name = _ref2[0],
|
|
342
|
+
value = _ref2[1];
|
|
343
|
+
result[name === 'class' ? 'className' : name] = value;
|
|
344
|
+
return result;
|
|
345
|
+
}, {});
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* 解析 HTML token 的标签信息
|
|
349
|
+
*/
|
|
350
|
+
function parseHtmlToken(content) {
|
|
351
|
+
var normalized = _trimInstanceProperty(content).call(content);
|
|
352
|
+
if (!normalized) return null;
|
|
353
|
+
var closeMatch = normalized.match(/^<\/([A-Za-z][\w-]*)\s*>$/);
|
|
354
|
+
if (closeMatch) {
|
|
355
|
+
return {
|
|
356
|
+
kind: 'close',
|
|
357
|
+
tag: closeMatch[1].toLowerCase()
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
var openMatch = normalized.match(/^<([A-Za-z][\w-]*)([\s\S]*?)>$/);
|
|
361
|
+
if (!openMatch) return null;
|
|
362
|
+
return {
|
|
363
|
+
kind: /\/>$/.test(normalized) ? 'self' : 'open',
|
|
364
|
+
tag: openMatch[1].toLowerCase()
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* 还原 inline token 的原始文本
|
|
369
|
+
*/
|
|
370
|
+
function getInlineTokenRawContent(token) {
|
|
371
|
+
if (!token) return '';
|
|
372
|
+
switch (token.type) {
|
|
373
|
+
case 'text':
|
|
374
|
+
return String(token.content || '');
|
|
375
|
+
case 'softbreak':
|
|
376
|
+
case 'hardbreak':
|
|
377
|
+
return '\n';
|
|
378
|
+
case 'html_inline':
|
|
379
|
+
return String(token.content || '');
|
|
380
|
+
default:
|
|
381
|
+
return String(token.content || '');
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* 收集顶层 block 的行号范围
|
|
386
|
+
*/
|
|
387
|
+
function collectTopLevelBlockRanges(tokens) {
|
|
388
|
+
var ranges = [];
|
|
389
|
+
var depth = 0;
|
|
390
|
+
tokens.forEach(function (token) {
|
|
391
|
+
var atTopLevel = depth === 0;
|
|
392
|
+
if (atTopLevel) {
|
|
393
|
+
var range = getTokenLineRange(token);
|
|
394
|
+
if (range) {
|
|
395
|
+
ranges.push(_extends({
|
|
396
|
+
type: token.type || token.tag || 'block'
|
|
397
|
+
}, range));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (token.nesting === 1) {
|
|
401
|
+
depth++;
|
|
402
|
+
} else if (token.nesting === -1) {
|
|
403
|
+
depth = Math.max(depth - 1, 0);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
return mergeAdjacentRanges(ranges);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* 获取 token 对应的源码行号范围
|
|
410
|
+
*/
|
|
411
|
+
function getTokenLineRange(token) {
|
|
412
|
+
if (token && Array.isArray(_mapInstanceProperty(token)) && _mapInstanceProperty(token).length === 2) {
|
|
413
|
+
return {
|
|
414
|
+
start: _mapInstanceProperty(token)[0],
|
|
415
|
+
end: _mapInstanceProperty(token)[1]
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* 合并重复的顶层 block 范围
|
|
422
|
+
*/
|
|
423
|
+
function mergeAdjacentRanges(ranges) {
|
|
424
|
+
var merged = [];
|
|
425
|
+
ranges.forEach(function (range) {
|
|
426
|
+
var previous = merged[merged.length - 1];
|
|
427
|
+
if (!previous || previous.start !== range.start || previous.end !== range.end) {
|
|
428
|
+
merged.push(range);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
return merged;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* 生成整段文档的渲染 key
|
|
435
|
+
*/
|
|
436
|
+
function createDocumentKey(source) {
|
|
437
|
+
return "document-" + hashString(normalizeSource(source));
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* 生成顶层 block 的稳定 key
|
|
441
|
+
*/
|
|
442
|
+
function createBlockKey(type, index, source) {
|
|
443
|
+
return type + "-" + index + "-" + hashString(source);
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* 统一标准化 Markdown 源码
|
|
447
|
+
*/
|
|
448
|
+
function normalizeSource(source) {
|
|
449
|
+
return String(source || '').replace(/\r\n?/g, '\n');
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* 生成轻量级字符串哈希
|
|
453
|
+
*/
|
|
454
|
+
function hashString(source) {
|
|
455
|
+
var hash = 0;
|
|
456
|
+
for (var i = 0; i < source.length; i++) {
|
|
457
|
+
hash = hash * 33 + source.charCodeAt(i) >>> 0;
|
|
458
|
+
}
|
|
459
|
+
return hash.toString(36);
|
|
460
|
+
}
|
|
461
|
+
export { renderCodeBlock, renderMermaidBlock };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 流式渲染
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenFenceInfo, StreamingMarkdownSegments, XMarkdownRenderOptions, XMarkdownStreamingTailCache } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* 创建流式尾部缓存
|
|
7
|
+
*/
|
|
8
|
+
export declare function createStreamingTailCache(): XMarkdownStreamingTailCache;
|
|
9
|
+
/**
|
|
10
|
+
* 判断源码中是否包含公式语法
|
|
11
|
+
*/
|
|
12
|
+
export declare function containsFormulaSyntax(source: string, delimiters?: string | string[]): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 将流式 Markdown 拆分为 stable 和 tail 两段
|
|
15
|
+
*/
|
|
16
|
+
export declare function splitMarkdownForStreaming(source: string, cache?: XMarkdownStreamingTailCache): StreamingMarkdownSegments;
|
|
17
|
+
/**
|
|
18
|
+
* 渲染尚未进入 stable 区的尾部内容
|
|
19
|
+
*/
|
|
20
|
+
export declare function renderMarkdownTail(tailText: string, openFence?: OpenFenceInfo | null, options?: XMarkdownRenderOptions): any[];
|
|
21
|
+
/**
|
|
22
|
+
* 转义 tail 中的 HTML 文本
|
|
23
|
+
*/
|
|
24
|
+
export declare function escapeMarkdownHtml(text: string): string;
|