@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.
Files changed (233) hide show
  1. package/bin/starter_webui.zip +0 -0
  2. package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Builder.tsx +8 -4
  3. package/components/ImageGenerator/index.tsx +1 -1
  4. package/components/Markdown/Markdown.tsx +105 -0
  5. package/components/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.tsx +1 -1
  6. package/components/Markdown/core/components/Null.tsx +1 -0
  7. package/components/Markdown/core/components/Raw.tsx +18 -0
  8. package/components/Markdown/{Markdown → core}/hooks/useCitationsData.tsx +3 -7
  9. package/components/Markdown/core/hooks/useCursorContent.tsx +15 -0
  10. package/components/Markdown/{Markdown/hooks/useTyping.ts → core/hooks/useTyping.tsx} +4 -1
  11. package/components/Markdown/core/index.tsx +18 -0
  12. package/components/Markdown/{plugins → core/plugins}/citations/CitationComponent.tsx +5 -3
  13. package/components/Markdown/{plugins → core/plugins}/citations/index.tsx +3 -4
  14. package/components/Markdown/{plugins → core/plugins}/cursor/Underline.tsx +1 -1
  15. package/components/Markdown/{plugins → core/plugins}/cursor/index.tsx +8 -8
  16. package/components/Markdown/demo/cursor.tsx +2 -3
  17. package/components/Markdown/index.en-US.md +1 -2
  18. package/components/Markdown/index.tsx +6 -0
  19. package/components/Markdown/index.zh-CN.md +1 -2
  20. package/components/Markdown/{Markdown/style.ts → styles.ts} +12 -21
  21. package/components/Markdown/types.tsx +94 -0
  22. package/components/index.ts +1 -3
  23. package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Builder.js +5 -3
  24. package/lib/ImageGenerator/index.js +1 -1
  25. package/lib/Markdown/Markdown.d.ts +4 -0
  26. package/lib/Markdown/Markdown.js +110 -0
  27. package/lib/Markdown/core/components/Null.d.ts +2 -0
  28. package/lib/Markdown/core/components/Null.js +3 -0
  29. package/lib/Markdown/core/components/Raw.d.ts +8 -0
  30. package/lib/Markdown/core/components/Raw.js +13 -0
  31. package/lib/Markdown/core/hooks/useCitationsData.d.ts +6 -0
  32. package/lib/Markdown/{Markdown → core}/hooks/useCitationsData.js +1 -1
  33. package/lib/Markdown/core/hooks/useCursorContent.d.ts +4 -0
  34. package/lib/Markdown/core/hooks/useCursorContent.js +14 -0
  35. package/lib/Markdown/core/hooks/useTyping.d.ts +5 -0
  36. package/lib/Markdown/{Markdown → core}/hooks/useTyping.js +3 -2
  37. package/lib/Markdown/core/index.d.ts +2 -0
  38. package/lib/Markdown/{Markdown/hooks/useAnimation.js → core/index.js} +23 -23
  39. package/lib/Markdown/{plugins → core/plugins}/citations/CitationComponent.js +5 -5
  40. package/lib/Markdown/{plugins → core/plugins}/citations/index.d.ts +1 -2
  41. package/lib/Markdown/{plugins → core/plugins}/citations/index.js +1 -1
  42. package/lib/Markdown/{plugins → core/plugins}/cursor/Dot.js +1 -1
  43. package/lib/Markdown/{plugins → core/plugins}/cursor/Underline.js +1 -1
  44. package/lib/Markdown/{plugins → core/plugins}/cursor/index.js +4 -4
  45. package/lib/Markdown/index.d.ts +2 -1
  46. package/lib/Markdown/styles.js +32 -0
  47. package/lib/Markdown/types.d.ts +78 -0
  48. package/lib/index.d.ts +0 -2
  49. package/lib/index.js +0 -2
  50. package/package.json +7 -31
  51. package/components/AGUI/components/HelpModal/icons.tsx +0 -68
  52. package/components/AGUI/components/HelpModal/index.tsx +0 -1
  53. package/components/AGUI/components/HelpModal/modal.tsx +0 -101
  54. package/components/AGUI/components/chat/Button.tsx +0 -18
  55. package/components/AGUI/components/chat/Chat.tsx +0 -780
  56. package/components/AGUI/components/chat/ChatContext.tsx +0 -248
  57. package/components/AGUI/components/chat/CodeBlock.tsx +0 -406
  58. package/components/AGUI/components/chat/Header.tsx +0 -22
  59. package/components/AGUI/components/chat/Icons.tsx +0 -237
  60. package/components/AGUI/components/chat/ImageUploadQueue.tsx +0 -77
  61. package/components/AGUI/components/chat/Input.tsx +0 -24
  62. package/components/AGUI/components/chat/Markdown.tsx +0 -134
  63. package/components/AGUI/components/chat/Messages.tsx +0 -259
  64. package/components/AGUI/components/chat/Modal.tsx +0 -133
  65. package/components/AGUI/components/chat/Popup.tsx +0 -57
  66. package/components/AGUI/components/chat/PoweredByTag.tsx +0 -29
  67. package/components/AGUI/components/chat/Sidebar.tsx +0 -74
  68. package/components/AGUI/components/chat/Suggestion.tsx +0 -132
  69. package/components/AGUI/components/chat/Suggestions.tsx +0 -20
  70. package/components/AGUI/components/chat/Textarea.tsx +0 -61
  71. package/components/AGUI/components/chat/Window.tsx +0 -152
  72. package/components/AGUI/components/chat/index.tsx +0 -11
  73. package/components/AGUI/components/chat/messages/AssistantMessage.tsx +0 -69
  74. package/components/AGUI/components/chat/messages/RenderActionExecutionMessage.tsx +0 -129
  75. package/components/AGUI/components/chat/messages/RenderAgentStateMessage.tsx +0 -116
  76. package/components/AGUI/components/chat/messages/RenderImageMessage.tsx +0 -64
  77. package/components/AGUI/components/chat/messages/RenderResultMessage.tsx +0 -26
  78. package/components/AGUI/components/chat/messages/RenderTextMessage.tsx +0 -51
  79. package/components/AGUI/components/chat/messages/UserMessage.tsx +0 -10
  80. package/components/AGUI/components/chat/props.ts +0 -186
  81. package/components/AGUI/components/index.ts +0 -1
  82. package/components/AGUI/context/index.ts +0 -1
  83. package/components/AGUI/hooks/index.ts +0 -1
  84. package/components/AGUI/hooks/use-copilot-chat-suggestions.tsx +0 -122
  85. package/components/AGUI/hooks/use-copy-to-clipboard.tsx +0 -29
  86. package/components/AGUI/hooks/use-dark-mode.ts +0 -10
  87. package/components/AGUI/hooks/use-push-to-talk.tsx +0 -166
  88. package/components/AGUI/index.tsx +0 -4
  89. package/components/AGUI/lib/utils.test.ts +0 -7
  90. package/components/AGUI/lib/utils.ts +0 -27
  91. package/components/AGUI/styles.css +0 -0
  92. package/components/AGUI/types/css.ts +0 -0
  93. package/components/AGUI/types/index.ts +0 -1
  94. package/components/AGUI/types/suggestions.ts +0 -6
  95. package/components/Markdown/Markdown/AnimationNode.tsx +0 -89
  96. package/components/Markdown/Markdown/Markdown.tsx +0 -61
  97. package/components/Markdown/Markdown/core/Parser.ts +0 -52
  98. package/components/Markdown/Markdown/core/Renderer.ts +0 -121
  99. package/components/Markdown/Markdown/core/index.ts +0 -4
  100. package/components/Markdown/Markdown/hooks/index.ts +0 -4
  101. package/components/Markdown/Markdown/hooks/useAnimation.tsx +0 -27
  102. package/components/Markdown/Markdown/hooks/useStreaming.ts +0 -503
  103. package/components/Markdown/Markdown/index.tsx +0 -198
  104. package/components/Markdown/Markdown/interface.ts +0 -217
  105. package/components/Markdown/demo/typing.tsx +0 -82
  106. package/components/Markdown/index.ts +0 -1
  107. package/components/Markdown/plugins/latex/index.ts +0 -109
  108. package/components/Markdown/plugins/type.ts +0 -71
  109. package/lib/AGUI/components/HelpModal/icons.d.ts +0 -5
  110. package/lib/AGUI/components/HelpModal/icons.js +0 -84
  111. package/lib/AGUI/components/HelpModal/index.d.ts +0 -1
  112. package/lib/AGUI/components/HelpModal/index.js +0 -1
  113. package/lib/AGUI/components/HelpModal/modal.d.ts +0 -1
  114. package/lib/AGUI/components/HelpModal/modal.js +0 -104
  115. package/lib/AGUI/components/chat/Button.d.ts +0 -2
  116. package/lib/AGUI/components/chat/Button.js +0 -27
  117. package/lib/AGUI/components/chat/Chat.d.ts +0 -242
  118. package/lib/AGUI/components/chat/Chat.js +0 -634
  119. package/lib/AGUI/components/chat/ChatContext.d.ts +0 -142
  120. package/lib/AGUI/components/chat/ChatContext.js +0 -75
  121. package/lib/AGUI/components/chat/CodeBlock.d.ts +0 -12
  122. package/lib/AGUI/components/chat/CodeBlock.js +0 -398
  123. package/lib/AGUI/components/chat/Header.d.ts +0 -2
  124. package/lib/AGUI/components/chat/Header.js +0 -28
  125. package/lib/AGUI/components/chat/Icons.d.ts +0 -16
  126. package/lib/AGUI/components/chat/Icons.js +0 -247
  127. package/lib/AGUI/components/chat/ImageUploadQueue.d.ts +0 -11
  128. package/lib/AGUI/components/chat/ImageUploadQueue.js +0 -65
  129. package/lib/AGUI/components/chat/Input.d.ts +0 -2
  130. package/lib/AGUI/components/chat/Input.js +0 -30
  131. package/lib/AGUI/components/chat/Markdown.d.ts +0 -7
  132. package/lib/AGUI/components/chat/Markdown.js +0 -187
  133. package/lib/AGUI/components/chat/Messages.d.ts +0 -7
  134. package/lib/AGUI/components/chat/Messages.js +0 -242
  135. package/lib/AGUI/components/chat/Modal.d.ts +0 -43
  136. package/lib/AGUI/components/chat/Modal.js +0 -113
  137. package/lib/AGUI/components/chat/Popup.d.ts +0 -49
  138. package/lib/AGUI/components/chat/Popup.js +0 -64
  139. package/lib/AGUI/components/chat/PoweredByTag.d.ts +0 -3
  140. package/lib/AGUI/components/chat/PoweredByTag.js +0 -27
  141. package/lib/AGUI/components/chat/Sidebar.d.ts +0 -2
  142. package/lib/AGUI/components/chat/Sidebar.js +0 -85
  143. package/lib/AGUI/components/chat/Suggestion.d.ts +0 -16
  144. package/lib/AGUI/components/chat/Suggestion.js +0 -146
  145. package/lib/AGUI/components/chat/Suggestions.d.ts +0 -2
  146. package/lib/AGUI/components/chat/Suggestions.js +0 -21
  147. package/lib/AGUI/components/chat/Textarea.d.ts +0 -11
  148. package/lib/AGUI/components/chat/Textarea.js +0 -60
  149. package/lib/AGUI/components/chat/Window.d.ts +0 -2
  150. package/lib/AGUI/components/chat/Window.js +0 -115
  151. package/lib/AGUI/components/chat/index.d.ts +0 -11
  152. package/lib/AGUI/components/chat/index.js +0 -11
  153. package/lib/AGUI/components/chat/messages/AssistantMessage.d.ts +0 -2
  154. package/lib/AGUI/components/chat/messages/AssistantMessage.js +0 -56
  155. package/lib/AGUI/components/chat/messages/RenderActionExecutionMessage.d.ts +0 -2
  156. package/lib/AGUI/components/chat/messages/RenderActionExecutionMessage.js +0 -114
  157. package/lib/AGUI/components/chat/messages/RenderAgentStateMessage.d.ts +0 -2
  158. package/lib/AGUI/components/chat/messages/RenderAgentStateMessage.js +0 -97
  159. package/lib/AGUI/components/chat/messages/RenderImageMessage.d.ts +0 -2
  160. package/lib/AGUI/components/chat/messages/RenderImageMessage.js +0 -61
  161. package/lib/AGUI/components/chat/messages/RenderResultMessage.d.ts +0 -2
  162. package/lib/AGUI/components/chat/messages/RenderResultMessage.js +0 -27
  163. package/lib/AGUI/components/chat/messages/RenderTextMessage.d.ts +0 -2
  164. package/lib/AGUI/components/chat/messages/RenderTextMessage.js +0 -47
  165. package/lib/AGUI/components/chat/messages/UserMessage.d.ts +0 -2
  166. package/lib/AGUI/components/chat/messages/UserMessage.js +0 -9
  167. package/lib/AGUI/components/chat/props.d.ts +0 -157
  168. package/lib/AGUI/components/index.d.ts +0 -1
  169. package/lib/AGUI/components/index.js +0 -1
  170. package/lib/AGUI/context/index.d.ts +0 -1
  171. package/lib/AGUI/context/index.js +0 -1
  172. package/lib/AGUI/hooks/index.d.ts +0 -1
  173. package/lib/AGUI/hooks/index.js +0 -1
  174. package/lib/AGUI/hooks/use-copilot-chat-suggestions.d.ts +0 -87
  175. package/lib/AGUI/hooks/use-copilot-chat-suggestions.js +0 -95
  176. package/lib/AGUI/hooks/use-copy-to-clipboard.d.ts +0 -7
  177. package/lib/AGUI/hooks/use-copy-to-clipboard.js +0 -34
  178. package/lib/AGUI/hooks/use-dark-mode.d.ts +0 -1
  179. package/lib/AGUI/hooks/use-dark-mode.js +0 -4
  180. package/lib/AGUI/hooks/use-push-to-talk.d.ts +0 -16
  181. package/lib/AGUI/hooks/use-push-to-talk.js +0 -260
  182. package/lib/AGUI/index.d.ts +0 -4
  183. package/lib/AGUI/index.js +0 -4
  184. package/lib/AGUI/lib/utils.d.ts +0 -2
  185. package/lib/AGUI/lib/utils.js +0 -52
  186. package/lib/AGUI/styles.css +0 -0
  187. package/lib/AGUI/types/css.d.ts +0 -0
  188. package/lib/AGUI/types/css.js +0 -0
  189. package/lib/AGUI/types/index.d.ts +0 -1
  190. package/lib/AGUI/types/index.js +0 -1
  191. package/lib/AGUI/types/suggestions.d.ts +0 -6
  192. package/lib/AGUI/types/suggestions.js +0 -1
  193. package/lib/Markdown/Markdown/AnimationNode.d.ts +0 -20
  194. package/lib/Markdown/Markdown/AnimationNode.js +0 -84
  195. package/lib/Markdown/Markdown/Markdown.d.ts +0 -4
  196. package/lib/Markdown/Markdown/Markdown.js +0 -58
  197. package/lib/Markdown/Markdown/core/Parser.d.ts +0 -16
  198. package/lib/Markdown/Markdown/core/Parser.js +0 -65
  199. package/lib/Markdown/Markdown/core/Renderer.d.ts +0 -24
  200. package/lib/Markdown/Markdown/core/Renderer.js +0 -137
  201. package/lib/Markdown/Markdown/core/index.d.ts +0 -3
  202. package/lib/Markdown/Markdown/core/index.js +0 -3
  203. package/lib/Markdown/Markdown/hooks/index.d.ts +0 -3
  204. package/lib/Markdown/Markdown/hooks/index.js +0 -3
  205. package/lib/Markdown/Markdown/hooks/useAnimation.d.ts +0 -4
  206. package/lib/Markdown/Markdown/hooks/useCitationsData.d.ts +0 -7
  207. package/lib/Markdown/Markdown/hooks/useStreaming.d.ts +0 -3
  208. package/lib/Markdown/Markdown/hooks/useStreaming.js +0 -521
  209. package/lib/Markdown/Markdown/hooks/useTyping.d.ts +0 -4
  210. package/lib/Markdown/Markdown/index.d.ts +0 -84
  211. package/lib/Markdown/Markdown/index.js +0 -161
  212. package/lib/Markdown/Markdown/interface.d.ts +0 -203
  213. package/lib/Markdown/Markdown/interface.js +0 -1
  214. package/lib/Markdown/Markdown/style.js +0 -32
  215. package/lib/Markdown/plugins/latex/index.d.ts +0 -9
  216. package/lib/Markdown/plugins/latex/index.js +0 -97
  217. package/lib/Markdown/plugins/type.d.ts +0 -60
  218. package/lib/Markdown/plugins/type.js +0 -1
  219. /package/components/Markdown/{Markdown/defaultComponents/DisabledImage.tsx → core/components/DisableImage.tsx} +0 -0
  220. /package/components/Markdown/{Markdown/defaultComponents → core/components}/Media.tsx +0 -0
  221. /package/components/Markdown/{plugins → core/plugins}/cursor/Dot.tsx +0 -0
  222. /package/lib/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.d.ts +0 -0
  223. /package/lib/Markdown/{Markdown/defaultComponents → core/components}/CodeBlock.js +0 -0
  224. /package/lib/Markdown/{Markdown/defaultComponents/DisabledImage.d.ts → core/components/DisableImage.d.ts} +0 -0
  225. /package/lib/Markdown/{Markdown/defaultComponents/DisabledImage.js → core/components/DisableImage.js} +0 -0
  226. /package/lib/Markdown/{Markdown/defaultComponents → core/components}/Media.d.ts +0 -0
  227. /package/lib/Markdown/{Markdown/defaultComponents → core/components}/Media.js +0 -0
  228. /package/lib/Markdown/{plugins → core/plugins}/citations/CitationComponent.d.ts +0 -0
  229. /package/lib/Markdown/{plugins → core/plugins}/cursor/Dot.d.ts +0 -0
  230. /package/lib/Markdown/{plugins → core/plugins}/cursor/Underline.d.ts +0 -0
  231. /package/lib/Markdown/{plugins → core/plugins}/cursor/index.d.ts +0 -0
  232. /package/lib/Markdown/{Markdown/style.d.ts → styles.d.ts} +0 -0
  233. /package/lib/{AGUI/components/chat/props.js → Markdown/types.js} +0 -0
@@ -1,521 +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 _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
- 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."); }
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 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; }
8
- 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; }
9
- 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; }
10
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
11
- 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); }
12
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
13
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
- 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); }
15
- 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; }
16
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
17
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
19
- var TokenType = /*#__PURE__*/function (TokenType) {
20
- TokenType[TokenType["Text"] = 0] = "Text";
21
- TokenType[TokenType["Link"] = 1] = "Link";
22
- TokenType[TokenType["Image"] = 2] = "Image";
23
- TokenType[TokenType["Heading"] = 3] = "Heading";
24
- TokenType[TokenType["MaybeEmphasis"] = 4] = "MaybeEmphasis";
25
- TokenType[TokenType["Emphasis"] = 5] = "Emphasis";
26
- TokenType[TokenType["Strong"] = 6] = "Strong";
27
- TokenType[TokenType["XML"] = 7] = "XML";
28
- TokenType[TokenType["MaybeCode"] = 8] = "MaybeCode";
29
- TokenType[TokenType["Code"] = 9] = "Code";
30
- TokenType[TokenType["MaybeHr"] = 10] = "MaybeHr";
31
- TokenType[TokenType["MaybeList"] = 11] = "MaybeList";
32
- TokenType[TokenType["MaybeInlineMath"] = 12] = "MaybeInlineMath";
33
- TokenType[TokenType["InlineMath"] = 13] = "InlineMath";
34
- TokenType[TokenType["MaybeBlockMath"] = 14] = "MaybeBlockMath";
35
- TokenType[TokenType["BlockMath"] = 15] = "BlockMath";
36
- TokenType[TokenType["MaybeBackslashMath"] = 16] = "MaybeBackslashMath";
37
- TokenType[TokenType["Word"] = 17] = "Word";
38
- return TokenType;
39
- }(TokenType || {});
40
- var Markdown_Symbols = {
41
- emphasis: ['*', '_'],
42
- code: ['`'],
43
- list: ['-', '+', '*']
44
- };
45
-
46
- // 辅助函数:判断是否是英文字母
47
- var isEnglishLetter = function isEnglishLetter(char) {
48
- var code = char.charCodeAt(0);
49
- return code >= 65 && code <= 90 || code >= 97 && code <= 122; // A-Z or a-z
50
- };
51
-
52
- // 辅助函数:判断是否是单词的一部分(字母、数字、连字符、撇号)
53
- var isWordChar = function isWordChar(char) {
54
- var code = char.charCodeAt(0);
55
- return code >= 65 && code <= 90 ||
56
- // A-Z
57
- code >= 97 && code <= 122 ||
58
- // a-z
59
- code >= 48 && code <= 57 ||
60
- // 0-9
61
- char === '-' ||
62
- // 连字符 (well-known)
63
- char === "'" // 撇号 (don't)
64
- ;
65
- };
66
-
67
- // 辅助函数:判断是否是单词分隔符
68
- var isWordSeparator = function isWordSeparator(char) {
69
- return char === ' ' || char === '\n' || char === '\t' || char === ',' || char === '.' || char === '!' || char === '?' || char === ';' || char === ':' || char === ')' || char === ']' || char === '}' || char === '"' || char === "'" || char === '>' || char === '<';
70
- };
71
- var STREAM_BUFFER_INIT = {
72
- processedLength: 0,
73
- rawStream: '',
74
- pending: '',
75
- token: TokenType.Text,
76
- tokens: [TokenType.Text],
77
- headingLevel: 0,
78
- emphasisCount: 0,
79
- backtickCount: 0,
80
- dollarCount: 0,
81
- mathDelimiter: '',
82
- blockMathEnding: false // 标记是否遇到了结束的 $$
83
- };
84
- var useStreaming = function useStreaming(input, config, cursor) {
85
- var _ref = config || {},
86
- _ref$hasNextChunk = _ref.hasNextChunk,
87
- hasNextChunk = _ref$hasNextChunk === void 0 ? false : _ref$hasNextChunk,
88
- _ref$enableWordCachin = _ref.enableWordCaching,
89
- enableWordCaching = _ref$enableWordCachin === void 0 ? false : _ref$enableWordCachin,
90
- _ref$enableMathCachin = _ref.enableMathCaching,
91
- enableMathCaching = _ref$enableMathCachin === void 0 ? true : _ref$enableMathCachin;
92
- var _useState = useState(''),
93
- _useState2 = _slicedToArray(_useState, 2),
94
- output = _useState2[0],
95
- setOutput = _useState2[1];
96
- var streamBuffer = useRef(_objectSpread({}, STREAM_BUFFER_INIT));
97
- var pushToken = useCallback(function (type) {
98
- streamBuffer.current.tokens = [].concat(_toConsumableArray(streamBuffer.current.tokens), [type]);
99
- streamBuffer.current.token = type;
100
- }, []);
101
- var popToken = useCallback(function () {
102
- var tokens = streamBuffer.current.tokens;
103
- if (tokens.length <= 1) return;
104
- var newTokens = _toConsumableArray(tokens.slice(0, -1));
105
- streamBuffer.current.tokens = newTokens;
106
- streamBuffer.current.token = newTokens[newTokens.length - 1];
107
- }, []);
108
- var flushOutput = function flushOutput() {
109
- var needPopToken = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
110
- if (needPopToken) popToken();
111
- streamBuffer.current.pending = '';
112
- streamBuffer.current.blockMathEnding = false;
113
- var renderText = streamBuffer.current.rawStream;
114
- if (renderText) {
115
- setOutput(renderText);
116
- }
117
- };
118
- var handleChunk = function handleChunk(chunk) {
119
- var buffer = streamBuffer.current;
120
- var _iterator = _createForOfIteratorHelper(chunk),
121
- _step;
122
- try {
123
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
124
- var char = _step.value;
125
- buffer.rawStream += char;
126
- buffer.pending += char;
127
- var token = buffer.token,
128
- pending = buffer.pending,
129
- tokens = buffer.tokens,
130
- emphasisCount = buffer.emphasisCount;
131
- switch (token) {
132
- case TokenType.Image:
133
- {
134
- /**
135
- * \![
136
- * ^
137
- */
138
- var isInvalidStart = pending.indexOf('![') === -1;
139
- /**
140
- * \![image]()
141
- * ^
142
- */
143
- var isImageEnd = char === ')' || char === '\n';
144
- if (isInvalidStart || isImageEnd) {
145
- if (tokens[tokens.length - 2] === TokenType.Link) {
146
- popToken();
147
- } else {
148
- flushOutput();
149
- }
150
- }
151
- break;
152
- }
153
- case TokenType.Link:
154
- {
155
- // not support link reference definitions, [foo]: /url "title" \n[foo]
156
- var isReferenceLink = pending.endsWith(']:');
157
- var isLinkEnd = char === ')' || char === '\n';
158
- var isImageInLink = char === '!';
159
- if (isImageInLink) {
160
- pushToken(TokenType.Image);
161
- } else if (isLinkEnd || isReferenceLink) {
162
- flushOutput();
163
- }
164
- break;
165
- }
166
- case TokenType.Heading:
167
- {
168
- /**
169
- * # token / ## token / #####token
170
- * ^ ^ ^
171
- */
172
- buffer.headingLevel++;
173
- var shouldFlushOutput = char !== '#' || buffer.headingLevel >= 6;
174
- if (shouldFlushOutput) {
175
- flushOutput();
176
- buffer.headingLevel = 0;
177
- }
178
- break;
179
- }
180
- case TokenType.MaybeEmphasis:
181
- {
182
- /**
183
- * /* / *\/n
184
- ^ ^
185
- */
186
- var _shouldFlushOutput = char === ' ' || char === '\n';
187
- if (_shouldFlushOutput) {
188
- flushOutput();
189
- } else if (Markdown_Symbols.emphasis.includes(char)) {
190
- buffer.emphasisCount++;
191
- } else {
192
- popToken();
193
- if (emphasisCount === 1) {
194
- /**
195
- * _token_ / *token*
196
- * ^ ^
197
- */
198
- pushToken(TokenType.Emphasis);
199
- } else if (emphasisCount === 2) {
200
- /**
201
- * __token__ / **token**
202
- * ^ ^
203
- */
204
- pushToken(TokenType.Strong);
205
- } else if (emphasisCount === 3) {
206
- /**
207
- * ___token___ / ***token***
208
- * ^ ^
209
- */
210
- pushToken(TokenType.Emphasis);
211
- pushToken(TokenType.Strong);
212
- } else {
213
- // no more than 3
214
- buffer.emphasisCount = 0;
215
- }
216
- }
217
- break;
218
- }
219
- case TokenType.Strong:
220
- {
221
- /**
222
- * __token__ / **token**
223
- * ^ ^
224
- */
225
- if (char === '\n') {
226
- flushOutput();
227
- } else if (pending.endsWith('**') || pending.endsWith('__')) {
228
- if (tokens[tokens.length - 2] === TokenType.Emphasis) {
229
- popToken();
230
- } else {
231
- flushOutput();
232
- }
233
- }
234
- break;
235
- }
236
- case TokenType.Emphasis:
237
- {
238
- /**
239
- * _token_ / *token*
240
- * ^ ^
241
- */
242
- if (char === '\n') {
243
- flushOutput();
244
- buffer.emphasisCount = 0;
245
- } else if (Markdown_Symbols.emphasis.includes(char)) {
246
- flushOutput();
247
- buffer.emphasisCount = 0;
248
- }
249
- break;
250
- }
251
- case TokenType.XML:
252
- {
253
- /**
254
- * <XML /> /<XML></XML>
255
- * ^ ^
256
- */
257
- var _shouldFlushOutput2 = char === '>' || pending === '< ' || char === '\n';
258
- if (_shouldFlushOutput2) {
259
- flushOutput();
260
- continue;
261
- }
262
- break;
263
- }
264
- case TokenType.MaybeCode:
265
- {
266
- if (char === '`') {
267
- buffer.backtickCount++;
268
- } else {
269
- if (buffer.backtickCount > 2) {
270
- /**
271
- * ```
272
- * ^
273
- */
274
- flushOutput();
275
- buffer.backtickCount = 0;
276
- } else {
277
- /**
278
- * ``
279
- * ^
280
- */
281
- popToken();
282
- pushToken(TokenType.Code);
283
- }
284
- }
285
- break;
286
- }
287
- case TokenType.Code:
288
- {
289
- if (char === '`') {
290
- buffer.backtickCount--;
291
- }
292
- if (buffer.backtickCount === 0) {
293
- flushOutput();
294
- buffer.backtickCount = 0;
295
- }
296
- break;
297
- }
298
- case TokenType.MaybeHr:
299
- {
300
- if (char !== '-' && char !== '=') {
301
- flushOutput();
302
- }
303
- break;
304
- }
305
- case TokenType.MaybeList:
306
- {
307
- if (char !== ' ') {
308
- flushOutput();
309
- }
310
- break;
311
- }
312
- case TokenType.MaybeInlineMath:
313
- {
314
- /**
315
- * $ / $$
316
- * ^ ^
317
- */
318
- if (char === '$') {
319
- buffer.dollarCount++;
320
- if (buffer.dollarCount === 2) {
321
- // $$ 块级公式
322
- popToken();
323
- pushToken(TokenType.MaybeBlockMath);
324
- buffer.mathDelimiter = '$$';
325
- }
326
- } else if (char === '\n') {
327
- // $ 后跟换行,不是有效的公式
328
- flushOutput();
329
- buffer.dollarCount = 0;
330
- buffer.mathDelimiter = '';
331
- } else {
332
- // 确认为行内公式
333
- popToken();
334
- pushToken(TokenType.InlineMath);
335
- buffer.mathDelimiter = '$';
336
- }
337
- break;
338
- }
339
- case TokenType.InlineMath:
340
- {
341
- /**
342
- * $x^2$ / \(x^2\)
343
- * ^ ^
344
- */
345
- if (buffer.mathDelimiter === '$') {
346
- if (char === '$') {
347
- flushOutput();
348
- buffer.dollarCount = 0;
349
- buffer.mathDelimiter = '';
350
- } else if (char === '\n') {
351
- // 行内公式不应跨行
352
- flushOutput();
353
- buffer.dollarCount = 0;
354
- buffer.mathDelimiter = '';
355
- }
356
- } else if (buffer.mathDelimiter === '\\(') {
357
- if (pending.endsWith('\\)')) {
358
- flushOutput();
359
- buffer.mathDelimiter = '';
360
- }
361
- }
362
- break;
363
- }
364
- case TokenType.MaybeBlockMath:
365
- {
366
- /**
367
- * $$
368
- * ^
369
- */
370
- if (char !== '$') {
371
- // $$ 后跟任何非 $ 字符,确认为块级公式
372
- popToken();
373
- pushToken(TokenType.BlockMath);
374
- }
375
- break;
376
- }
377
- case TokenType.BlockMath:
378
- {
379
- /**
380
- * $$E=mc^2$$
381
- * ^^
382
- */
383
- // 处理 $$ 块级公式
384
- if (buffer.mathDelimiter === '$$') {
385
- // 检测是否遇到结束的 $$
386
- if (char === '$') {
387
- buffer.dollarCount++;
388
- if (buffer.dollarCount === 2) {
389
- // 遇到了结束 $$,立即释放缓存
390
- flushOutput();
391
- buffer.dollarCount = 0;
392
- buffer.mathDelimiter = '';
393
- }
394
- } else {
395
- buffer.dollarCount = 0;
396
- }
397
- } else if (buffer.mathDelimiter === '\\[') {
398
- // 处理 \[...\] 块级公式
399
- if (pending.endsWith('\\]')) {
400
- flushOutput();
401
- buffer.mathDelimiter = '';
402
- }
403
- }
404
- break;
405
- }
406
- case TokenType.MaybeBackslashMath:
407
- {
408
- /**
409
- * \( / \[
410
- * ^ ^
411
- */
412
- if (char === '(') {
413
- // \( 行内公式
414
- popToken();
415
- pushToken(TokenType.InlineMath);
416
- buffer.mathDelimiter = '\\(';
417
- } else if (char === '[') {
418
- // \[ 块级公式
419
- popToken();
420
- pushToken(TokenType.BlockMath);
421
- buffer.mathDelimiter = '\\[';
422
- } else {
423
- // 不是数学公式,普通反斜杠
424
- flushOutput();
425
- buffer.mathDelimiter = '';
426
- }
427
- break;
428
- }
429
- case TokenType.Word:
430
- {
431
- /**
432
- * Hello world
433
- * ^
434
- * 缓存英文单词,直到遇到分隔符(空格、标点等)
435
- */
436
- if (isWordSeparator(char)) {
437
- // 遇到分隔符,释放缓存显示完整单词
438
- flushOutput();
439
- } else if (!isWordChar(char)) {
440
- // 遇到非单词字符且非分隔符(如 Markdown 符号),也释放缓存
441
- flushOutput();
442
- }
443
- // 否则继续缓存单词字符
444
- break;
445
- }
446
- default:
447
- {
448
- buffer.pending = char;
449
- if (char === '!') {
450
- pushToken(TokenType.Image);
451
- } else if (char === '[') {
452
- pushToken(TokenType.Link);
453
- } else if (char === '#') {
454
- pushToken(TokenType.Heading);
455
- } else if (char === '_' || char === '*') {
456
- pushToken(TokenType.MaybeEmphasis);
457
- buffer.emphasisCount = 1;
458
- } else if (char === '<') {
459
- pushToken(TokenType.XML);
460
- } else if (char === '`') {
461
- pushToken(TokenType.MaybeCode);
462
- buffer.backtickCount = 1;
463
- } else if (char === '-' || char === '=') {
464
- pushToken(TokenType.MaybeHr);
465
- } else if (Markdown_Symbols.list.includes(char)) {
466
- pushToken(TokenType.MaybeList);
467
- } else if (enableMathCaching && char === '$') {
468
- // 只有启用公式缓存时,才缓存 $ 符号的公式
469
- pushToken(TokenType.MaybeInlineMath);
470
- buffer.dollarCount = 1;
471
- buffer.mathDelimiter = '';
472
- } else if (enableMathCaching && char === '\\') {
473
- // 只有启用公式缓存时,才缓存 \ 开头的公式
474
- pushToken(TokenType.MaybeBackslashMath);
475
- } else if (enableWordCaching && isEnglishLetter(char)) {
476
- // 只有启用单词缓存时,才缓存英文单词
477
- pushToken(TokenType.Word);
478
- } else {
479
- flushOutput(false);
480
- }
481
- }
482
- }
483
- }
484
- } catch (err) {
485
- _iterator.e(err);
486
- } finally {
487
- _iterator.f();
488
- }
489
- };
490
- var cursorContent = useMemo(function () {
491
- if (config !== null && config !== void 0 && config.enableAnimation) return '';
492
- if (cursor) {
493
- if (cursor === 'dot') return ' :dot:';
494
- if (cursor === 'underline') return ' :underline:';
495
- return ' :dot:';
496
- }
497
- return '';
498
- }, [cursor]);
499
- useEffect(function () {
500
- if (!input) {
501
- setOutput('');
502
- streamBuffer.current = _objectSpread({}, STREAM_BUFFER_INIT);
503
- return;
504
- }
505
- if (typeof input !== 'string') {
506
- console.error("X-Markdown: input must be string, not ".concat(_typeof(input), "."));
507
- return;
508
- }
509
- if (!hasNextChunk) {
510
- setOutput(input);
511
- return;
512
- }
513
- var chunk = input.slice(streamBuffer.current.processedLength);
514
- if (chunk.length) {
515
- streamBuffer.current.processedLength += chunk.length;
516
- handleChunk(chunk);
517
- }
518
- }, [input, hasNextChunk]);
519
- return output + cursorContent;
520
- };
521
- export default useStreaming;
@@ -1,4 +0,0 @@
1
- export declare const useTyping: ({ content, typing }: {
2
- content: any;
3
- typing: any;
4
- }) => any;
@@ -1,84 +0,0 @@
1
- /// <reference types="react" />
2
- import type { MarkdownProps as InnerMarkdownProps } from './interface';
3
- export interface MarkdownProps {
4
- /**
5
- * @description 需要渲染的 Markdown 内容
6
- * @descriptionEn Markdown content to be rendered
7
- */
8
- content?: InnerMarkdownProps['content'];
9
- /**
10
- * @description 光标样式类型,支持点状、下划线或布尔值控制
11
- * @descriptionEn Cursor style type, supports dot, underline, or boolean control
12
- */
13
- cursor?: boolean | 'dot' | 'underline';
14
- /**
15
- * @description 基础字体大小,影响整个Markdown内容的字体大小
16
- * @descriptionEn Base font size that affects the font size of the entire Markdown content
17
- */
18
- baseFontSize?: InnerMarkdownProps['baseFontSize'];
19
- /**
20
- * @description 基础行高,影响文本的行间距
21
- * @descriptionEn Base line height that affects text line spacing
22
- */
23
- baseLineHeight?: InnerMarkdownProps['baseLineHeight'];
24
- /**
25
- * @description 引用数据数组,用于显示引用信息
26
- * @descriptionEn Citation data array for displaying reference information
27
- */
28
- citations?: InnerMarkdownProps['citations'];
29
- /**
30
- * @description 引用映射对象,用于快速查找引用信息
31
- * @descriptionEn Citation mapping object for quick lookup of reference information
32
- */
33
- citationsMap?: InnerMarkdownProps['citationsMap'];
34
- /**
35
- * @description 用于替换 HTML 元素的自定义 React 组件映射,组件会接收 domNode、streamStatus 等属性
36
- * @descriptionEn Custom React components to replace HTML elements, components receive domNode, streamStatus, etc.
37
- */
38
- components?: InnerMarkdownProps['components'];
39
- /**
40
- * @description 是否允许渲染HTML标签,影响安全性
41
- * @descriptionEn Whether to allow rendering HTML tags, affects security
42
- */
43
- allowHtml?: boolean;
44
- /**
45
- * @description 是否禁用图片渲染
46
- * @descriptionEn Whether to disable image rendering
47
- */
48
- disableImage?: boolean;
49
- /**
50
- * @description 是否启用打字机效果,逐字显示内容
51
- * @descriptionEn Whether to enable typewriter effect for character-by-character display
52
- */
53
- typing?: boolean | number;
54
- /**
55
- * @description 是否以原始文本形式显示,跳过Markdown解析
56
- * @descriptionEn Whether to display as raw text, skipping Markdown parsing
57
- */
58
- raw?: boolean;
59
- /**
60
- * @description 组件的CSS类名
61
- * @descriptionEn CSS class name for the component
62
- */
63
- className?: string;
64
- /**
65
- * @description 启用英文单词缓存,单词会在遇到空格或标点后才整体显示(仅在 typing 为 true 时生效)
66
- * @descriptionEn Enable English word caching, words will be displayed as a whole after encountering spaces or punctuation (only works when typing is true)
67
- * @default false
68
- */
69
- enableWordCaching?: boolean;
70
- /**
71
- * @description 启用 LaTeX 公式缓存,公式会在完整后才整体显示(仅在 typing 为 true 时生效)
72
- * @descriptionEn Enable LaTeX formula caching, formulas will be displayed as a whole when complete (only works when typing is true)
73
- * @default true
74
- */
75
- enableMathCaching?: boolean;
76
- /**
77
- * @description 启用文字出现动画效果
78
- * @descriptionEn Enable text appearance animation effects
79
- * @default false
80
- */
81
- enableAnimation?: boolean;
82
- }
83
- declare const _default: import("react").NamedExoticComponent<MarkdownProps>;
84
- export default _default;