@agentscope-ai/chat 1.1.39 → 1.1.41-beta.1764749089549
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/bin/starter_webui.zip +0 -0
- package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Builder.tsx +8 -4
- package/components/ImageGenerator/index.tsx +1 -1
- package/components/Markdown/Markdown.tsx +105 -0
- package/components/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.tsx +1 -1
- package/components/Markdown/core/components/Null.tsx +1 -0
- package/components/Markdown/core/components/Raw.tsx +18 -0
- package/components/Markdown/{Markdown → core}/hooks/useCitationsData.tsx +3 -7
- package/components/Markdown/core/hooks/useCursorContent.tsx +15 -0
- package/components/Markdown/{Markdown/hooks/useTyping.ts → core/hooks/useTyping.tsx} +4 -1
- package/components/Markdown/core/index.tsx +18 -0
- package/components/Markdown/{plugins → core/plugins}/citations/CitationComponent.tsx +5 -3
- package/components/Markdown/{plugins → core/plugins}/citations/index.tsx +3 -4
- package/components/Markdown/{plugins → core/plugins}/cursor/Underline.tsx +1 -1
- package/components/Markdown/{plugins → core/plugins}/cursor/index.tsx +8 -8
- package/components/Markdown/demo/cursor.tsx +2 -3
- package/components/Markdown/index.en-US.md +1 -2
- package/components/Markdown/index.tsx +6 -0
- package/components/Markdown/index.zh-CN.md +1 -2
- package/components/Markdown/{Markdown/style.ts → styles.ts} +12 -21
- package/components/Markdown/types.tsx +94 -0
- package/components/index.ts +1 -3
- package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Builder.js +5 -3
- package/lib/ImageGenerator/index.js +1 -1
- package/lib/Markdown/Markdown.d.ts +4 -0
- package/lib/Markdown/Markdown.js +110 -0
- package/lib/Markdown/core/components/Null.d.ts +2 -0
- package/lib/Markdown/core/components/Null.js +3 -0
- package/lib/Markdown/core/components/Raw.d.ts +8 -0
- package/lib/Markdown/core/components/Raw.js +13 -0
- package/lib/Markdown/core/hooks/useCitationsData.d.ts +6 -0
- package/lib/Markdown/{Markdown → core}/hooks/useCitationsData.js +1 -1
- package/lib/Markdown/core/hooks/useCursorContent.d.ts +4 -0
- package/lib/Markdown/core/hooks/useCursorContent.js +14 -0
- package/lib/Markdown/core/hooks/useTyping.d.ts +5 -0
- package/lib/Markdown/{Markdown → core}/hooks/useTyping.js +3 -2
- package/lib/Markdown/core/index.d.ts +2 -0
- package/lib/Markdown/{Markdown/hooks/useAnimation.js → core/index.js} +23 -23
- package/lib/Markdown/{plugins → core/plugins}/citations/CitationComponent.js +5 -5
- package/lib/Markdown/{plugins → core/plugins}/citations/index.d.ts +1 -2
- package/lib/Markdown/{plugins → core/plugins}/citations/index.js +1 -1
- package/lib/Markdown/{plugins → core/plugins}/cursor/Dot.js +1 -1
- package/lib/Markdown/{plugins → core/plugins}/cursor/Underline.js +1 -1
- package/lib/Markdown/{plugins → core/plugins}/cursor/index.js +4 -4
- package/lib/Markdown/index.d.ts +2 -1
- package/lib/Markdown/styles.js +32 -0
- package/lib/Markdown/types.d.ts +78 -0
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/package.json +7 -31
- package/components/AGUI/components/HelpModal/icons.tsx +0 -68
- package/components/AGUI/components/HelpModal/index.tsx +0 -1
- package/components/AGUI/components/HelpModal/modal.tsx +0 -101
- package/components/AGUI/components/chat/Button.tsx +0 -18
- package/components/AGUI/components/chat/Chat.tsx +0 -780
- package/components/AGUI/components/chat/ChatContext.tsx +0 -248
- package/components/AGUI/components/chat/CodeBlock.tsx +0 -406
- package/components/AGUI/components/chat/Header.tsx +0 -22
- package/components/AGUI/components/chat/Icons.tsx +0 -237
- package/components/AGUI/components/chat/ImageUploadQueue.tsx +0 -77
- package/components/AGUI/components/chat/Input.tsx +0 -24
- package/components/AGUI/components/chat/Markdown.tsx +0 -134
- package/components/AGUI/components/chat/Messages.tsx +0 -259
- package/components/AGUI/components/chat/Modal.tsx +0 -133
- package/components/AGUI/components/chat/Popup.tsx +0 -57
- package/components/AGUI/components/chat/PoweredByTag.tsx +0 -29
- package/components/AGUI/components/chat/Sidebar.tsx +0 -74
- package/components/AGUI/components/chat/Suggestion.tsx +0 -132
- package/components/AGUI/components/chat/Suggestions.tsx +0 -20
- package/components/AGUI/components/chat/Textarea.tsx +0 -61
- package/components/AGUI/components/chat/Window.tsx +0 -152
- package/components/AGUI/components/chat/index.tsx +0 -11
- package/components/AGUI/components/chat/messages/AssistantMessage.tsx +0 -69
- package/components/AGUI/components/chat/messages/RenderActionExecutionMessage.tsx +0 -129
- package/components/AGUI/components/chat/messages/RenderAgentStateMessage.tsx +0 -116
- package/components/AGUI/components/chat/messages/RenderImageMessage.tsx +0 -64
- package/components/AGUI/components/chat/messages/RenderResultMessage.tsx +0 -26
- package/components/AGUI/components/chat/messages/RenderTextMessage.tsx +0 -51
- package/components/AGUI/components/chat/messages/UserMessage.tsx +0 -10
- package/components/AGUI/components/chat/props.ts +0 -186
- package/components/AGUI/components/index.ts +0 -1
- package/components/AGUI/context/index.ts +0 -1
- package/components/AGUI/hooks/index.ts +0 -1
- package/components/AGUI/hooks/use-copilot-chat-suggestions.tsx +0 -122
- package/components/AGUI/hooks/use-copy-to-clipboard.tsx +0 -29
- package/components/AGUI/hooks/use-dark-mode.ts +0 -10
- package/components/AGUI/hooks/use-push-to-talk.tsx +0 -166
- package/components/AGUI/index.tsx +0 -4
- package/components/AGUI/lib/utils.test.ts +0 -7
- package/components/AGUI/lib/utils.ts +0 -27
- package/components/AGUI/styles.css +0 -0
- package/components/AGUI/types/css.ts +0 -0
- package/components/AGUI/types/index.ts +0 -1
- package/components/AGUI/types/suggestions.ts +0 -6
- package/components/Markdown/Markdown/AnimationNode.tsx +0 -89
- package/components/Markdown/Markdown/Markdown.tsx +0 -61
- package/components/Markdown/Markdown/core/Parser.ts +0 -52
- package/components/Markdown/Markdown/core/Renderer.ts +0 -121
- package/components/Markdown/Markdown/core/index.ts +0 -4
- package/components/Markdown/Markdown/hooks/index.ts +0 -4
- package/components/Markdown/Markdown/hooks/useAnimation.tsx +0 -27
- package/components/Markdown/Markdown/hooks/useStreaming.ts +0 -503
- package/components/Markdown/Markdown/index.tsx +0 -198
- package/components/Markdown/Markdown/interface.ts +0 -217
- package/components/Markdown/demo/typing.tsx +0 -82
- package/components/Markdown/index.ts +0 -1
- package/components/Markdown/plugins/latex/index.ts +0 -109
- package/components/Markdown/plugins/type.ts +0 -71
- package/lib/AGUI/components/HelpModal/icons.d.ts +0 -5
- package/lib/AGUI/components/HelpModal/icons.js +0 -84
- package/lib/AGUI/components/HelpModal/index.d.ts +0 -1
- package/lib/AGUI/components/HelpModal/index.js +0 -1
- package/lib/AGUI/components/HelpModal/modal.d.ts +0 -1
- package/lib/AGUI/components/HelpModal/modal.js +0 -104
- package/lib/AGUI/components/chat/Button.d.ts +0 -2
- package/lib/AGUI/components/chat/Button.js +0 -27
- package/lib/AGUI/components/chat/Chat.d.ts +0 -242
- package/lib/AGUI/components/chat/Chat.js +0 -634
- package/lib/AGUI/components/chat/ChatContext.d.ts +0 -142
- package/lib/AGUI/components/chat/ChatContext.js +0 -75
- package/lib/AGUI/components/chat/CodeBlock.d.ts +0 -12
- package/lib/AGUI/components/chat/CodeBlock.js +0 -398
- package/lib/AGUI/components/chat/Header.d.ts +0 -2
- package/lib/AGUI/components/chat/Header.js +0 -28
- package/lib/AGUI/components/chat/Icons.d.ts +0 -16
- package/lib/AGUI/components/chat/Icons.js +0 -247
- package/lib/AGUI/components/chat/ImageUploadQueue.d.ts +0 -11
- package/lib/AGUI/components/chat/ImageUploadQueue.js +0 -65
- package/lib/AGUI/components/chat/Input.d.ts +0 -2
- package/lib/AGUI/components/chat/Input.js +0 -30
- package/lib/AGUI/components/chat/Markdown.d.ts +0 -7
- package/lib/AGUI/components/chat/Markdown.js +0 -187
- package/lib/AGUI/components/chat/Messages.d.ts +0 -7
- package/lib/AGUI/components/chat/Messages.js +0 -242
- package/lib/AGUI/components/chat/Modal.d.ts +0 -43
- package/lib/AGUI/components/chat/Modal.js +0 -113
- package/lib/AGUI/components/chat/Popup.d.ts +0 -49
- package/lib/AGUI/components/chat/Popup.js +0 -64
- package/lib/AGUI/components/chat/PoweredByTag.d.ts +0 -3
- package/lib/AGUI/components/chat/PoweredByTag.js +0 -27
- package/lib/AGUI/components/chat/Sidebar.d.ts +0 -2
- package/lib/AGUI/components/chat/Sidebar.js +0 -85
- package/lib/AGUI/components/chat/Suggestion.d.ts +0 -16
- package/lib/AGUI/components/chat/Suggestion.js +0 -146
- package/lib/AGUI/components/chat/Suggestions.d.ts +0 -2
- package/lib/AGUI/components/chat/Suggestions.js +0 -21
- package/lib/AGUI/components/chat/Textarea.d.ts +0 -11
- package/lib/AGUI/components/chat/Textarea.js +0 -60
- package/lib/AGUI/components/chat/Window.d.ts +0 -2
- package/lib/AGUI/components/chat/Window.js +0 -115
- package/lib/AGUI/components/chat/index.d.ts +0 -11
- package/lib/AGUI/components/chat/index.js +0 -11
- package/lib/AGUI/components/chat/messages/AssistantMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/AssistantMessage.js +0 -56
- package/lib/AGUI/components/chat/messages/RenderActionExecutionMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/RenderActionExecutionMessage.js +0 -114
- package/lib/AGUI/components/chat/messages/RenderAgentStateMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/RenderAgentStateMessage.js +0 -97
- package/lib/AGUI/components/chat/messages/RenderImageMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/RenderImageMessage.js +0 -61
- package/lib/AGUI/components/chat/messages/RenderResultMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/RenderResultMessage.js +0 -27
- package/lib/AGUI/components/chat/messages/RenderTextMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/RenderTextMessage.js +0 -47
- package/lib/AGUI/components/chat/messages/UserMessage.d.ts +0 -2
- package/lib/AGUI/components/chat/messages/UserMessage.js +0 -9
- package/lib/AGUI/components/chat/props.d.ts +0 -157
- package/lib/AGUI/components/index.d.ts +0 -1
- package/lib/AGUI/components/index.js +0 -1
- package/lib/AGUI/context/index.d.ts +0 -1
- package/lib/AGUI/context/index.js +0 -1
- package/lib/AGUI/hooks/index.d.ts +0 -1
- package/lib/AGUI/hooks/index.js +0 -1
- package/lib/AGUI/hooks/use-copilot-chat-suggestions.d.ts +0 -87
- package/lib/AGUI/hooks/use-copilot-chat-suggestions.js +0 -95
- package/lib/AGUI/hooks/use-copy-to-clipboard.d.ts +0 -7
- package/lib/AGUI/hooks/use-copy-to-clipboard.js +0 -34
- package/lib/AGUI/hooks/use-dark-mode.d.ts +0 -1
- package/lib/AGUI/hooks/use-dark-mode.js +0 -4
- package/lib/AGUI/hooks/use-push-to-talk.d.ts +0 -16
- package/lib/AGUI/hooks/use-push-to-talk.js +0 -260
- package/lib/AGUI/index.d.ts +0 -4
- package/lib/AGUI/index.js +0 -4
- package/lib/AGUI/lib/utils.d.ts +0 -2
- package/lib/AGUI/lib/utils.js +0 -52
- package/lib/AGUI/styles.css +0 -0
- package/lib/AGUI/types/css.d.ts +0 -0
- package/lib/AGUI/types/css.js +0 -0
- package/lib/AGUI/types/index.d.ts +0 -1
- package/lib/AGUI/types/index.js +0 -1
- package/lib/AGUI/types/suggestions.d.ts +0 -6
- package/lib/AGUI/types/suggestions.js +0 -1
- package/lib/Markdown/Markdown/AnimationNode.d.ts +0 -20
- package/lib/Markdown/Markdown/AnimationNode.js +0 -84
- package/lib/Markdown/Markdown/Markdown.d.ts +0 -4
- package/lib/Markdown/Markdown/Markdown.js +0 -58
- package/lib/Markdown/Markdown/core/Parser.d.ts +0 -16
- package/lib/Markdown/Markdown/core/Parser.js +0 -65
- package/lib/Markdown/Markdown/core/Renderer.d.ts +0 -24
- package/lib/Markdown/Markdown/core/Renderer.js +0 -137
- package/lib/Markdown/Markdown/core/index.d.ts +0 -3
- package/lib/Markdown/Markdown/core/index.js +0 -3
- package/lib/Markdown/Markdown/hooks/index.d.ts +0 -3
- package/lib/Markdown/Markdown/hooks/index.js +0 -3
- package/lib/Markdown/Markdown/hooks/useAnimation.d.ts +0 -4
- package/lib/Markdown/Markdown/hooks/useCitationsData.d.ts +0 -7
- package/lib/Markdown/Markdown/hooks/useStreaming.d.ts +0 -3
- package/lib/Markdown/Markdown/hooks/useStreaming.js +0 -521
- package/lib/Markdown/Markdown/hooks/useTyping.d.ts +0 -4
- package/lib/Markdown/Markdown/index.d.ts +0 -84
- package/lib/Markdown/Markdown/index.js +0 -161
- package/lib/Markdown/Markdown/interface.d.ts +0 -203
- package/lib/Markdown/Markdown/interface.js +0 -1
- package/lib/Markdown/Markdown/style.js +0 -32
- package/lib/Markdown/plugins/latex/index.d.ts +0 -9
- package/lib/Markdown/plugins/latex/index.js +0 -97
- package/lib/Markdown/plugins/type.d.ts +0 -60
- package/lib/Markdown/plugins/type.js +0 -1
- /package/components/Markdown/{Markdown/defaultComponents/DisabledImage.tsx → core/components/DisableImage.tsx} +0 -0
- /package/components/Markdown/{Markdown/defaultComponents → core/components}/Media.tsx +0 -0
- /package/components/Markdown/{plugins → core/plugins}/cursor/Dot.tsx +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.d.ts +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.js +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents/DisabledImage.d.ts → core/components/DisableImage.d.ts} +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents/DisabledImage.js → core/components/DisableImage.js} +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents → core/components}/Media.d.ts +0 -0
- /package/lib/Markdown/{Markdown/defaultComponents → core/components}/Media.js +0 -0
- /package/lib/Markdown/{plugins → core/plugins}/citations/CitationComponent.d.ts +0 -0
- /package/lib/Markdown/{plugins → core/plugins}/cursor/Dot.d.ts +0 -0
- /package/lib/Markdown/{plugins → core/plugins}/cursor/Underline.d.ts +0 -0
- /package/lib/Markdown/{plugins → core/plugins}/cursor/index.d.ts +0 -0
- /package/lib/Markdown/{Markdown/style.d.ts → styles.d.ts} +0 -0
- /package/lib/{AGUI/components/chat/props.js → Markdown/types.js} +0 -0
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
var _excluded = ["className", "allowHtml", "content", "typing", "cursor", "enableWordCaching", "enableMathCaching", "enableAnimation"];
|
|
3
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
13
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
|
-
import Markdown from "./Markdown";
|
|
17
|
-
import CodeBlock from "./defaultComponents/CodeBlock";
|
|
18
|
-
import Media from "./defaultComponents/Media";
|
|
19
|
-
import DisabledImage from "./defaultComponents/DisabledImage";
|
|
20
|
-
import { useProviderContext } from "../..";
|
|
21
|
-
import { useTyping } from "./hooks/useTyping";
|
|
22
|
-
import { cursorExtension, CursorComponent } from "../plugins/cursor";
|
|
23
|
-
import { citationsExtension } from "../plugins/citations";
|
|
24
|
-
import latex from "../plugins/latex";
|
|
25
|
-
import useCitationsData from "./hooks/useCitationsData";
|
|
26
|
-
import classnames from 'classnames';
|
|
27
|
-
import { ErrorBoundary } from "react-error-boundary";
|
|
28
|
-
import { memo, useMemo } from 'react';
|
|
29
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
30
|
-
var Null = function Null() {
|
|
31
|
-
return null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// 缓存不变的 dompurify 配置
|
|
35
|
-
var EMPTY_DOMPURIFY_CONFIG = {
|
|
36
|
-
ALLOWED_TAGS: []
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 检测浏览器是否支持正则表达式的 lookbehind assertions
|
|
41
|
-
* iOS Safari < 16.4 不支持此特性
|
|
42
|
-
*/
|
|
43
|
-
function supportsLookbehindAssertions() {
|
|
44
|
-
try {
|
|
45
|
-
// 尝试创建包含正向后行断言的正则表达式
|
|
46
|
-
new RegExp('(?<=a)b');
|
|
47
|
-
return true;
|
|
48
|
-
} catch (e) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
var isSupportsLookbehindAssertions = supportsLookbehindAssertions();
|
|
53
|
-
console.log({
|
|
54
|
-
isSupportsLookbehindAssertions: isSupportsLookbehindAssertions
|
|
55
|
-
});
|
|
56
|
-
export default /*#__PURE__*/memo(function (props) {
|
|
57
|
-
var baseFontSize = props.baseFontSize || 14;
|
|
58
|
-
var baseLineHeight = props.baseLineHeight || 1.7;
|
|
59
|
-
var _useProviderContext = useProviderContext(),
|
|
60
|
-
getPrefixCls = _useProviderContext.getPrefixCls;
|
|
61
|
-
var prefixCls = getPrefixCls('markdown');
|
|
62
|
-
var className = props.className,
|
|
63
|
-
_props$allowHtml = props.allowHtml,
|
|
64
|
-
allowHtml = _props$allowHtml === void 0 ? true : _props$allowHtml,
|
|
65
|
-
_props$content = props.content,
|
|
66
|
-
_content = _props$content === void 0 ? '' : _props$content,
|
|
67
|
-
_props$typing = props.typing,
|
|
68
|
-
typing = _props$typing === void 0 ? false : _props$typing,
|
|
69
|
-
_props$cursor = props.cursor,
|
|
70
|
-
cursor = _props$cursor === void 0 ? false : _props$cursor,
|
|
71
|
-
_props$enableWordCach = props.enableWordCaching,
|
|
72
|
-
enableWordCaching = _props$enableWordCach === void 0 ? false : _props$enableWordCach,
|
|
73
|
-
_props$enableMathCach = props.enableMathCaching,
|
|
74
|
-
enableMathCaching = _props$enableMathCach === void 0 ? true : _props$enableMathCach,
|
|
75
|
-
_props$enableAnimatio = props.enableAnimation,
|
|
76
|
-
enableAnimation = _props$enableAnimatio === void 0 ? false : _props$enableAnimatio,
|
|
77
|
-
restProps = _objectWithoutProperties(props, _excluded);
|
|
78
|
-
var content = useTyping({
|
|
79
|
-
content: _content,
|
|
80
|
-
typing: typing
|
|
81
|
-
});
|
|
82
|
-
var _useCitationsData = useCitationsData({
|
|
83
|
-
citations: props.citations,
|
|
84
|
-
citationsMap: props.citationsMap
|
|
85
|
-
}),
|
|
86
|
-
citationsData = _useCitationsData.citationsData,
|
|
87
|
-
citationsDataCount = _useCitationsData.citationsDataCount,
|
|
88
|
-
CitationComponent = _useCitationsData.CitationComponent;
|
|
89
|
-
if (props.raw || !isSupportsLookbehindAssertions) return /*#__PURE__*/_jsx("div", {
|
|
90
|
-
className: prefixCls,
|
|
91
|
-
style: {
|
|
92
|
-
fontSize: baseFontSize,
|
|
93
|
-
lineHeight: baseLineHeight
|
|
94
|
-
},
|
|
95
|
-
children: content
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// 使用 useMemo 缓存 extensions 配置
|
|
99
|
-
var extensions = useMemo(function () {
|
|
100
|
-
var exts = [cursorExtension()].concat(_toConsumableArray(latex()));
|
|
101
|
-
if (citationsDataCount > 0) exts.push(citationsExtension(citationsData));
|
|
102
|
-
return exts;
|
|
103
|
-
}, [citationsDataCount, citationsData]);
|
|
104
|
-
|
|
105
|
-
// 使用 useMemo 缓存 config 对象
|
|
106
|
-
var config = useMemo(function () {
|
|
107
|
-
return {
|
|
108
|
-
extensions: extensions
|
|
109
|
-
};
|
|
110
|
-
}, [extensions]);
|
|
111
|
-
|
|
112
|
-
// 使用 useMemo 缓存 streaming 配置
|
|
113
|
-
var streaming = useMemo(function () {
|
|
114
|
-
return {
|
|
115
|
-
hasNextChunk: Boolean(typing),
|
|
116
|
-
enableWordCaching: enableWordCaching,
|
|
117
|
-
enableMathCaching: enableMathCaching,
|
|
118
|
-
enableAnimation: enableAnimation
|
|
119
|
-
};
|
|
120
|
-
}, [typing, enableWordCaching, enableMathCaching, enableAnimation]);
|
|
121
|
-
|
|
122
|
-
// 使用 useMemo 缓存 components 对象
|
|
123
|
-
var components = useMemo(function () {
|
|
124
|
-
return {
|
|
125
|
-
// @ts-ignore
|
|
126
|
-
pre: CodeBlock,
|
|
127
|
-
style: Null,
|
|
128
|
-
script: Null,
|
|
129
|
-
img: props.disableImage ? DisabledImage : Media,
|
|
130
|
-
cursor: CursorComponent,
|
|
131
|
-
// @ts-ignore
|
|
132
|
-
citation: CitationComponent
|
|
133
|
-
};
|
|
134
|
-
}, [props.disableImage, CitationComponent]);
|
|
135
|
-
|
|
136
|
-
// 使用 useMemo 缓存 dompurifyConfig
|
|
137
|
-
var dompurifyConfig = useMemo(function () {
|
|
138
|
-
return allowHtml ? undefined : EMPTY_DOMPURIFY_CONFIG;
|
|
139
|
-
}, [allowHtml]);
|
|
140
|
-
return /*#__PURE__*/_jsx(ErrorBoundary, {
|
|
141
|
-
fallback: /*#__PURE__*/_jsx("div", {
|
|
142
|
-
className: prefixCls,
|
|
143
|
-
style: {
|
|
144
|
-
fontSize: baseFontSize,
|
|
145
|
-
lineHeight: baseLineHeight
|
|
146
|
-
},
|
|
147
|
-
children: content
|
|
148
|
-
}),
|
|
149
|
-
children: /*#__PURE__*/_jsx(Markdown, _objectSpread({
|
|
150
|
-
baseFontSize: baseFontSize,
|
|
151
|
-
baseLineHeight: baseLineHeight,
|
|
152
|
-
dompurifyConfig: dompurifyConfig,
|
|
153
|
-
streaming: streaming,
|
|
154
|
-
cursor: cursor,
|
|
155
|
-
className: classnames(prefixCls, className),
|
|
156
|
-
components: components,
|
|
157
|
-
content: content,
|
|
158
|
-
config: config
|
|
159
|
-
}, restProps))
|
|
160
|
-
});
|
|
161
|
-
});
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import type { Config as DOMPurifyConfig } from 'dompurify';
|
|
2
|
-
import type { DOMNode } from 'html-react-parser';
|
|
3
|
-
import type { MarkedExtension, Tokens } from 'marked';
|
|
4
|
-
import type { CSSProperties, JSX } from 'react';
|
|
5
|
-
export interface AnimationConfig {
|
|
6
|
-
/**
|
|
7
|
-
* @description 淡入动画的持续时间(毫秒)
|
|
8
|
-
* @description The duration of the fade-in animation in milliseconds
|
|
9
|
-
* @default 200
|
|
10
|
-
*/
|
|
11
|
-
fadeDuration?: number;
|
|
12
|
-
/**
|
|
13
|
-
* @description 动画的缓动函数
|
|
14
|
-
* @description Easing function for the animation
|
|
15
|
-
* @default 'ease-in-out'
|
|
16
|
-
*/
|
|
17
|
-
easing?: string;
|
|
18
|
-
}
|
|
19
|
-
type Token = Tokens.Generic;
|
|
20
|
-
interface SteamingOption {
|
|
21
|
-
/**
|
|
22
|
-
* @description 指示是否还有后续内容块,为 false 时刷新所有缓存并完成渲染
|
|
23
|
-
* @description Indicates whether more content chunks are expected. When false, flushes all cached content and completes rendering
|
|
24
|
-
* @default false
|
|
25
|
-
*/
|
|
26
|
-
hasNextChunk?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* @description 为块级元素(p、li、h1、h2、h3、h4)启用文字淡入动画
|
|
29
|
-
* @description Enables text fade-in animation for block elements (p, li, h1, h2, h3, h4)
|
|
30
|
-
* @default false
|
|
31
|
-
*/
|
|
32
|
-
enableAnimation?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* @description 文字出现动画效果的配置
|
|
35
|
-
* @description Configuration for text appearance animation effects
|
|
36
|
-
*/
|
|
37
|
-
animationConfig?: AnimationConfig;
|
|
38
|
-
/**
|
|
39
|
-
* @description 启用英文单词缓存,单词会在遇到空格或标点后才整体显示
|
|
40
|
-
* @description Enable English word caching, words will be displayed as a whole after encountering spaces or punctuation
|
|
41
|
-
* @default false
|
|
42
|
-
*/
|
|
43
|
-
enableWordCaching?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* @description 启用 LaTeX 公式缓存,公式会在完整后才整体显示($...$、$$...$$、\(...\)、\[...\])
|
|
46
|
-
* @description Enable LaTeX formula caching, formulas will be displayed as a whole when complete ($...$, $$...$$, \(...\), \[...\])
|
|
47
|
-
* @default true
|
|
48
|
-
*/
|
|
49
|
-
enableMathCaching?: boolean;
|
|
50
|
-
}
|
|
51
|
-
type StreamStatus = 'loading' | 'done';
|
|
52
|
-
type ComponentProps<T extends Record<string, unknown> = Record<string, unknown>> = React.HTMLAttributes<HTMLElement> & {
|
|
53
|
-
/**
|
|
54
|
-
* @description 组件对应的 DOM 节点,包含解析后的 DOM 节点信息
|
|
55
|
-
* @description Component Element from html-react-parser, contains the parsed DOM node information
|
|
56
|
-
*/
|
|
57
|
-
domNode: DOMNode;
|
|
58
|
-
/**
|
|
59
|
-
* @description 流式状态,`loading` 表示正在加载,`done` 表示加载完成
|
|
60
|
-
* @description Streaming status, `loading` indicates streaming in progress, `done` indicates streaming complete
|
|
61
|
-
*/
|
|
62
|
-
streamStatus: StreamStatus;
|
|
63
|
-
} & T;
|
|
64
|
-
interface MarkdownProps {
|
|
65
|
-
citations?: {
|
|
66
|
-
/**
|
|
67
|
-
* @description 引用的标题
|
|
68
|
-
* @descriptionEn Title of the citation
|
|
69
|
-
*/
|
|
70
|
-
title?: string;
|
|
71
|
-
/**
|
|
72
|
-
* @description 引用的URL地址
|
|
73
|
-
* @descriptionEn URL address of the citation
|
|
74
|
-
*/
|
|
75
|
-
url?: string;
|
|
76
|
-
/**
|
|
77
|
-
* @description 引用的内容
|
|
78
|
-
* @descriptionEn Content of the citation
|
|
79
|
-
*/
|
|
80
|
-
content?: string;
|
|
81
|
-
/**
|
|
82
|
-
* @description 引用的渲染函数
|
|
83
|
-
* @descriptionEn Rendering function of the citation
|
|
84
|
-
*/
|
|
85
|
-
render?: (props: {
|
|
86
|
-
text: string;
|
|
87
|
-
url: string;
|
|
88
|
-
title: string;
|
|
89
|
-
content: string;
|
|
90
|
-
}) => React.ReactNode;
|
|
91
|
-
}[];
|
|
92
|
-
/**
|
|
93
|
-
* @description 引用映射对象,用于快速查找引用信息
|
|
94
|
-
* @descriptionEn Citation mapping object for quick lookup of reference information
|
|
95
|
-
*/
|
|
96
|
-
citationsMap?: Record<string, {
|
|
97
|
-
/**
|
|
98
|
-
* @description 引用的标题
|
|
99
|
-
* @descriptionEn Title of the citation
|
|
100
|
-
*/
|
|
101
|
-
title?: string;
|
|
102
|
-
/**
|
|
103
|
-
* @description 引用的URL地址
|
|
104
|
-
* @descriptionEn URL address of the citation
|
|
105
|
-
*/
|
|
106
|
-
url?: string;
|
|
107
|
-
/**
|
|
108
|
-
* @description 引用的内容
|
|
109
|
-
* @descriptionEn Content of the citation
|
|
110
|
-
*/
|
|
111
|
-
content?: string;
|
|
112
|
-
/**
|
|
113
|
-
* @description 引用的渲染函数
|
|
114
|
-
* @descriptionEn Rendering function of the citation
|
|
115
|
-
*/
|
|
116
|
-
render?: (props: {
|
|
117
|
-
text: string;
|
|
118
|
-
url: string;
|
|
119
|
-
title: string;
|
|
120
|
-
content: string;
|
|
121
|
-
}) => React.ReactNode;
|
|
122
|
-
}>;
|
|
123
|
-
/**
|
|
124
|
-
* @description 光标样式类型,支持点状、下划线或布尔值控制
|
|
125
|
-
* @description Cursor style type, supports dot, underline, or boolean control
|
|
126
|
-
*/
|
|
127
|
-
cursor?: boolean | 'dot' | 'underline';
|
|
128
|
-
/**
|
|
129
|
-
* @description 基础字体大小,影响整个Markdown内容的字体大小
|
|
130
|
-
* @description Base font size that affects the font size of the entire Markdown content
|
|
131
|
-
*/
|
|
132
|
-
baseFontSize?: number;
|
|
133
|
-
/**
|
|
134
|
-
* @description 基础行高,影响文本的行间距
|
|
135
|
-
* @description Base line height that affects text line spacing
|
|
136
|
-
*/
|
|
137
|
-
baseLineHeight?: number;
|
|
138
|
-
/**
|
|
139
|
-
* @description 需要渲染的 Markdown 内容
|
|
140
|
-
* @description Markdown content to be rendered
|
|
141
|
-
*/
|
|
142
|
-
content?: string;
|
|
143
|
-
/**
|
|
144
|
-
* @description Markdown 内容,作为 `content` 属性的别名
|
|
145
|
-
* @description Markdown content, alias for `content` property
|
|
146
|
-
*/
|
|
147
|
-
children?: string;
|
|
148
|
-
/**
|
|
149
|
-
* @description 用于替换 HTML 元素的自定义 React 组件映射,组件会接收 domNode、streamStatus 等属性
|
|
150
|
-
* @description Custom React components to replace HTML elements, components receive domNode, streamStatus, etc.
|
|
151
|
-
*/
|
|
152
|
-
components?: {
|
|
153
|
-
[tagName: string]: React.ComponentType<ComponentProps> | keyof JSX.IntrinsicElements;
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* @description 流式渲染行为的配置
|
|
157
|
-
* @description Configuration for streaming rendering behavior
|
|
158
|
-
*/
|
|
159
|
-
streaming?: SteamingOption;
|
|
160
|
-
/**
|
|
161
|
-
* @description Markdown 解析和扩展的 Marked.js 配置
|
|
162
|
-
* @description Marked.js configuration for Markdown parsing and extensions
|
|
163
|
-
*/
|
|
164
|
-
config?: MarkedExtension;
|
|
165
|
-
/**
|
|
166
|
-
* @description 根元素的额外 CSS 类名
|
|
167
|
-
* @description Additional CSS class name for the root container
|
|
168
|
-
*/
|
|
169
|
-
rootClassName?: string;
|
|
170
|
-
/**
|
|
171
|
-
* @description 根容器的额外 CSS 类名
|
|
172
|
-
* @description Additional CSS class name for the root container
|
|
173
|
-
*/
|
|
174
|
-
className?: string;
|
|
175
|
-
/**
|
|
176
|
-
* @description 段落元素的自定义 HTML 标签,防止自定义组件包含块级元素时的验证错误
|
|
177
|
-
* @description Custom HTML tag for paragraph elements, prevents validation errors when custom components contain block-level elements
|
|
178
|
-
* @default 'p'
|
|
179
|
-
*/
|
|
180
|
-
paragraphTag?: keyof JSX.IntrinsicElements;
|
|
181
|
-
/**
|
|
182
|
-
* @description 根容器的内联样式
|
|
183
|
-
* @description Inline styles for the root container
|
|
184
|
-
*/
|
|
185
|
-
style?: CSSProperties;
|
|
186
|
-
/**
|
|
187
|
-
* @description 组件的 CSS 类名前缀
|
|
188
|
-
* @description CSS class name prefix for the component
|
|
189
|
-
*/
|
|
190
|
-
prefixCls?: string;
|
|
191
|
-
/**
|
|
192
|
-
* @description 是否为所有锚点标签添加 `target="_blank"`
|
|
193
|
-
* @description Whether to add `target="_blank"` to all anchor tags
|
|
194
|
-
* @default false
|
|
195
|
-
*/
|
|
196
|
-
openLinksInNewTab?: boolean;
|
|
197
|
-
/**
|
|
198
|
-
* @description HTML 净化和 XSS 防护的 DOMPurify 配置
|
|
199
|
-
* @description DOMPurify configuration for HTML sanitization and XSS protection
|
|
200
|
-
*/
|
|
201
|
-
dompurifyConfig?: DOMPurifyConfig;
|
|
202
|
-
}
|
|
203
|
-
export type { ComponentProps, MarkdownProps, StreamStatus, Token, Tokens };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
var _templateObject;
|
|
2
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
|
-
import { createGlobalStyle } from 'antd-style';
|
|
4
|
-
export default createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n.", "-markdown {\n color: inherit;\n max-width: 100%;\n\n ol, ul {\n padding-left: 30px;\n }\n\n blockquote {\n padding-inline: 0.6em 0;\n padding-block: 0;\n margin: 1em 0;\n border-inline-start: 4px solid ", ";\n opacity: 0.85;\n }\n\n figure {\n margin: 0;\n }\n\n code {\n font-size: 0.8571428571428571em;\n border: 0;\n margin: 0;\n background-color: ", ";\n color: ", ";\n border-radius: ", "px;\n padding: 2px 6px;\n margin-inline: 3px;\n border: 1px solid ", ";\n }\n\n pre code {\n font-size: 0.8571428571428571em;\n }\n\n h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n margin-top: 0.5714285714285714em;\n margin-bottom: 0.5714285714285714em;\n font-weight: 500;\n line-height: 1.7777;\n color: inherit;\n }\n\n p {\n margin-top: 0.5714285714285714em;\n margin-bottom: 0.5714285714285714em;\n }\n\n h1 {\n font-size: 1.2857142857142858em;\n }\n\n h2 {\n font-size: 1.1428571428571428em;\n }\n\n h3 {\n font-size: 1em;\n }\n\n h4 {\n font-size: 1em;\n }\n\n h5 {\n font-size: 1em;\n }\n\n h6 {\n font-size: 1em;\n }\n\n hr {\n border-color: ", ";\n border-style: solid;\n border-width: 1px 0 0 0;\n margin: 1em 0;\n }\n\n table {\n border-collapse: collapse;\n display: block;\n width: max-content;\n max-width: 100%;\n overflow: auto;\n }\n\n table th {\n background: ", ";\n text-align: left;\n }\n\n table td,\n table th {\n padding: 0.75em 1.5em;\n border: 1px solid ", ";\n white-space: pre;\n }\n\n .", "-image {\n max-width: 480px;\n overflow: hidden;\n }\n\n .", "-markdown-video {\n position: relative;\n \n &-poster {\n display: flex;\n align-items: center;\n justify-content: center;\n max-width: 480px;\n background-color: #000;\n border-radius: 8px;\n padding: 100px 0;\n cursor: pointer;\n }\n\n &-play {\n color: #ccc;\n font-size: 30px;\n }\n }\n \n}\n\n.", "-markdown > *:last-child {\n margin-bottom: 0 !important;\n}\n\n.", "-markdown > *:first-child {\n margin-top: 0 !important;\n}\n\n@keyframes ", "-markdown-fadeIn {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}\n"])), function (p) {
|
|
5
|
-
return p.theme.prefixCls;
|
|
6
|
-
}, function (p) {
|
|
7
|
-
return p.theme.colorBorder;
|
|
8
|
-
}, function (p) {
|
|
9
|
-
return p.theme.colorFillQuaternary;
|
|
10
|
-
}, function (p) {
|
|
11
|
-
return p.theme.colorText;
|
|
12
|
-
}, function (p) {
|
|
13
|
-
return p.theme.borderRadiusSM;
|
|
14
|
-
}, function (p) {
|
|
15
|
-
return p.theme.colorBorderSecondary;
|
|
16
|
-
}, function (p) {
|
|
17
|
-
return p.theme.colorBorderSecondary;
|
|
18
|
-
}, function (p) {
|
|
19
|
-
return p.theme.colorFillQuaternary;
|
|
20
|
-
}, function (p) {
|
|
21
|
-
return p.theme.colorBorderSecondary;
|
|
22
|
-
}, function (p) {
|
|
23
|
-
return p.theme.prefixCls;
|
|
24
|
-
}, function (p) {
|
|
25
|
-
return p.theme.prefixCls;
|
|
26
|
-
}, function (p) {
|
|
27
|
-
return p.theme.prefixCls;
|
|
28
|
-
}, function (p) {
|
|
29
|
-
return p.theme.prefixCls;
|
|
30
|
-
}, function (p) {
|
|
31
|
-
return p.theme.prefixCls;
|
|
32
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type KatexOptions } from 'katex';
|
|
2
|
-
import { TokenizerAndRendererExtension } from 'marked';
|
|
3
|
-
import 'katex/dist/katex.min.css';
|
|
4
|
-
type LatexOption = {
|
|
5
|
-
katexOptions?: KatexOptions;
|
|
6
|
-
replaceAlignStart?: boolean;
|
|
7
|
-
};
|
|
8
|
-
declare const Latex: (options?: LatexOption) => TokenizerAndRendererExtension[];
|
|
9
|
-
export default Latex;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
-
import katex from 'katex';
|
|
14
|
-
import 'katex/dist/katex.min.css';
|
|
15
|
-
var inlineRuleNonStandard = /^(?:\${1,2}([^$]{1,10000}?)\${1,2}|\\\(([\s\S]{1,10000}?)\\\)|\\\[((?:\\.|[^\\]){1,10000}?)\\\])/;
|
|
16
|
-
var blockRule = /^(\${1,2})\n([\s\S]{1,10000}?)\n\1(?:\n|$)|^\\\[((?:\\.|[^\\]){1,10000}?)\\\]/;
|
|
17
|
-
// fix katex not support align*: https://github.com/KaTeX/KaTeX/issues/1007
|
|
18
|
-
function replaceAlign(text) {
|
|
19
|
-
return text ? text.replace(/\{align\*\}/g, '{aligned}') : text;
|
|
20
|
-
}
|
|
21
|
-
function createRenderer(options, newlineAfter) {
|
|
22
|
-
return function (token) {
|
|
23
|
-
return katex.renderToString(token.text, _objectSpread(_objectSpread({}, options), {}, {
|
|
24
|
-
displayMode: token.displayMode
|
|
25
|
-
})) + (newlineAfter ? '\n' : '');
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function inlineKatex(renderer, replaceAlignStart) {
|
|
29
|
-
var ruleReg = inlineRuleNonStandard;
|
|
30
|
-
return {
|
|
31
|
-
name: 'inlineKatex',
|
|
32
|
-
level: 'inline',
|
|
33
|
-
start: function start(src) {
|
|
34
|
-
if (!src.includes('$') && !src.includes('\\(')) return;
|
|
35
|
-
var indices = [src.indexOf('$'), src.indexOf('\\(')].filter(function (idx) {
|
|
36
|
-
return idx !== -1;
|
|
37
|
-
});
|
|
38
|
-
if (indices.length === 0) return;
|
|
39
|
-
var katexIndex = Math.min.apply(Math, _toConsumableArray(indices));
|
|
40
|
-
var possibleKatex = src.slice(katexIndex);
|
|
41
|
-
if (possibleKatex.match(ruleReg)) {
|
|
42
|
-
return katexIndex;
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
tokenizer: function tokenizer(src) {
|
|
46
|
-
var match = src.match(inlineRuleNonStandard);
|
|
47
|
-
if (match) {
|
|
48
|
-
var text = (match[1] || match[2]).trim();
|
|
49
|
-
if (replaceAlignStart) {
|
|
50
|
-
text = replaceAlign(text);
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
type: 'inlineKatex',
|
|
54
|
-
raw: match[0],
|
|
55
|
-
text: text,
|
|
56
|
-
displayMode: false
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
renderer: renderer
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function blockKatex(renderer, replaceAlignStart) {
|
|
64
|
-
return {
|
|
65
|
-
name: 'blockKatex',
|
|
66
|
-
level: 'block',
|
|
67
|
-
tokenizer: function tokenizer(src) {
|
|
68
|
-
var match = src.match(blockRule);
|
|
69
|
-
if (match) {
|
|
70
|
-
var text = replaceAlign(match[2] || match[3].trim());
|
|
71
|
-
if (replaceAlignStart) {
|
|
72
|
-
text = replaceAlign(text);
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
type: 'blockKatex',
|
|
76
|
-
raw: match[0],
|
|
77
|
-
text: text,
|
|
78
|
-
displayMode: true
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
renderer: renderer
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
var Latex = function Latex(options) {
|
|
86
|
-
var _ref = options || {},
|
|
87
|
-
_ref$replaceAlignStar = _ref.replaceAlignStart,
|
|
88
|
-
replaceAlignStart = _ref$replaceAlignStar === void 0 ? true : _ref$replaceAlignStar,
|
|
89
|
-
_ref$katexOptions = _ref.katexOptions,
|
|
90
|
-
katexOptions = _ref$katexOptions === void 0 ? {
|
|
91
|
-
output: 'html'
|
|
92
|
-
} : _ref$katexOptions;
|
|
93
|
-
var inlineRenderer = createRenderer(katexOptions, false);
|
|
94
|
-
var blockRenderer = createRenderer(katexOptions, true);
|
|
95
|
-
return [inlineKatex(inlineRenderer, replaceAlignStart), blockKatex(blockRenderer, replaceAlignStart)];
|
|
96
|
-
};
|
|
97
|
-
export default Latex;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { KatexOptions } from 'katex';
|
|
2
|
-
import type { TokenizerAndRendererExtension } from 'marked';
|
|
3
|
-
import type { ReactNode } from 'react';
|
|
4
|
-
import type { SyntaxHighlighterProps } from 'react-syntax-highlighter';
|
|
5
|
-
export type LatexOption = {
|
|
6
|
-
katexOptions?: KatexOptions;
|
|
7
|
-
replaceAlignStart?: boolean;
|
|
8
|
-
};
|
|
9
|
-
type HighlightCodeType = 'root' | 'header' | 'headerTitle' | 'code';
|
|
10
|
-
export type HighlightCodeProps = {
|
|
11
|
-
lang?: string;
|
|
12
|
-
children: string;
|
|
13
|
-
header?: ReactNode | null;
|
|
14
|
-
prefixCls?: string;
|
|
15
|
-
style?: React.CSSProperties;
|
|
16
|
-
className?: string;
|
|
17
|
-
highlightProps?: Partial<SyntaxHighlighterProps>;
|
|
18
|
-
classNames?: Partial<Record<HighlightCodeType, string>>;
|
|
19
|
-
styles?: Partial<Record<HighlightCodeType, React.CSSProperties>>;
|
|
20
|
-
};
|
|
21
|
-
type MermaidType = 'root' | 'header' | 'graph' | 'code';
|
|
22
|
-
export type MermaidProps = {
|
|
23
|
-
children: string;
|
|
24
|
-
header?: ReactNode | null;
|
|
25
|
-
prefixCls?: string;
|
|
26
|
-
style?: React.CSSProperties;
|
|
27
|
-
className?: string;
|
|
28
|
-
highlightProps?: Partial<SyntaxHighlighterProps>;
|
|
29
|
-
classNames?: Partial<Record<MermaidType, string>>;
|
|
30
|
-
styles?: Partial<Record<MermaidType, React.CSSProperties>>;
|
|
31
|
-
};
|
|
32
|
-
interface BaseComponentConfig {
|
|
33
|
-
style: React.CSSProperties;
|
|
34
|
-
styles: Record<string, React.CSSProperties>;
|
|
35
|
-
className: string;
|
|
36
|
-
classNames: Record<string, string>;
|
|
37
|
-
}
|
|
38
|
-
type ComponentConfig<CompProps extends Record<PropertyKey, any>, PickType extends keyof CompProps = keyof BaseComponentConfig> = Pick<CompProps, PickType>;
|
|
39
|
-
export interface MarkdownComponentsConfig {
|
|
40
|
-
highlightCode?: ComponentConfig<HighlightCodeProps>;
|
|
41
|
-
mermaid?: ComponentConfig<MermaidProps>;
|
|
42
|
-
}
|
|
43
|
-
export type PluginsType = {
|
|
44
|
-
/**
|
|
45
|
-
* @desc 渲染数学公式Latex语法。
|
|
46
|
-
* @descEN Rendering mathematical formulas using Latex syntax.
|
|
47
|
-
*/
|
|
48
|
-
Latex: (options?: LatexOption) => TokenizerAndRendererExtension[];
|
|
49
|
-
/**
|
|
50
|
-
* @desc 渲染代码高亮。
|
|
51
|
-
* @descEN Highlight the rendering code.
|
|
52
|
-
*/
|
|
53
|
-
HighlightCode: (props: HighlightCodeProps) => React.ReactNode;
|
|
54
|
-
/**
|
|
55
|
-
* @desc 渲染 Mermaid 图表。
|
|
56
|
-
* @descEN Rendering the Mermaid Chart.
|
|
57
|
-
*/
|
|
58
|
-
Mermaid: (props: MermaidProps) => React.ReactNode;
|
|
59
|
-
};
|
|
60
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|