@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,386 @@
|
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
|
+
import _Set from "@babel/runtime-corejs3/core-js/set";
|
|
3
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
|
|
4
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js/instance/filter";
|
|
5
|
+
import _trimInstanceProperty from "@babel/runtime-corejs3/core-js/instance/trim";
|
|
6
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js/object/keys";
|
|
7
|
+
import _Array$from from "@babel/runtime-corejs3/core-js/array/from";
|
|
8
|
+
import DOMPurify from 'dompurify';
|
|
9
|
+
import { createVNode } from 'intact-vue-next';
|
|
10
|
+
var VOID_TAGS = new _Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
11
|
+
var BLOCK_TAGS = new _Set(['address', 'article', 'aside', 'blockquote', 'details', 'dialog', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul']);
|
|
12
|
+
/**
|
|
13
|
+
* 创建节点 key 生成器
|
|
14
|
+
*/
|
|
15
|
+
export function createKeyGenerator(prefix) {
|
|
16
|
+
if (prefix === void 0) {
|
|
17
|
+
prefix = 'xmarkdown-node';
|
|
18
|
+
}
|
|
19
|
+
var index = 0;
|
|
20
|
+
return function (scope) {
|
|
21
|
+
if (scope === void 0) {
|
|
22
|
+
scope = 'node';
|
|
23
|
+
}
|
|
24
|
+
return prefix + "-" + scope + "-" + index++;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 创建文本节点
|
|
29
|
+
*/
|
|
30
|
+
export function createTextNode(content) {
|
|
31
|
+
return {
|
|
32
|
+
type: 'text',
|
|
33
|
+
content: content
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 创建元素节点
|
|
38
|
+
*/
|
|
39
|
+
export function createElementNode(tag, attrs, children, key) {
|
|
40
|
+
if (attrs === void 0) {
|
|
41
|
+
attrs = {};
|
|
42
|
+
}
|
|
43
|
+
if (children === void 0) {
|
|
44
|
+
children = [];
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
type: 'element',
|
|
48
|
+
tag: tag,
|
|
49
|
+
attrs: attrs,
|
|
50
|
+
children: children,
|
|
51
|
+
key: key
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 创建自定义渲染节点
|
|
56
|
+
*/
|
|
57
|
+
export function createIslandNode(value, block) {
|
|
58
|
+
if (block === void 0) {
|
|
59
|
+
block = false;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
type: 'island',
|
|
63
|
+
value: value,
|
|
64
|
+
block: block
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 清洗并解析 HTML 片段
|
|
69
|
+
*/
|
|
70
|
+
export function parseSanitizedHtmlFragment(html, options, nextKey) {
|
|
71
|
+
var sanitized = sanitizeHtmlFragment(html, options.sanitizeOptions);
|
|
72
|
+
return parseHtmlFragment(sanitized, nextKey);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 解析 HTML 片段为渲染树节点
|
|
76
|
+
*/
|
|
77
|
+
export function parseHtmlFragment(html, nextKey) {
|
|
78
|
+
if (!html) return [];
|
|
79
|
+
if (typeof DOMParser === 'undefined') {
|
|
80
|
+
return [createTextNode(html)];
|
|
81
|
+
}
|
|
82
|
+
var parser = new DOMParser();
|
|
83
|
+
var document = parser.parseFromString("<body>" + html + "</body>", 'text/html');
|
|
84
|
+
return convertDomChildrenToRenderNodes(document.body.childNodes, nextKey);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 将渲染树节点转换为 VNode
|
|
88
|
+
*/
|
|
89
|
+
export function renderTreeNodes(nodes, options) {
|
|
90
|
+
var rendered = [];
|
|
91
|
+
nodes.forEach(function (node) {
|
|
92
|
+
appendRenderedValue(rendered, renderTreeNode(node, options));
|
|
93
|
+
});
|
|
94
|
+
return rendered;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 序列化渲染树节点
|
|
98
|
+
*/
|
|
99
|
+
export function serializeRenderTreeNodes(nodes) {
|
|
100
|
+
return _mapInstanceProperty(nodes).call(nodes, serializeRenderTreeNode).join('');
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 获取渲染树的纯文本内容
|
|
104
|
+
*/
|
|
105
|
+
export function getTextContent(nodes) {
|
|
106
|
+
return _mapInstanceProperty(nodes).call(nodes, getNodeTextContent).join('');
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 渲染单个渲染树节点
|
|
110
|
+
*/
|
|
111
|
+
function renderTreeNode(node, options) {
|
|
112
|
+
var _options$tagRenderers;
|
|
113
|
+
if (node.type === 'text') {
|
|
114
|
+
return node.content;
|
|
115
|
+
}
|
|
116
|
+
if (node.type === 'island') {
|
|
117
|
+
return normalizeRendererOutput(node.value, options);
|
|
118
|
+
}
|
|
119
|
+
var normalizedParagraph = normalizeParagraphNode(node, options);
|
|
120
|
+
if (normalizedParagraph) {
|
|
121
|
+
return normalizedParagraph;
|
|
122
|
+
}
|
|
123
|
+
var attrs = applyTagAttrs(node, options);
|
|
124
|
+
var renderer = (_options$tagRenderers = options.tagRenderers) == null ? void 0 : _options$tagRenderers[node.tag];
|
|
125
|
+
if (renderer) {
|
|
126
|
+
var rendered = renderer({
|
|
127
|
+
tag: node.tag,
|
|
128
|
+
attrs: attrs,
|
|
129
|
+
html: serializeElement(node.tag, attrs, node.children),
|
|
130
|
+
innerHTML: serializeRenderTreeNodes(node.children),
|
|
131
|
+
textContent: getTextContent(node.children),
|
|
132
|
+
streaming: !!options.streaming,
|
|
133
|
+
typing: !!options.typing
|
|
134
|
+
});
|
|
135
|
+
if (rendered !== undefined) {
|
|
136
|
+
return normalizeRendererOutput(rendered, options);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
var children = renderTreeNodes(node.children, options);
|
|
140
|
+
var props = toVNodeProps(attrs, node.key);
|
|
141
|
+
return createVNode(node.tag, props, children);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 规范化只包含块级子节点的段落
|
|
145
|
+
*/
|
|
146
|
+
function normalizeParagraphNode(node, options) {
|
|
147
|
+
var _context;
|
|
148
|
+
if (node.tag !== 'p') return null;
|
|
149
|
+
var blockChildren = _filterInstanceProperty(_context = node.children).call(_context, function (child) {
|
|
150
|
+
return isParagraphBlockChild(child, options);
|
|
151
|
+
});
|
|
152
|
+
if (!blockChildren.length) return null;
|
|
153
|
+
var hasInlineContent = node.children.some(function (child) {
|
|
154
|
+
var _context2;
|
|
155
|
+
if (isParagraphBlockChild(child, options)) return false;
|
|
156
|
+
return child.type !== 'text' || !!_trimInstanceProperty(_context2 = child.content).call(_context2);
|
|
157
|
+
});
|
|
158
|
+
if (hasInlineContent) return null;
|
|
159
|
+
var rendered = [];
|
|
160
|
+
node.children.forEach(function (child) {
|
|
161
|
+
var _context3;
|
|
162
|
+
if (child.type === 'text' && !_trimInstanceProperty(_context3 = child.content).call(_context3)) return;
|
|
163
|
+
appendRenderedValue(rendered, renderTreeNode(child, options));
|
|
164
|
+
});
|
|
165
|
+
return rendered;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 判断节点是否可作为段落中的块级子节点
|
|
169
|
+
*/
|
|
170
|
+
function isParagraphBlockChild(node, options) {
|
|
171
|
+
var _options$tagRenderers2;
|
|
172
|
+
if (node.type === 'island') {
|
|
173
|
+
return node.block;
|
|
174
|
+
}
|
|
175
|
+
return node.type === 'element' && (BLOCK_TAGS.has(node.tag) || !!((_options$tagRenderers2 = options.tagRenderers) != null && _options$tagRenderers2[node.tag]));
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* 应用默认属性和自定义标签属性
|
|
179
|
+
*/
|
|
180
|
+
function applyTagAttrs(node, options) {
|
|
181
|
+
var _options$tagAttrs;
|
|
182
|
+
var attrs = _extends({}, node.attrs);
|
|
183
|
+
applyDefaultElementAttrs(node.tag, attrs);
|
|
184
|
+
var resolver = (_options$tagAttrs = options.tagAttrs) == null ? void 0 : _options$tagAttrs[node.tag];
|
|
185
|
+
if (!resolver) return attrs;
|
|
186
|
+
var resolved = typeof resolver === 'function' ? resolver({
|
|
187
|
+
tag: node.tag,
|
|
188
|
+
attrs: _extends({}, attrs),
|
|
189
|
+
html: serializeElement(node.tag, attrs, node.children),
|
|
190
|
+
textContent: getTextContent(node.children)
|
|
191
|
+
}) : resolver;
|
|
192
|
+
if (!resolved) return attrs;
|
|
193
|
+
return mergeAttrs(attrs, resolved);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 合并标签属性
|
|
197
|
+
*/
|
|
198
|
+
function mergeAttrs(baseAttrs, patch) {
|
|
199
|
+
var attrs = _extends({}, baseAttrs);
|
|
200
|
+
_Object$keys(patch).forEach(function (name) {
|
|
201
|
+
var value = patch[name];
|
|
202
|
+
var normalizedName = normalizeAttrName(name);
|
|
203
|
+
if (value === undefined || value === null || value === false) {
|
|
204
|
+
delete attrs[normalizedName];
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
attrs[normalizedName] = value;
|
|
208
|
+
});
|
|
209
|
+
return attrs;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* 规范化自定义渲染器输出
|
|
213
|
+
*/
|
|
214
|
+
function normalizeRendererOutput(value, options) {
|
|
215
|
+
var normalize = options.normalizeRendererOutput;
|
|
216
|
+
return normalize ? normalize(value) : value;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* 将渲染结果安全地压入数组
|
|
220
|
+
*/
|
|
221
|
+
function appendRenderedValue(target, value) {
|
|
222
|
+
if (value === undefined || value === null || value === false) return;
|
|
223
|
+
if (Array.isArray(value)) {
|
|
224
|
+
value.forEach(function (item) {
|
|
225
|
+
return appendRenderedValue(target, item);
|
|
226
|
+
});
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
target.push(value);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* 应用元素默认属性
|
|
233
|
+
*/
|
|
234
|
+
function applyDefaultElementAttrs(tag, attrs) {
|
|
235
|
+
if (tag === 'a') {
|
|
236
|
+
var href = attrs.href || '';
|
|
237
|
+
if (/^(https?:)?\/\//i.test(href)) {
|
|
238
|
+
if (!attrs.target) {
|
|
239
|
+
attrs.target = '_blank';
|
|
240
|
+
}
|
|
241
|
+
if (!attrs.rel) {
|
|
242
|
+
attrs.rel = 'noopener noreferrer';
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (tag === 'img') {
|
|
248
|
+
if (!attrs.loading) {
|
|
249
|
+
attrs.loading = 'lazy';
|
|
250
|
+
}
|
|
251
|
+
if (!attrs.decoding) {
|
|
252
|
+
attrs.decoding = 'async';
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 将属性对象转换为 VNode props
|
|
258
|
+
*/
|
|
259
|
+
function toVNodeProps(attrs, key) {
|
|
260
|
+
var props = key ? {
|
|
261
|
+
key: key
|
|
262
|
+
} : {};
|
|
263
|
+
_Object$keys(attrs).forEach(function (name) {
|
|
264
|
+
var value = attrs[name];
|
|
265
|
+
if (value === undefined || value === null || value === false) return;
|
|
266
|
+
props[normalizeAttrName(name)] = value;
|
|
267
|
+
});
|
|
268
|
+
return props;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* 规范化属性名
|
|
272
|
+
*/
|
|
273
|
+
function normalizeAttrName(name) {
|
|
274
|
+
return name === 'class' ? 'className' : name;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* 清洗 HTML 片段
|
|
278
|
+
*/
|
|
279
|
+
function sanitizeHtmlFragment(html, sanitizeOptions) {
|
|
280
|
+
return DOMPurify.sanitize(html, _extends({
|
|
281
|
+
USE_PROFILES: {
|
|
282
|
+
html: true,
|
|
283
|
+
mathMl: true
|
|
284
|
+
},
|
|
285
|
+
ALLOW_DATA_ATTR: true,
|
|
286
|
+
ADD_ATTR: ['target', 'rel', 'class', 'loading', 'decoding', 'type', 'title']
|
|
287
|
+
}, sanitizeOptions));
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* 将 DOM 子节点转换为渲染树节点
|
|
291
|
+
*/
|
|
292
|
+
function convertDomChildrenToRenderNodes(nodes, nextKey) {
|
|
293
|
+
var result = [];
|
|
294
|
+
_Array$from(nodes).forEach(function (node) {
|
|
295
|
+
appendDomNode(result, node, nextKey);
|
|
296
|
+
});
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* 追加单个 DOM 节点到渲染树结果
|
|
301
|
+
*/
|
|
302
|
+
function appendDomNode(result, node, nextKey) {
|
|
303
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
304
|
+
if (!node.textContent) return;
|
|
305
|
+
result.push(createTextNode(node.textContent));
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
309
|
+
var element = node;
|
|
310
|
+
var attrs = _Array$from(element.attributes).reduce(function (current, attribute) {
|
|
311
|
+
current[normalizeAttrName(attribute.name)] = attribute.value;
|
|
312
|
+
return current;
|
|
313
|
+
}, {});
|
|
314
|
+
result.push(createElementNode(element.tagName.toLowerCase(), attrs, convertDomChildrenToRenderNodes(element.childNodes, nextKey), nextKey(element.tagName.toLowerCase())));
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* 序列化单个渲染树节点
|
|
318
|
+
*/
|
|
319
|
+
function serializeRenderTreeNode(node) {
|
|
320
|
+
if (node.type === 'text') {
|
|
321
|
+
return escapeHtml(node.content);
|
|
322
|
+
}
|
|
323
|
+
if (node.type === 'island') {
|
|
324
|
+
return '';
|
|
325
|
+
}
|
|
326
|
+
return serializeElement(node.tag, node.attrs, node.children);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* 序列化元素节点
|
|
330
|
+
*/
|
|
331
|
+
function serializeElement(tag, attrs, children) {
|
|
332
|
+
var serializedAttrs = _Object$keys(attrs).reduce(function (result, name) {
|
|
333
|
+
var value = attrs[name];
|
|
334
|
+
if (value === undefined || value === null || value === false) return result;
|
|
335
|
+
var attrName = name === 'className' ? 'class' : name;
|
|
336
|
+
if (value === true) {
|
|
337
|
+
result.push(attrName);
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
340
|
+
var attrValue = attrName === 'style' && value && typeof value === 'object' ? styleObjectToString(value) : String(value);
|
|
341
|
+
result.push(attrName + "=\"" + escapeHtml(attrValue) + "\"");
|
|
342
|
+
return result;
|
|
343
|
+
}, []);
|
|
344
|
+
var openTag = serializedAttrs.length ? "<" + tag + " " + serializedAttrs.join(' ') + ">" : "<" + tag + ">";
|
|
345
|
+
if (VOID_TAGS.has(tag)) {
|
|
346
|
+
return openTag;
|
|
347
|
+
}
|
|
348
|
+
return "" + openTag + serializeRenderTreeNodes(children) + "</" + tag + ">";
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* 获取单个节点的文本内容
|
|
352
|
+
*/
|
|
353
|
+
function getNodeTextContent(node) {
|
|
354
|
+
if (node.type === 'text') {
|
|
355
|
+
return node.content;
|
|
356
|
+
}
|
|
357
|
+
if (node.type === 'island') {
|
|
358
|
+
return '';
|
|
359
|
+
}
|
|
360
|
+
return getTextContent(node.children);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* 将 style 对象序列化为字符串
|
|
364
|
+
*/
|
|
365
|
+
function styleObjectToString(style) {
|
|
366
|
+
var _context4, _context5;
|
|
367
|
+
return _mapInstanceProperty(_context4 = _filterInstanceProperty(_context5 = _Object$keys(style)).call(_context5, function (key) {
|
|
368
|
+
return style[key] !== undefined && style[key] !== null && style[key] !== '';
|
|
369
|
+
})).call(_context4, function (key) {
|
|
370
|
+
return toKebabCase(key) + ": " + style[key];
|
|
371
|
+
}).join('; ');
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* 将驼峰命名转换为 kebab-case
|
|
375
|
+
*/
|
|
376
|
+
function toKebabCase(value) {
|
|
377
|
+
return value.replace(/[A-Z]/g, function (match) {
|
|
378
|
+
return "-" + match.toLowerCase();
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* 转义 HTML 文本
|
|
383
|
+
*/
|
|
384
|
+
function escapeHtml(text) {
|
|
385
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
386
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown 渲染器
|
|
3
|
+
*
|
|
4
|
+
* 基于 markdown-it 生成 token,再转换为 Intact VNode。
|
|
5
|
+
*/
|
|
6
|
+
import { renderCodeBlock } from './codeblock';
|
|
7
|
+
import { renderMermaidBlock } from './mermaid';
|
|
8
|
+
import type { XMarkdownRegisterRenderedBlock, XMarkdownRenderOptions, XMarkdownRenderResult, XMarkdownRenderedStableBlock, XMarkdownSourceBlock } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* 创建 Markdown 渲染器
|
|
11
|
+
*/
|
|
12
|
+
export declare function createMarkdownRenderer(options?: XMarkdownRenderOptions): {
|
|
13
|
+
render(source: string): XMarkdownRenderResult;
|
|
14
|
+
parseBlocks(source: string): XMarkdownSourceBlock[];
|
|
15
|
+
renderBlock(block: XMarkdownSourceBlock, registerBlock?: XMarkdownRegisterRenderedBlock): XMarkdownRenderedStableBlock;
|
|
16
|
+
};
|
|
17
|
+
export type { XMarkdownRenderOptions, XMarkdownRenderResult } from './types';
|
|
18
|
+
export { renderCodeBlock, renderMermaidBlock, };
|