@ant-design/agentic-ui 2.8.0 → 2.10.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.
Files changed (585) hide show
  1. package/dist/AgentRunBar/Robot.js +105 -57
  2. package/dist/AgentRunBar/icons/PauseIcon.js +38 -38
  3. package/dist/AgentRunBar/icons/PlayIcon.js +38 -38
  4. package/dist/AgentRunBar/icons/SimplePauseIcon.js +38 -38
  5. package/dist/AgentRunBar/icons/SimplePlayIcon.js +38 -38
  6. package/dist/AgentRunBar/icons/SimpleStopIcon.js +38 -38
  7. package/dist/AgentRunBar/icons/StopIcon.js +41 -50
  8. package/dist/AgentRunBar/icons/index.js +0 -1
  9. package/dist/AgentRunBar/index.js +270 -237
  10. package/dist/AgentRunBar/style.js +273 -239
  11. package/dist/AgenticLayout/index.js +140 -85
  12. package/dist/AgenticLayout/style.js +126 -107
  13. package/dist/AnswerAlert/components/CloseIcon.js +12 -21
  14. package/dist/AnswerAlert/components/ErrorIcon.js +42 -38
  15. package/dist/AnswerAlert/components/InfoIcon.js +42 -38
  16. package/dist/AnswerAlert/components/LoaderIcon.js +12 -21
  17. package/dist/AnswerAlert/components/SuccessIcon.js +42 -38
  18. package/dist/AnswerAlert/components/WarningIcon.js +42 -38
  19. package/dist/AnswerAlert/index.js +155 -75
  20. package/dist/AnswerAlert/style.js +159 -147
  21. package/dist/BackTo/BackBottom.js +154 -70
  22. package/dist/BackTo/BackTop.js +148 -68
  23. package/dist/BackTo/ScrollVisibleButton.js +124 -98
  24. package/dist/BackTo/hooks/useScrollVisible.js +79 -33
  25. package/dist/BackTo/icons/BottomIcon.js +37 -37
  26. package/dist/BackTo/icons/TopIcon.js +37 -37
  27. package/dist/BackTo/index.js +22 -7
  28. package/dist/BackTo/style.js +93 -70
  29. package/dist/Bubble/AIBubble.js +469 -406
  30. package/dist/Bubble/Avatar/index.js +139 -85
  31. package/dist/Bubble/Avatar/isEmoji.js +2 -6
  32. package/dist/Bubble/Bubble.js +114 -38
  33. package/dist/Bubble/BubbleBeforeNode.js +104 -74
  34. package/dist/Bubble/BubbleConfigProvide.js +3 -7
  35. package/dist/Bubble/FileView.js +63 -69
  36. package/dist/Bubble/List/PureBubbleList.js +130 -131
  37. package/dist/Bubble/List/SkeletonList.js +33 -24
  38. package/dist/Bubble/List/index.js +187 -124
  39. package/dist/Bubble/List/style.js +76 -47
  40. package/dist/Bubble/MessagesContent/BubbleContext.js +6 -12
  41. package/dist/Bubble/MessagesContent/BubbleExtra.js +663 -355
  42. package/dist/Bubble/MessagesContent/CopyButton/index.js +326 -96
  43. package/dist/Bubble/MessagesContent/DocInfo.js +351 -386
  44. package/dist/Bubble/MessagesContent/EXCEPTION.js +42 -22
  45. package/dist/Bubble/MessagesContent/MarkdownPreview.js +206 -156
  46. package/dist/Bubble/MessagesContent/VoiceButton/index.js +213 -115
  47. package/dist/Bubble/MessagesContent/VoiceButton/style.js +129 -105
  48. package/dist/Bubble/MessagesContent/VoiceButton/types.js +9 -0
  49. package/dist/Bubble/MessagesContent/docInfoStyle.js +118 -88
  50. package/dist/Bubble/MessagesContent/icons.js +157 -57
  51. package/dist/Bubble/MessagesContent/index.js +609 -368
  52. package/dist/Bubble/PureBubble.js +439 -326
  53. package/dist/Bubble/Title.js +110 -87
  54. package/dist/Bubble/UserBubble.js +218 -279
  55. package/dist/Bubble/index.js +10 -16
  56. package/dist/Bubble/style.js +248 -227
  57. package/dist/Bubble/type.js +3 -0
  58. package/dist/Bubble/types/BubbleExtra.js +1 -0
  59. package/dist/Bubble/types/DocInfo.js +1 -0
  60. package/dist/ChatBootPage/ButtonTab.js +25 -45
  61. package/dist/ChatBootPage/ButtonTabGroup.js +74 -47
  62. package/dist/ChatBootPage/ButtonTabGroupStyle.js +73 -45
  63. package/dist/ChatBootPage/ButtonTabStyle.js +121 -98
  64. package/dist/ChatBootPage/CaseReply.js +119 -113
  65. package/dist/ChatBootPage/CaseReplyStyle.js +217 -189
  66. package/dist/ChatBootPage/Title.js +19 -23
  67. package/dist/ChatBootPage/index.js +9 -11
  68. package/dist/ChatBootPage/style.js +80 -50
  69. package/dist/ChatLayout/index.js +93 -57
  70. package/dist/ChatLayout/style.js +206 -176
  71. package/dist/ChatLayout/types.js +1 -0
  72. package/dist/Components/ActionIconBox/index.js +571 -197
  73. package/dist/Components/ActionIconBox/style.js +141 -111
  74. package/dist/Components/ActionItemBox/ActionItemBox.js +95 -149
  75. package/dist/Components/ActionItemBox/index.js +7 -7
  76. package/dist/Components/ActionItemBox/style.js +353 -361
  77. package/dist/Components/Button/IconButton/index.js +35 -43
  78. package/dist/Components/Button/IconButton/style.js +357 -331
  79. package/dist/Components/Button/SwitchButton/index.js +243 -87
  80. package/dist/Components/Button/SwitchButton/style.js +160 -146
  81. package/dist/Components/Button/ToggleButton/index.js +46 -57
  82. package/dist/Components/Button/ToggleButton/style.js +283 -258
  83. package/dist/Components/Button/index.js +6 -2
  84. package/dist/Components/GradientText/index.js +21 -27
  85. package/dist/Components/GradientText/style.js +88 -63
  86. package/dist/Components/ImageList.js +111 -133
  87. package/dist/Components/LayoutHeader/index.js +145 -81
  88. package/dist/Components/LayoutHeader/style.js +89 -64
  89. package/dist/Components/LayoutHeader/types.js +3 -0
  90. package/dist/Components/Loading/index.js +53 -22
  91. package/dist/Components/Robot/index.js +90 -56
  92. package/dist/Components/Robot/lotties/DazingLottie/index.js +78 -47
  93. package/dist/Components/Robot/lotties/ThinkingLottie/index.js +78 -47
  94. package/dist/Components/Robot/lotties/index.js +0 -1
  95. package/dist/Components/SuggestionList/index.js +354 -182
  96. package/dist/Components/SuggestionList/style.js +204 -186
  97. package/dist/Components/TextAnimate/index.js +494 -362
  98. package/dist/Components/TextAnimate/style.js +72 -48
  99. package/dist/Components/TypingAnimation/index.js +214 -169
  100. package/dist/Components/TypingAnimation/style.js +76 -52
  101. package/dist/Components/VisualList/index.js +267 -180
  102. package/dist/Components/VisualList/style.js +140 -124
  103. package/dist/Components/icons/LoadingSpinnerIcon.js +124 -73
  104. package/dist/Components/lotties/DazingLottie/index.js +78 -47
  105. package/dist/Components/lotties/LoadingLottie/index.js +82 -48
  106. package/dist/Components/lotties/TextLoading/index.js +73 -49
  107. package/dist/Components/lotties/TextLoading/style.js +95 -78
  108. package/dist/Components/lotties/ThinkingLottie/index.js +78 -47
  109. package/dist/Components/lotties/index.js +0 -1
  110. package/dist/Constants/colors.js +71 -97
  111. package/dist/History/components/HistoryActionsBox.js +407 -180
  112. package/dist/History/components/HistoryEmpty.js +38 -42
  113. package/dist/History/components/HistoryEmptyIcon.js +682 -964
  114. package/dist/History/components/HistoryItem.js +683 -471
  115. package/dist/History/components/HistoryList.js +170 -87
  116. package/dist/History/components/HistoryRunningIcon.js +160 -111
  117. package/dist/History/components/LoadMoreComponent.js +308 -103
  118. package/dist/History/components/NewChatComponent.js +261 -69
  119. package/dist/History/components/NewChatComponent.style.js +79 -53
  120. package/dist/History/components/SearchComponent.js +367 -156
  121. package/dist/History/components/index.js +11 -23
  122. package/dist/History/hooks/useHistory.js +404 -129
  123. package/dist/History/index.js +301 -186
  124. package/dist/History/menu.js +158 -212
  125. package/dist/History/style.js +282 -276
  126. package/dist/History/types/HistoryData.js +6 -10
  127. package/dist/History/types/HistoryList.js +3 -0
  128. package/dist/History/types/index.js +3 -0
  129. package/dist/History/utils/index.js +35 -32
  130. package/dist/Hooks/useAutoScroll.js +262 -84
  131. package/dist/Hooks/useClickAway.js +60 -21
  132. package/dist/Hooks/useCopied.js +72 -20
  133. package/dist/Hooks/useDebounceFn/index.js +213 -55
  134. package/dist/Hooks/useIntersectionOnce.js +163 -74
  135. package/dist/Hooks/useLanguage.d.ts +3 -0
  136. package/dist/Hooks/useLanguage.js +67 -26
  137. package/dist/Hooks/useRefFunction/index.js +76 -11
  138. package/dist/Hooks/useSpeechSynthesis.js +143 -99
  139. package/dist/Hooks/useStyle/index.js +95 -60
  140. package/dist/Hooks/useThrottleFn/index.js +41 -41
  141. package/dist/I18n/index.js +246 -109
  142. package/dist/I18n/locales.d.ts +3 -0
  143. package/dist/I18n/locales.js +724 -711
  144. package/dist/Icons/animated/VoicePlayLottie/index.js +75 -46
  145. package/dist/Icons/animated/VoicingLottie/index.js +78 -47
  146. package/dist/MarkdownEditor/BaseMarkdownEditor.js +421 -349
  147. package/dist/MarkdownEditor/editor/Editor.js +1160 -843
  148. package/dist/MarkdownEditor/editor/components/CommentList/index.js +407 -239
  149. package/dist/MarkdownEditor/editor/components/CommentList/style.js +119 -89
  150. package/dist/MarkdownEditor/editor/components/ContributorAvatar/index.js +61 -63
  151. package/dist/MarkdownEditor/editor/components/ContributorAvatar/style.js +82 -52
  152. package/dist/MarkdownEditor/editor/components/LazyElement/index.js +208 -106
  153. package/dist/MarkdownEditor/editor/components/LazyElement/style.js +69 -42
  154. package/dist/MarkdownEditor/editor/components/fntTag/index.js +7 -11
  155. package/dist/MarkdownEditor/editor/components/fntTag/style.js +66 -36
  156. package/dist/MarkdownEditor/editor/components/index.js +0 -1
  157. package/dist/MarkdownEditor/editor/elements/Blockquote.js +95 -37
  158. package/dist/MarkdownEditor/editor/elements/Break.js +56 -25
  159. package/dist/MarkdownEditor/editor/elements/Card/index.js +131 -52
  160. package/dist/MarkdownEditor/editor/elements/Code.js +89 -67
  161. package/dist/MarkdownEditor/editor/elements/Comment/index.js +79 -50
  162. package/dist/MarkdownEditor/editor/elements/ErrorBoundary.js +117 -21
  163. package/dist/MarkdownEditor/editor/elements/FootnoteDefinition.js +83 -64
  164. package/dist/MarkdownEditor/editor/elements/FootnoteReference.js +115 -41
  165. package/dist/MarkdownEditor/editor/elements/Head.js +131 -67
  166. package/dist/MarkdownEditor/editor/elements/Hr.js +63 -38
  167. package/dist/MarkdownEditor/editor/elements/Image/index.js +636 -494
  168. package/dist/MarkdownEditor/editor/elements/InlineKatex.js +60 -44
  169. package/dist/MarkdownEditor/editor/elements/Katex.js +71 -55
  170. package/dist/MarkdownEditor/editor/elements/LinkCard/index.js +79 -175
  171. package/dist/MarkdownEditor/editor/elements/LinkCard/style.js +130 -100
  172. package/dist/MarkdownEditor/editor/elements/List/List.js +96 -69
  173. package/dist/MarkdownEditor/editor/elements/List/ListItem.js +422 -247
  174. package/dist/MarkdownEditor/editor/elements/List/index.js +1 -5
  175. package/dist/MarkdownEditor/editor/elements/List/style.js +131 -117
  176. package/dist/MarkdownEditor/editor/elements/Media.js +637 -519
  177. package/dist/MarkdownEditor/editor/elements/Mermaid.js +79 -54
  178. package/dist/MarkdownEditor/editor/elements/Paragraph.js +144 -83
  179. package/dist/MarkdownEditor/editor/elements/Schema.js +167 -128
  180. package/dist/MarkdownEditor/editor/elements/Table/ReadonlyTableComponent.js +211 -178
  181. package/dist/MarkdownEditor/editor/elements/Table/SimpleTable.js +73 -49
  182. package/dist/MarkdownEditor/editor/elements/Table/Table.js +285 -204
  183. package/dist/MarkdownEditor/editor/elements/Table/TableCellIndex/index.js +397 -280
  184. package/dist/MarkdownEditor/editor/elements/Table/TableCellIndex/style.js +126 -101
  185. package/dist/MarkdownEditor/editor/elements/Table/TableCellIndexSpacer/index.js +381 -276
  186. package/dist/MarkdownEditor/editor/elements/Table/TableCellIndexSpacer/style.js +120 -98
  187. package/dist/MarkdownEditor/editor/elements/Table/TableContext.js +64 -21
  188. package/dist/MarkdownEditor/editor/elements/Table/TableRowIndex/index.js +52 -42
  189. package/dist/MarkdownEditor/editor/elements/Table/TableRowIndex/style.js +69 -39
  190. package/dist/MarkdownEditor/editor/elements/Table/Td/index.js +126 -72
  191. package/dist/MarkdownEditor/editor/elements/Table/Td/style.js +85 -55
  192. package/dist/MarkdownEditor/editor/elements/Table/index.js +204 -105
  193. package/dist/MarkdownEditor/editor/elements/Table/style.js +244 -233
  194. package/dist/MarkdownEditor/editor/elements/Table/useScrollShadow.js +119 -62
  195. package/dist/MarkdownEditor/editor/elements/TagPopup/index.js +438 -276
  196. package/dist/MarkdownEditor/editor/elements/TagPopup/style.js +103 -77
  197. package/dist/MarkdownEditor/editor/elements/index.js +437 -424
  198. package/dist/MarkdownEditor/editor/parser/json-parse.js +38 -9
  199. package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +1753 -1168
  200. package/dist/MarkdownEditor/editor/parser/parserMdToSchema.js +16 -20
  201. package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +1021 -606
  202. package/dist/MarkdownEditor/editor/parser/remarkParse.js +158 -102
  203. package/dist/MarkdownEditor/editor/plugins/catchError.js +78 -17
  204. package/dist/MarkdownEditor/editor/plugins/elements.js +458 -342
  205. package/dist/MarkdownEditor/editor/plugins/handlePaste.js +752 -300
  206. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/arrow.js +215 -129
  207. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/backspace.js +325 -180
  208. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/enter.js +576 -418
  209. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/match.js +157 -47
  210. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/tab.js +331 -209
  211. package/dist/MarkdownEditor/editor/plugins/index.js +0 -1
  212. package/dist/MarkdownEditor/editor/plugins/insertParsedHtmlNodes.js +1245 -507
  213. package/dist/MarkdownEditor/editor/plugins/parseMarkdownToNodesAndInsert.js +36 -24
  214. package/dist/MarkdownEditor/editor/plugins/useHighlight.js +267 -116
  215. package/dist/MarkdownEditor/editor/plugins/useKeyboard.js +234 -160
  216. package/dist/MarkdownEditor/editor/plugins/useOnchange.js +253 -92
  217. package/dist/MarkdownEditor/editor/plugins/withMarkdown.js +728 -439
  218. package/dist/MarkdownEditor/editor/store.js +1819 -1389
  219. package/dist/MarkdownEditor/editor/style.js +551 -506
  220. package/dist/MarkdownEditor/editor/tagStyles.js +43 -43
  221. package/dist/MarkdownEditor/editor/tools/DragHandle.js +56 -54
  222. package/dist/MarkdownEditor/editor/tools/InsertAutocomplete.js +1049 -732
  223. package/dist/MarkdownEditor/editor/tools/InsertLink.js +232 -181
  224. package/dist/MarkdownEditor/editor/tools/Leading.js +566 -303
  225. package/dist/MarkdownEditor/editor/tools/ToolBar/BaseBar.js +415 -377
  226. package/dist/MarkdownEditor/editor/tools/ToolBar/FloatBar.js +162 -125
  227. package/dist/MarkdownEditor/editor/tools/ToolBar/ReadonlyBaseBar.js +480 -258
  228. package/dist/MarkdownEditor/editor/tools/ToolBar/ToolBar.js +44 -44
  229. package/dist/MarkdownEditor/editor/tools/ToolBar/components/ClearFormatButton.js +20 -35
  230. package/dist/MarkdownEditor/editor/tools/ToolBar/components/ColorPickerButton.js +69 -73
  231. package/dist/MarkdownEditor/editor/tools/ToolBar/components/FormatButton.js +13 -19
  232. package/dist/MarkdownEditor/editor/tools/ToolBar/components/FormattingTools.js +34 -41
  233. package/dist/MarkdownEditor/editor/tools/ToolBar/components/HeadingDropdown.js +53 -47
  234. package/dist/MarkdownEditor/editor/tools/ToolBar/components/LinkButton.js +11 -19
  235. package/dist/MarkdownEditor/editor/tools/ToolBar/components/ToolBarItem.js +23 -43
  236. package/dist/MarkdownEditor/editor/tools/ToolBar/components/UndoRedoButtons.js +14 -25
  237. package/dist/MarkdownEditor/editor/tools/ToolBar/config/toolsConfig.js +139 -102
  238. package/dist/MarkdownEditor/editor/tools/ToolBar/floatBarStyle.js +95 -65
  239. package/dist/MarkdownEditor/editor/tools/ToolBar/hooks/useToolBarLogic.js +252 -161
  240. package/dist/MarkdownEditor/editor/tools/ToolBar/index.js +14 -24
  241. package/dist/MarkdownEditor/editor/tools/ToolBar/toolBarStyle.js +95 -65
  242. package/dist/MarkdownEditor/editor/tools/insertAutocompleteStyle.js +82 -52
  243. package/dist/MarkdownEditor/editor/types/Table.js +1 -0
  244. package/dist/MarkdownEditor/editor/utils/InlineChromiumBugfix.js +11 -16
  245. package/dist/MarkdownEditor/editor/utils/ace.js +136 -40
  246. package/dist/MarkdownEditor/editor/utils/docx/docxDeserializer.js +29 -32
  247. package/dist/MarkdownEditor/editor/utils/docx/index.js +0 -1
  248. package/dist/MarkdownEditor/editor/utils/docx/module.js +193 -164
  249. package/dist/MarkdownEditor/editor/utils/docx/utils.js +113 -98
  250. package/dist/MarkdownEditor/editor/utils/dom.js +119 -90
  251. package/dist/MarkdownEditor/editor/utils/editorUtils.js +1369 -906
  252. package/dist/MarkdownEditor/editor/utils/htmlToMarkdown.js +196 -184
  253. package/dist/MarkdownEditor/editor/utils/index.js +354 -215
  254. package/dist/MarkdownEditor/editor/utils/isMarkdown.js +56 -44
  255. package/dist/MarkdownEditor/editor/utils/keyboard.js +1229 -664
  256. package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +294 -76
  257. package/dist/MarkdownEditor/editor/utils/media.js +274 -99
  258. package/dist/MarkdownEditor/editor/utils/path.js +22 -16
  259. package/dist/MarkdownEditor/editor/utils/performanceMonitor.js +370 -168
  260. package/dist/MarkdownEditor/editor/utils/useLocalState.js +96 -37
  261. package/dist/MarkdownEditor/el.js +1 -0
  262. package/dist/MarkdownEditor/hooks/editor.js +123 -41
  263. package/dist/MarkdownEditor/hooks/subscribe.js +18 -15
  264. package/dist/MarkdownEditor/index.js +118 -30
  265. package/dist/MarkdownEditor/plugin.js +2 -5
  266. package/dist/MarkdownEditor/style.js +96 -66
  267. package/dist/MarkdownEditor/types.js +1 -0
  268. package/dist/MarkdownEditor/utils/exportHtml.js +42 -83
  269. package/dist/MarkdownEditor/utils/native-table/index.js +0 -1
  270. package/dist/MarkdownEditor/utils/native-table/native-table-editor.js +337 -222
  271. package/dist/MarkdownEditor/utils/native-table/native-table-keyboard.js +201 -113
  272. package/dist/MarkdownInputField/AttachmentButton/AttachmentButtonPopover.d.ts +4 -0
  273. package/dist/MarkdownInputField/AttachmentButton/AttachmentButtonPopover.js +277 -82
  274. package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileIcon.js +62 -33
  275. package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileListItem.js +147 -125
  276. package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/index.js +174 -129
  277. package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/style.js +263 -237
  278. package/dist/MarkdownInputField/AttachmentButton/index.js +480 -205
  279. package/dist/MarkdownInputField/AttachmentButton/style.js +143 -114
  280. package/dist/MarkdownInputField/AttachmentButton/types.js +3 -0
  281. package/dist/MarkdownInputField/AttachmentButton/utils.d.ts +60 -0
  282. package/dist/MarkdownInputField/AttachmentButton/utils.js +365 -33
  283. package/dist/MarkdownInputField/BeforeToolContainer/BeforeToolContainer.js +438 -404
  284. package/dist/MarkdownInputField/Enlargement/index.js +7 -17
  285. package/dist/MarkdownInputField/FileMapView/FileMapViewItem.js +193 -216
  286. package/dist/MarkdownInputField/FileMapView/index.js +387 -174
  287. package/dist/MarkdownInputField/FileMapView/style.js +281 -259
  288. package/dist/MarkdownInputField/FilePaste/index.js +239 -65
  289. package/dist/MarkdownInputField/FileUploadManager/index.js +504 -170
  290. package/dist/MarkdownInputField/MarkdownInputField.js +819 -549
  291. package/dist/MarkdownInputField/QuickActions/index.js +304 -134
  292. package/dist/MarkdownInputField/RefinePromptButton/index.js +24 -33
  293. package/dist/MarkdownInputField/RefinePromptButton/style.js +99 -73
  294. package/dist/MarkdownInputField/SendActions/index.js +179 -197
  295. package/dist/MarkdownInputField/SendButton/index.js +150 -110
  296. package/dist/MarkdownInputField/SendButton/style.js +95 -64
  297. package/dist/MarkdownInputField/SkillModeBar/hooks/index.js +3 -5
  298. package/dist/MarkdownInputField/SkillModeBar/hooks/useSkillModeState.js +51 -26
  299. package/dist/MarkdownInputField/SkillModeBar/index.js +119 -106
  300. package/dist/MarkdownInputField/SkillModeBar/style.js +124 -98
  301. package/dist/MarkdownInputField/Suggestion/index.js +391 -154
  302. package/dist/MarkdownInputField/TopOperatingArea/index.js +37 -44
  303. package/dist/MarkdownInputField/TopOperatingArea/style.js +98 -81
  304. package/dist/MarkdownInputField/VoiceInput/index.js +210 -82
  305. package/dist/MarkdownInputField/VoiceInput/style.js +85 -59
  306. package/dist/MarkdownInputField/VoiceInputManager/index.js +321 -94
  307. package/dist/MarkdownInputField/style.js +296 -233
  308. package/dist/Plugins/chart/AreaChart/index.js +541 -393
  309. package/dist/Plugins/chart/AreaChart/style.js +114 -90
  310. package/dist/Plugins/chart/BarChart/index.d.ts +4 -0
  311. package/dist/Plugins/chart/BarChart/index.js +865 -697
  312. package/dist/Plugins/chart/BarChart/style.js +114 -90
  313. package/dist/Plugins/chart/ChartAttrToolBar/ChartAttrToolBarStyle.js +82 -52
  314. package/dist/Plugins/chart/ChartAttrToolBar/index.js +94 -65
  315. package/dist/Plugins/chart/ChartMark/Area.js +176 -150
  316. package/dist/Plugins/chart/ChartMark/Bar.js +181 -152
  317. package/dist/Plugins/chart/ChartMark/Column.js +181 -151
  318. package/dist/Plugins/chart/ChartMark/Container.js +116 -75
  319. package/dist/Plugins/chart/ChartMark/Line.js +179 -151
  320. package/dist/Plugins/chart/ChartMark/Pie.js +79 -63
  321. package/dist/Plugins/chart/ChartMark/index.js +6 -13
  322. package/dist/Plugins/chart/ChartMark/useChart.js +1 -0
  323. package/dist/Plugins/chart/ChartRender.js +981 -696
  324. package/dist/Plugins/chart/ChartStatistic/index.js +47 -62
  325. package/dist/Plugins/chart/ChartStatistic/style.js +142 -143
  326. package/dist/Plugins/chart/ChartStatistic/utils.js +37 -27
  327. package/dist/Plugins/chart/DonutChart/Legend.js +94 -124
  328. package/dist/Plugins/chart/DonutChart/constants.js +4 -11
  329. package/dist/Plugins/chart/DonutChart/hooks.js +183 -112
  330. package/dist/Plugins/chart/DonutChart/index.js +588 -516
  331. package/dist/Plugins/chart/DonutChart/plugins.js +47 -44
  332. package/dist/Plugins/chart/DonutChart/style.js +186 -175
  333. package/dist/Plugins/chart/DonutChart/types.js +1 -0
  334. package/dist/Plugins/chart/FunnelChart/index.js +844 -647
  335. package/dist/Plugins/chart/FunnelChart/style.js +97 -71
  336. package/dist/Plugins/chart/LineChart/index.js +516 -393
  337. package/dist/Plugins/chart/LineChart/style.js +114 -90
  338. package/dist/Plugins/chart/RadarChart/index.js +580 -582
  339. package/dist/Plugins/chart/RadarChart/style.js +122 -112
  340. package/dist/Plugins/chart/ScatterChart/index.js +633 -640
  341. package/dist/Plugins/chart/ScatterChart/style.js +108 -94
  342. package/dist/Plugins/chart/components/ChartContainer/ChartContainer.js +151 -80
  343. package/dist/Plugins/chart/components/ChartContainer/ChartErrorBoundary.js +160 -41
  344. package/dist/Plugins/chart/components/ChartContainer/ChartErrorBoundaryExample.js +80 -62
  345. package/dist/Plugins/chart/components/ChartContainer/index.js +2 -7
  346. package/dist/Plugins/chart/components/ChartContainer/style.js +121 -91
  347. package/dist/Plugins/chart/components/ChartFilter/ChartFilter.js +58 -90
  348. package/dist/Plugins/chart/components/ChartFilter/style.js +169 -154
  349. package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.js +54 -59
  350. package/dist/Plugins/chart/components/ChartToolBar/style.js +132 -117
  351. package/dist/Plugins/chart/components/icons/TimeIcon.js +20 -26
  352. package/dist/Plugins/chart/components/index.js +32 -34
  353. package/dist/Plugins/chart/const.js +34 -25
  354. package/dist/Plugins/chart/hooks/useChartStatistic.js +1 -0
  355. package/dist/Plugins/chart/index.js +436 -339
  356. package/dist/Plugins/chart/loadChartRuntime.js +209 -110
  357. package/dist/Plugins/chart/utils.js +311 -87
  358. package/dist/Plugins/code/CodeUI/Katex/Katex.js +112 -66
  359. package/dist/Plugins/code/components/AceEditor.js +334 -237
  360. package/dist/Plugins/code/components/AceEditorContainer.js +23 -32
  361. package/dist/Plugins/code/components/CodeContainer.js +41 -56
  362. package/dist/Plugins/code/components/CodeRenderer.js +202 -155
  363. package/dist/Plugins/code/components/CodeToolbar.js +137 -181
  364. package/dist/Plugins/code/components/HtmlPreview.js +19 -22
  365. package/dist/Plugins/code/components/LanguageSelector.js +162 -96
  366. package/dist/Plugins/code/components/LoadImage.js +145 -46
  367. package/dist/Plugins/code/components/ThinkBlock.js +38 -42
  368. package/dist/Plugins/code/components/index.js +13 -23
  369. package/dist/Plugins/code/hooks/index.js +7 -9
  370. package/dist/Plugins/code/hooks/useCodeEditorState.js +139 -62
  371. package/dist/Plugins/code/hooks/useRenderConditions.js +31 -23
  372. package/dist/Plugins/code/hooks/useToolbarConfig.js +44 -46
  373. package/dist/Plugins/code/index.js +141 -89
  374. package/dist/Plugins/code/langIconMap.js +400 -108
  375. package/dist/Plugins/code/langIcons/AbapIcon.js +90 -57
  376. package/dist/Plugins/code/langIcons/ActionscriptIcon.js +89 -56
  377. package/dist/Plugins/code/langIcons/AdaIcon.js +89 -52
  378. package/dist/Plugins/code/langIcons/ApacheIcon.js +205 -254
  379. package/dist/Plugins/code/langIcons/ApexIcon.js +108 -82
  380. package/dist/Plugins/code/langIcons/AplIcon.js +90 -54
  381. package/dist/Plugins/code/langIcons/ApplescriptIcon.js +89 -56
  382. package/dist/Plugins/code/langIcons/AstroIcon.js +91 -58
  383. package/dist/Plugins/code/langIcons/AwkIcon.js +98 -68
  384. package/dist/Plugins/code/langIcons/BallerinaIcon.js +92 -59
  385. package/dist/Plugins/code/langIcons/BatIcon.js +158 -229
  386. package/dist/Plugins/code/langIcons/BicepIcon.js +91 -58
  387. package/dist/Plugins/code/langIcons/BladeIcon.js +90 -58
  388. package/dist/Plugins/code/langIcons/CIcon.js +90 -55
  389. package/dist/Plugins/code/langIcons/CadenceIcon.js +89 -56
  390. package/dist/Plugins/code/langIcons/ClojureIcon.js +96 -75
  391. package/dist/Plugins/code/langIcons/CmakeIcon.js +93 -62
  392. package/dist/Plugins/code/langIcons/CobolIcon.js +99 -70
  393. package/dist/Plugins/code/langIcons/CodeqlIcon.js +96 -76
  394. package/dist/Plugins/code/langIcons/CoffeeIcon.js +89 -56
  395. package/dist/Plugins/code/langIcons/ConsoleIcon.js +89 -56
  396. package/dist/Plugins/code/langIcons/CppIcon.js +90 -55
  397. package/dist/Plugins/code/langIcons/CrystalIcon.js +90 -57
  398. package/dist/Plugins/code/langIcons/CsharpIcon.js +90 -59
  399. package/dist/Plugins/code/langIcons/CssIcon.js +89 -52
  400. package/dist/Plugins/code/langIcons/DIcon.js +90 -53
  401. package/dist/Plugins/code/langIcons/DartIcon.js +92 -71
  402. package/dist/Plugins/code/langIcons/DatabaseIcon.js +90 -57
  403. package/dist/Plugins/code/langIcons/DiffIcon.js +90 -57
  404. package/dist/Plugins/code/langIcons/DockerIcon.js +89 -56
  405. package/dist/Plugins/code/langIcons/DotenvIcon.js +94 -56
  406. package/dist/Plugins/code/langIcons/ElixirIcon.js +91 -58
  407. package/dist/Plugins/code/langIcons/ElmIcon.js +105 -58
  408. package/dist/Plugins/code/langIcons/ErbIcon.js +90 -54
  409. package/dist/Plugins/code/langIcons/ErlangIcon.js +89 -56
  410. package/dist/Plugins/code/langIcons/FsharpIcon.js +93 -62
  411. package/dist/Plugins/code/langIcons/GdscriptIcon.js +96 -88
  412. package/dist/Plugins/code/langIcons/GlslIcon.js +90 -58
  413. package/dist/Plugins/code/langIcons/GnuplotIcon.js +98 -77
  414. package/dist/Plugins/code/langIcons/GoIcon.js +114 -93
  415. package/dist/Plugins/code/langIcons/GraphqlIcon.js +106 -66
  416. package/dist/Plugins/code/langIcons/GroovyIcon.js +89 -56
  417. package/dist/Plugins/code/langIcons/HackIcon.js +97 -64
  418. package/dist/Plugins/code/langIcons/HamlIcon.js +89 -56
  419. package/dist/Plugins/code/langIcons/HandlebarsIcon.js +89 -56
  420. package/dist/Plugins/code/langIcons/HaskellIcon.js +93 -64
  421. package/dist/Plugins/code/langIcons/HclIcon.js +118 -93
  422. package/dist/Plugins/code/langIcons/HclLightIcon.js +118 -97
  423. package/dist/Plugins/code/langIcons/HjsonIcon.js +94 -62
  424. package/dist/Plugins/code/langIcons/HlslIcon.js +96 -76
  425. package/dist/Plugins/code/langIcons/HtmlIcon.js +89 -56
  426. package/dist/Plugins/code/langIcons/HttpIcon.js +89 -56
  427. package/dist/Plugins/code/langIcons/ImbaIcon.js +98 -65
  428. package/dist/Plugins/code/langIcons/IniIcon.js +90 -54
  429. package/dist/Plugins/code/langIcons/JavaIcon.js +89 -56
  430. package/dist/Plugins/code/langIcons/JavascriptIcon.js +89 -56
  431. package/dist/Plugins/code/langIcons/JinjaIcon.js +100 -68
  432. package/dist/Plugins/code/langIcons/Json5Icon.js +100 -82
  433. package/dist/Plugins/code/langIcons/JsonIcon.js +89 -56
  434. package/dist/Plugins/code/langIcons/JsonnetIcon.js +102 -86
  435. package/dist/Plugins/code/langIcons/JuliaIcon.js +105 -52
  436. package/dist/Plugins/code/langIcons/KotlinIcon.js +104 -74
  437. package/dist/Plugins/code/langIcons/KustoIcon.js +90 -57
  438. package/dist/Plugins/code/langIcons/LessIcon.js +90 -57
  439. package/dist/Plugins/code/langIcons/LiquidIcon.js +91 -58
  440. package/dist/Plugins/code/langIcons/LispIcon.js +89 -56
  441. package/dist/Plugins/code/langIcons/LuaIcon.js +93 -60
  442. package/dist/Plugins/code/langIcons/MakefileIcon.js +91 -58
  443. package/dist/Plugins/code/langIcons/MarkdownIcon.js +89 -56
  444. package/dist/Plugins/code/langIcons/MarkojsIcon.js +96 -73
  445. package/dist/Plugins/code/langIcons/MatlabIcon.js +93 -64
  446. package/dist/Plugins/code/langIcons/MdxIcon.js +90 -53
  447. package/dist/Plugins/code/langIcons/MermaidIcon.js +95 -64
  448. package/dist/Plugins/code/langIcons/MojoIcon.js +95 -62
  449. package/dist/Plugins/code/langIcons/NginxIcon.js +94 -61
  450. package/dist/Plugins/code/langIcons/NimIcon.js +91 -54
  451. package/dist/Plugins/code/langIcons/NixIcon.js +92 -56
  452. package/dist/Plugins/code/langIcons/ObjectiveCIcon.js +90 -59
  453. package/dist/Plugins/code/langIcons/ObjectiveCppIcon.js +90 -57
  454. package/dist/Plugins/code/langIcons/OcamlIcon.js +90 -61
  455. package/dist/Plugins/code/langIcons/PascalIcon.js +95 -55
  456. package/dist/Plugins/code/langIcons/Perl6Icon.js +299 -320
  457. package/dist/Plugins/code/langIcons/PerlIcon.js +89 -56
  458. package/dist/Plugins/code/langIcons/PhpIcon.js +89 -52
  459. package/dist/Plugins/code/langIcons/PostcssIcon.js +130 -113
  460. package/dist/Plugins/code/langIcons/PowershellIcon.js +91 -58
  461. package/dist/Plugins/code/langIcons/PrismaIcon.js +97 -68
  462. package/dist/Plugins/code/langIcons/PrologIcon.js +91 -58
  463. package/dist/Plugins/code/langIcons/ProtoIcon.js +94 -68
  464. package/dist/Plugins/code/langIcons/PugIcon.js +177 -145
  465. package/dist/Plugins/code/langIcons/PuppetIcon.js +96 -52
  466. package/dist/Plugins/code/langIcons/PurescriptIcon.js +93 -61
  467. package/dist/Plugins/code/langIcons/PythonIcon.js +90 -61
  468. package/dist/Plugins/code/langIcons/RIcon.js +89 -52
  469. package/dist/Plugins/code/langIcons/RazorIcon.js +90 -57
  470. package/dist/Plugins/code/langIcons/ReactIcon.js +89 -56
  471. package/dist/Plugins/code/langIcons/ReactTsIcon.js +90 -57
  472. package/dist/Plugins/code/langIcons/RubyIcon.js +91 -58
  473. package/dist/Plugins/code/langIcons/RustIcon.js +89 -56
  474. package/dist/Plugins/code/langIcons/SasIcon.js +89 -52
  475. package/dist/Plugins/code/langIcons/SassIcon.js +90 -57
  476. package/dist/Plugins/code/langIcons/ScalaIcon.js +96 -53
  477. package/dist/Plugins/code/langIcons/SchemeIcon.js +91 -58
  478. package/dist/Plugins/code/langIcons/ShaderlabIcon.js +89 -56
  479. package/dist/Plugins/code/langIcons/SolidityIcon.js +94 -52
  480. package/dist/Plugins/code/langIcons/SparqlIcon.js +94 -64
  481. package/dist/Plugins/code/langIcons/StataIcon.js +126 -108
  482. package/dist/Plugins/code/langIcons/StylusIcon.js +92 -59
  483. package/dist/Plugins/code/langIcons/SvelteIcon.js +91 -58
  484. package/dist/Plugins/code/langIcons/SwiftIcon.js +90 -57
  485. package/dist/Plugins/code/langIcons/SystemverilogIcon.js +115 -102
  486. package/dist/Plugins/code/langIcons/TclIcon.js +89 -52
  487. package/dist/Plugins/code/langIcons/TexIcon.js +99 -65
  488. package/dist/Plugins/code/langIcons/TomlIcon.js +94 -70
  489. package/dist/Plugins/code/langIcons/TwigIcon.js +89 -56
  490. package/dist/Plugins/code/langIcons/TypescriptIcon.js +93 -60
  491. package/dist/Plugins/code/langIcons/VerilogIcon.js +89 -56
  492. package/dist/Plugins/code/langIcons/VhdlIcon.js +94 -64
  493. package/dist/Plugins/code/langIcons/VimIcon.js +278 -420
  494. package/dist/Plugins/code/langIcons/VueIcon.js +92 -59
  495. package/dist/Plugins/code/langIcons/WebassemblyIcon.js +103 -76
  496. package/dist/Plugins/code/langIcons/WenyanIcon.js +104 -100
  497. package/dist/Plugins/code/langIcons/WgslIcon.js +93 -77
  498. package/dist/Plugins/code/langIcons/WolframlanguageIcon.js +100 -71
  499. package/dist/Plugins/code/langIcons/XmlIcon.js +89 -52
  500. package/dist/Plugins/code/langIcons/XslIcon.js +94 -66
  501. package/dist/Plugins/code/langIcons/YamlIcon.js +89 -56
  502. package/dist/Plugins/code/langIcons/ZigIcon.js +106 -81
  503. package/dist/Plugins/code/langIcons/index.js +128 -259
  504. package/dist/Plugins/code/utils/index.js +5 -5
  505. package/dist/Plugins/code/utils/langOptions.js +86 -11
  506. package/dist/Plugins/defaultPlugins.js +9 -13
  507. package/dist/Plugins/formatter/index.js +205 -105
  508. package/dist/Plugins/index.js +6 -2
  509. package/dist/Plugins/katex/InlineKatex.js +196 -107
  510. package/dist/Plugins/katex/Katex.js +139 -65
  511. package/dist/Plugins/katex/index.js +163 -103
  512. package/dist/Plugins/mermaid/Mermaid.js +472 -197
  513. package/dist/Plugins/mermaid/index.js +237 -142
  514. package/dist/Quote/index.js +112 -73
  515. package/dist/Quote/style.js +176 -160
  516. package/dist/Schema/SchemaEditor/AceEditorWrapper.js +163 -119
  517. package/dist/Schema/SchemaEditor/index.js +385 -275
  518. package/dist/Schema/SchemaEditor/style.js +261 -269
  519. package/dist/Schema/SchemaForm/index.js +443 -268
  520. package/dist/Schema/SchemaForm/types.js +1 -0
  521. package/dist/Schema/SchemaRenderer/index.js +973 -588
  522. package/dist/Schema/SchemaRenderer/templateEngine.js +106 -26
  523. package/dist/Schema/index.js +7 -11
  524. package/dist/Schema/types.js +1 -0
  525. package/dist/Schema/validator.js +74 -36
  526. package/dist/TaskList/index.js +197 -142
  527. package/dist/TaskList/style.js +143 -122
  528. package/dist/ThoughtChainList/CostMillis.js +88 -54
  529. package/dist/ThoughtChainList/DeepThink.js +187 -152
  530. package/dist/ThoughtChainList/DotAni/index.js +29 -14
  531. package/dist/ThoughtChainList/DotAni/style.js +82 -50
  532. package/dist/ThoughtChainList/FlipText/index.js +74 -30
  533. package/dist/ThoughtChainList/MarkdownEditor.js +126 -72
  534. package/dist/ThoughtChainList/RagRetrievalInfo.js +113 -145
  535. package/dist/ThoughtChainList/TableSql.js +413 -459
  536. package/dist/ThoughtChainList/ThoughtChainListItem.js +388 -222
  537. package/dist/ThoughtChainList/TitleInfo.js +189 -185
  538. package/dist/ThoughtChainList/ToolCall.js +429 -463
  539. package/dist/ThoughtChainList/WebSearch.js +192 -162
  540. package/dist/ThoughtChainList/index.js +449 -410
  541. package/dist/ThoughtChainList/style.js +253 -232
  542. package/dist/ThoughtChainList/types.js +1 -0
  543. package/dist/ToolUseBar/ToolUseBarItem.js +183 -139
  544. package/dist/ToolUseBar/ToolUseBarItemComponents.js +345 -276
  545. package/dist/ToolUseBar/ToolUseBarThink.js +335 -396
  546. package/dist/ToolUseBar/index.js +226 -113
  547. package/dist/ToolUseBar/style.js +334 -308
  548. package/dist/ToolUseBar/thinkStyle.js +350 -328
  549. package/dist/Types/common.js +1 -0
  550. package/dist/Types/index.js +4 -2
  551. package/dist/Types/message.js +1 -0
  552. package/dist/Utils/easings.js +9 -12
  553. package/dist/Utils/formatTime.js +41 -17
  554. package/dist/Utils/getScroll.js +41 -41
  555. package/dist/Utils/language.js +355 -150
  556. package/dist/Utils/proxySandbox/ProxySandbox.js +1637 -1076
  557. package/dist/Utils/proxySandbox/SecurityContextManager.js +607 -343
  558. package/dist/Utils/proxySandbox/index.js +554 -267
  559. package/dist/Utils/proxySandbox/types.js +187 -52
  560. package/dist/Utils/scrollTo.js +48 -56
  561. package/dist/Utils/throttleByAnimationFrame.js +46 -20
  562. package/dist/WelcomeMessage/index.js +106 -58
  563. package/dist/WelcomeMessage/style.js +80 -55
  564. package/dist/Workspace/Browser/index.js +102 -40
  565. package/dist/Workspace/Browser/style.js +62 -33
  566. package/dist/Workspace/File/DataSourceStrategy.js +419 -217
  567. package/dist/Workspace/File/FileComponent.js +1004 -791
  568. package/dist/Workspace/File/FileTypeProcessor.js +337 -184
  569. package/dist/Workspace/File/PreviewComponent.js +472 -532
  570. package/dist/Workspace/File/index.js +3 -10
  571. package/dist/Workspace/File/style.js +397 -424
  572. package/dist/Workspace/File/utils.js +160 -106
  573. package/dist/Workspace/HtmlPreview/index.js +238 -137
  574. package/dist/Workspace/HtmlPreview/style.js +99 -77
  575. package/dist/Workspace/RealtimeFollow/index.js +411 -413
  576. package/dist/Workspace/RealtimeFollow/style.js +299 -303
  577. package/dist/Workspace/Task/index.js +53 -35
  578. package/dist/Workspace/Task/style.js +99 -73
  579. package/dist/Workspace/index.js +332 -254
  580. package/dist/Workspace/style.js +165 -146
  581. package/dist/Workspace/types.js +471 -252
  582. package/dist/Workspace/utils/codeLanguageUtils.js +148 -129
  583. package/dist/Workspace/utils.js +28 -20
  584. package/dist/index.js +27 -17
  585. package/package.json +3 -2
@@ -1,675 +1,872 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _array_without_holes(arr) {
10
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
11
+ }
12
+ function _define_property(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else {
21
+ obj[key] = value;
16
22
  }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
23
+ return obj;
24
+ }
25
+ function _iterable_to_array(iter) {
26
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
27
+ }
28
+ function _iterable_to_array_limit(arr, i) {
29
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
30
+ if (_i == null) return;
31
+ var _arr = [];
32
+ var _n = true;
33
+ var _d = false;
34
+ var _s, _e;
35
+ try {
36
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
37
+ _arr.push(_s.value);
38
+ if (i && _arr.length === i) break;
39
+ }
40
+ } catch (err) {
41
+ _d = true;
42
+ _e = err;
43
+ } finally{
44
+ try {
45
+ if (!_n && _i["return"] != null) _i["return"]();
46
+ } finally{
47
+ if (_d) throw _e;
48
+ }
29
49
  }
30
- return target;
31
- };
32
-
33
- // src/Plugins/chart/FunnelChart/index.tsx
50
+ return _arr;
51
+ }
52
+ function _non_iterable_rest() {
53
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
54
+ }
55
+ function _non_iterable_spread() {
56
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
+ }
58
+ function _object_spread(target) {
59
+ for(var i = 1; i < arguments.length; i++){
60
+ var source = arguments[i] != null ? arguments[i] : {};
61
+ var ownKeys = Object.keys(source);
62
+ if (typeof Object.getOwnPropertySymbols === "function") {
63
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
65
+ }));
66
+ }
67
+ ownKeys.forEach(function(key) {
68
+ _define_property(target, key, source[key]);
69
+ });
70
+ }
71
+ return target;
72
+ }
73
+ function ownKeys(object, enumerableOnly) {
74
+ var keys = Object.keys(object);
75
+ if (Object.getOwnPropertySymbols) {
76
+ var symbols = Object.getOwnPropertySymbols(object);
77
+ if (enumerableOnly) {
78
+ symbols = symbols.filter(function(sym) {
79
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
80
+ });
81
+ }
82
+ keys.push.apply(keys, symbols);
83
+ }
84
+ return keys;
85
+ }
86
+ function _object_spread_props(target, source) {
87
+ source = source != null ? source : {};
88
+ if (Object.getOwnPropertyDescriptors) {
89
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
90
+ } else {
91
+ ownKeys(Object(source)).forEach(function(key) {
92
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
93
+ });
94
+ }
95
+ return target;
96
+ }
97
+ function _object_without_properties(source, excluded) {
98
+ if (source == null) return {};
99
+ var target = _object_without_properties_loose(source, excluded);
100
+ var key, i;
101
+ if (Object.getOwnPropertySymbols) {
102
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
103
+ for(i = 0; i < sourceSymbolKeys.length; i++){
104
+ key = sourceSymbolKeys[i];
105
+ if (excluded.indexOf(key) >= 0) continue;
106
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
107
+ target[key] = source[key];
108
+ }
109
+ }
110
+ return target;
111
+ }
112
+ function _object_without_properties_loose(source, excluded) {
113
+ if (source == null) return {};
114
+ var target = {};
115
+ var sourceKeys = Object.keys(source);
116
+ var key, i;
117
+ for(i = 0; i < sourceKeys.length; i++){
118
+ key = sourceKeys[i];
119
+ if (excluded.indexOf(key) >= 0) continue;
120
+ target[key] = source[key];
121
+ }
122
+ return target;
123
+ }
124
+ function _sliced_to_array(arr, i) {
125
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
126
+ }
127
+ function _to_consumable_array(arr) {
128
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
129
+ }
130
+ function _unsupported_iterable_to_array(o, minLen) {
131
+ if (!o) return;
132
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
133
+ var n = Object.prototype.toString.call(o).slice(8, -1);
134
+ if (n === "Object" && o.constructor) n = o.constructor.name;
135
+ if (n === "Map" || n === "Set") return Array.from(n);
136
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
137
+ }
34
138
  import { ConfigProvider } from "antd";
35
- import {
36
- BarElement,
37
- CategoryScale,
38
- Chart as ChartJS,
39
- Legend,
40
- LinearScale,
41
- Tooltip
42
- } from "chart.js";
139
+ import { BarElement, CategoryScale, Chart as ChartJS, Legend, LinearScale, Tooltip } from "chart.js";
43
140
  import classNames from "classnames";
44
141
  import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
45
142
  import { Bar } from "react-chartjs-2";
46
143
  import ChartStatistic from "../ChartStatistic";
47
- import {
48
- ChartContainer,
49
- ChartFilter,
50
- ChartToolBar,
51
- downloadChart
52
- } from "../components";
144
+ import { ChartContainer, ChartFilter, ChartToolBar, downloadChart } from "../components";
53
145
  import { defaultColorList } from "../const";
54
146
  import { findDataPointByXValue, isXValueEqual, toNumber } from "../utils";
55
147
  import { useStyle } from "./style";
56
148
  var funnelChartComponentsRegistered = false;
57
- var FunnelChart = (_a) => {
58
- var _b = _a, {
59
- title,
60
- data,
61
- color,
62
- width = 600,
63
- height = 400,
64
- className,
65
- dataTime,
66
- theme = "light",
67
- showLegend = true,
68
- legendPosition = "bottom",
69
- legendAlign = "start",
70
- showPercent = true,
71
- toolbarExtra,
72
- renderFilterInToolbar = false,
73
- bottomLayerMinWidth = 0,
74
- typeNames,
75
- statistic: statisticConfig
76
- } = _b, props = __objRest(_b, [
77
- "title",
78
- "data",
79
- "color",
80
- "width",
81
- "height",
82
- "className",
83
- "dataTime",
84
- "theme",
85
- "showLegend",
86
- "legendPosition",
87
- "legendAlign",
88
- "showPercent",
89
- "toolbarExtra",
90
- "renderFilterInToolbar",
91
- "bottomLayerMinWidth",
92
- "typeNames",
93
- "statistic"
94
- ]);
95
- useMemo(() => {
96
- if (funnelChartComponentsRegistered) {
97
- return void 0;
98
- }
99
- if (typeof window === "undefined") {
100
- return void 0;
101
- }
102
- ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend);
103
- funnelChartComponentsRegistered = true;
104
- return void 0;
105
- }, []);
106
- const safeData = Array.isArray(data) ? data : [];
107
- const statistics = useMemo(() => {
108
- if (!statisticConfig)
109
- return null;
110
- return Array.isArray(statisticConfig) ? statisticConfig : [statisticConfig];
111
- }, [statisticConfig]);
112
- const [windowWidth, setWindowWidth] = useState(
113
- typeof window !== "undefined" ? window.innerWidth : 768
114
- );
115
- const isMobile = windowWidth <= 768;
116
- useEffect(() => {
117
- const handleResize = () => setWindowWidth(window.innerWidth);
118
- if (typeof window !== "undefined") {
119
- window.addEventListener("resize", handleResize);
120
- return () => window.removeEventListener("resize", handleResize);
121
- }
122
- }, []);
123
- const context = useContext(ConfigProvider.ConfigContext);
124
- const baseClassName = context == null ? void 0 : context.getPrefixCls("funnel-chart-container");
125
- const { hashId, wrapSSR } = useStyle(baseClassName);
126
- const chartRef = useRef(null);
127
- const [showTrapezoid, setShowTrapezoid] = useState(true);
128
- const [pluginToggleKey, setPluginToggleKey] = useState(0);
129
- const categories = useMemo(() => {
130
- return [...new Set(safeData.map((d) => d.category))];
131
- }, [safeData]);
132
- const [selectedFilter, setSelectedFilter] = useState(
133
- categories.find(Boolean) || ""
134
- );
135
- const [selectedFilterLabel, setSelectedFilterLabel] = useState(void 0);
136
- const filterLabels = useMemo(() => {
137
- const labels = safeData.filter((d) => !selectedFilter || d.category === selectedFilter).map((d) => d.filterLabel).filter((v) => v !== void 0);
138
- return labels.length > 0 ? [...new Set(labels)] : void 0;
139
- }, [safeData, selectedFilter]);
140
- useEffect(() => {
141
- const first = filterLabels && filterLabels.length > 0 ? filterLabels[0] : void 0;
142
- if (!filterLabels || filterLabels.length === 0) {
143
- if (selectedFilterLabel !== void 0)
144
- setSelectedFilterLabel(void 0);
145
- return;
146
- }
147
- if (!selectedFilterLabel || !filterLabels.includes(selectedFilterLabel)) {
148
- setSelectedFilterLabel(first);
149
- }
150
- }, [filterLabels]);
151
- const filteredData = useMemo(() => {
152
- const base = selectedFilter ? safeData.filter((d) => d.category === selectedFilter) : safeData;
153
- const withFilterLabel = !filterLabels || !selectedFilterLabel ? base : base.filter((d) => d.filterLabel === selectedFilterLabel);
154
- return withFilterLabel.filter((d) => d.x !== null && d.x !== void 0);
155
- }, [safeData, selectedFilter, filterLabels, selectedFilterLabel]);
156
- const stages = useMemo(() => {
157
- const unique = [
158
- ...new Set(
159
- filteredData.map((d) => d.x).filter((x) => x !== null && x !== void 0)
160
- )
161
- ];
162
- const values = unique.map((x) => {
163
- const dp = findDataPointByXValue(filteredData, x);
164
- const n = toNumber(dp == null ? void 0 : dp.y, 0);
165
- return { x, n };
166
- });
167
- values.sort((a, b) => b.n - a.n);
168
- return values.map((v) => v.x);
169
- }, [filteredData]);
170
- const BAR_THICKNESS = 30;
171
- const ROW_GAP = 24;
172
- const PADDING_Y = isMobile ? 48 : 64;
173
- const chartHeight = useMemo(() => {
174
- const rows = Math.max(1, stages.length);
175
- return rows * (BAR_THICKNESS + ROW_GAP) + PADDING_Y;
176
- }, [stages.length, PADDING_Y]);
177
- const finalHeight = useMemo(() => {
178
- if (typeof height === "number") {
179
- return height;
180
- } else if (typeof height === "string" && height.includes("px")) {
181
- return parseInt(height, 10) || chartHeight;
182
- }
183
- return chartHeight;
184
- }, [height, chartHeight]);
185
- const originalValues = useMemo(() => {
186
- return stages.map((x) => {
187
- const dp = findDataPointByXValue(filteredData, x);
188
- return toNumber(dp == null ? void 0 : dp.y, 0);
189
- });
190
- }, [filteredData, stages]);
191
- const processedData = useMemo(() => {
192
- const baseColor = color || defaultColorList[0];
193
- const labels = stages.map((x) => x.toString());
194
- const values = stages.map((x) => {
195
- const dp = findDataPointByXValue(filteredData, x);
196
- const n = toNumber(dp == null ? void 0 : dp.y, 0);
197
- return n;
198
- });
199
- const typeName = (typeNames == null ? void 0 : typeNames.name) || "转化";
200
- const adjustedValues = (() => {
201
- if (bottomLayerMinWidth <= 0 || bottomLayerMinWidth > 1 || values.length === 0) {
202
- return values;
203
- }
204
- const maxValue = Math.max(...values);
205
- const minValue = Math.min(...values);
206
- if (minValue >= maxValue * bottomLayerMinWidth) {
207
- return values;
208
- }
209
- const minWidth = bottomLayerMinWidth * maxValue;
210
- const range = maxValue - minValue;
211
- return values.map((v) => {
212
- if (range === 0)
213
- return maxValue;
214
- const normalized = (v - minValue) / range;
215
- return minWidth + normalized * (maxValue - minWidth);
216
- });
217
- })();
218
- const datasetData = adjustedValues.map(
219
- (v) => [-v / 2, v / 2]
220
- );
221
- const hexToRgb = (hex) => {
222
- const s = hex.replace("#", "");
223
- const bigint = parseInt(s, 16);
224
- return {
225
- r: bigint >> 16 & 255,
226
- g: bigint >> 8 & 255,
227
- b: bigint & 255
228
- };
229
- };
230
- const rgbToHex = (r, g, b) => `#${[r, g, b].map(
231
- (v) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, "0")
232
- ).join("")}`;
233
- const lighten = (hex, t) => {
234
- const { r, g, b } = hexToRgb(hex);
235
- const lr = r + (255 - r) * t;
236
- const lg = g + (255 - g) * t;
237
- const lb = b + (255 - b) * t;
238
- return rgbToHex(lr, lg, lb);
239
- };
240
- const count = Math.max(1, stages.length - 1);
241
- const colorList = stages.map((_, i) => {
242
- const t = i / count * 0.6;
243
- return lighten(baseColor, t);
244
- });
245
- return {
246
- labels,
247
- datasets: [
248
- {
249
- label: typeName,
250
- data: datasetData,
251
- backgroundColor: colorList,
252
- borderColor: colorList,
253
- borderWidth: 0,
254
- borderRadius: 0,
255
- borderSkipped: false,
256
- barThickness: BAR_THICKNESS,
257
- categoryPercentage: 1,
258
- barPercentage: 1
149
+ var FunnelChart = function(_param) {
150
+ var title = _param.title, data = _param.data, color = _param.color, _param_width = _param.width, width = _param_width === void 0 ? 600 : _param_width, _param_height = _param.height, height = _param_height === void 0 ? 400 : _param_height, className = _param.className, dataTime = _param.dataTime, _param_theme = _param.theme, theme = _param_theme === void 0 ? 'light' : _param_theme, _param_showLegend = _param.showLegend, showLegend = _param_showLegend === void 0 ? true : _param_showLegend, _param_legendPosition = _param.legendPosition, legendPosition = _param_legendPosition === void 0 ? 'bottom' : _param_legendPosition, _param_legendAlign = _param.legendAlign, legendAlign = _param_legendAlign === void 0 ? 'start' : _param_legendAlign, _param_showPercent = _param.showPercent, showPercent = _param_showPercent === void 0 ? true : _param_showPercent, toolbarExtra = _param.toolbarExtra, _param_renderFilterInToolbar = _param.renderFilterInToolbar, renderFilterInToolbar = _param_renderFilterInToolbar === void 0 ? false : _param_renderFilterInToolbar, _param_bottomLayerMinWidth = _param.bottomLayerMinWidth, bottomLayerMinWidth = _param_bottomLayerMinWidth === void 0 ? 0 : _param_bottomLayerMinWidth, typeNames = _param.typeNames, statisticConfig = _param.statistic, props = _object_without_properties(_param, [
151
+ "title",
152
+ "data",
153
+ "color",
154
+ "width",
155
+ "height",
156
+ "className",
157
+ "dataTime",
158
+ "theme",
159
+ "showLegend",
160
+ "legendPosition",
161
+ "legendAlign",
162
+ "showPercent",
163
+ "toolbarExtra",
164
+ "renderFilterInToolbar",
165
+ "bottomLayerMinWidth",
166
+ "typeNames",
167
+ "statistic"
168
+ ]);
169
+ useMemo(function() {
170
+ if (funnelChartComponentsRegistered) {
171
+ return undefined;
259
172
  }
260
- ]
261
- };
262
- }, [filteredData, stages, bottomLayerMinWidth, color, typeNames]);
263
- const ratioDisplay = useMemo(() => {
264
- const formatRaw = (v) => {
265
- if (v === null || v === void 0)
266
- return void 0;
267
- if (typeof v === "string") {
268
- const s = v.trim();
269
- if (!s)
270
- return void 0;
271
- return s.endsWith("%") ? s : `${s}%`;
272
- }
273
- if (typeof v === "number" && Number.isFinite(v)) {
274
- return `${String(v)}%`;
275
- }
276
- return void 0;
277
- };
278
- const anyNonTopProvided = stages.some((_, i) => {
279
- if (i === 0)
280
- return false;
281
- const prevStage = stages[i - 1];
282
- const dp = (filteredData || []).find(
283
- (d) => isXValueEqual(d.x, prevStage)
284
- );
285
- const v = dp == null ? void 0 : dp.ratio;
286
- if (v === null || v === void 0)
287
- return false;
288
- if (typeof v === "string")
289
- return v.trim() !== "";
290
- return true;
291
- });
292
- return stages.map((_, i) => {
293
- if (i === 0)
294
- return anyNonTopProvided ? "100%" : void 0;
295
- const prevStage = stages[i - 1];
296
- const dp = (filteredData || []).find(
297
- (d) => isXValueEqual(d.x, prevStage)
298
- );
299
- return formatRaw(dp == null ? void 0 : dp.ratio);
300
- });
301
- }, [filteredData, stages]);
302
- const ratioProvided = useMemo(() => {
303
- return stages.map((_, i) => {
304
- if (i === 0)
305
- return false;
306
- const prevStage = stages[i - 1];
307
- const dp = (filteredData || []).find(
308
- (d) => isXValueEqual(d.x, prevStage)
309
- );
310
- const v = dp == null ? void 0 : dp.ratio;
311
- if (v === null || v === void 0)
312
- return false;
313
- if (typeof v === "string")
314
- return v.trim() !== "";
315
- return true;
316
- });
317
- }, [filteredData, stages]);
318
- const filterOptions = useMemo(
319
- () => categories.map((c) => ({
320
- label: c || "默认",
321
- value: c || "默认"
322
- })),
323
- [categories]
324
- );
325
- const customOptions = useMemo(() => {
326
- return filterLabels == null ? void 0 : filterLabels.map((l) => ({ key: l, label: l }));
327
- }, [filterLabels]);
328
- const isLight = theme === "light";
329
- const axisTextColor = isLight ? "rgba(0, 25, 61, 0.3255)" : "rgba(255, 255, 255, 0.8)";
330
- const options = {
331
- responsive: true,
332
- maintainAspectRatio: false,
333
- indexAxis: "y",
334
- layout: {
335
- padding: {
336
- left: 8,
337
- right: isMobile ? 72 : 96,
338
- top: 8,
339
- bottom: 8
340
- }
341
- },
342
- parsing: {
343
- // 允许使用 [start, end] 浮动条
344
- xAxisKey: void 0,
345
- yAxisKey: void 0
346
- },
347
- plugins: {
348
- legend: {
349
- display: showLegend,
350
- position: legendPosition,
351
- align: legendAlign,
352
- labels: {
353
- color: axisTextColor,
354
- font: { size: isMobile ? 10 : 12, weight: "normal" },
355
- padding: isMobile ? 10 : 12,
356
- usePointStyle: true,
357
- pointStyle: "rectRounded",
358
- generateLabels: (chart) => {
359
- const base = (ChartJS.defaults.plugins.legend.labels.generateLabels(chart) || []).map((it) => __spreadProps(__spreadValues({}, it), {
360
- pointStyle: "rectRounded"
361
- }));
362
- const anyNonTopProvided = stages.some((_, i) => {
363
- if (i === 0)
364
- return false;
365
- const prevStage = stages[i - 1];
366
- const dp = (filteredData || []).find(
367
- (d) => isXValueEqual(d.x, prevStage)
368
- );
369
- const v = dp == null ? void 0 : dp.ratio;
370
- if (v === null || v === void 0)
371
- return false;
372
- if (typeof v === "string")
373
- return v.trim() !== "";
374
- return true;
375
- });
376
- if (!anyNonTopProvided)
377
- return base;
378
- return [
379
- ...base,
380
- {
381
- text: (typeNames == null ? void 0 : typeNames.rate) || "转化率",
382
- fillStyle: "#F1F2F4",
383
- strokeStyle: "#F1F2F4",
384
- lineWidth: 0,
385
- hidden: !showTrapezoid,
386
- datasetIndex: chart.data.datasets.length,
387
- pointStyle: "rectRounded"
388
- }
389
- ];
390
- }
391
- },
392
- onClick: (e, legendItem, legend) => {
393
- if (legendItem.text === ((typeNames == null ? void 0 : typeNames.rate) || "转化率")) {
394
- setShowTrapezoid((v) => !v);
395
- setPluginToggleKey((k) => k + 1);
173
+ if (typeof window === 'undefined') {
174
+ return undefined;
175
+ }
176
+ ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend);
177
+ funnelChartComponentsRegistered = true;
178
+ return undefined;
179
+ }, []);
180
+ var safeData = Array.isArray(data) ? data : [];
181
+ // 处理 ChartStatistic 组件配置
182
+ var statistics = useMemo(function() {
183
+ if (!statisticConfig) return null;
184
+ return Array.isArray(statisticConfig) ? statisticConfig : [
185
+ statisticConfig
186
+ ];
187
+ }, [
188
+ statisticConfig
189
+ ]);
190
+ // 响应式尺寸
191
+ var _useState = _sliced_to_array(useState(typeof window !== 'undefined' ? window.innerWidth : 768), 2), windowWidth = _useState[0], setWindowWidth = _useState[1];
192
+ var isMobile = windowWidth <= 768;
193
+ useEffect(function() {
194
+ var handleResize = function() {
195
+ return setWindowWidth(window.innerWidth);
196
+ };
197
+ if (typeof window !== 'undefined') {
198
+ window.addEventListener('resize', handleResize);
199
+ return function() {
200
+ return window.removeEventListener('resize', handleResize);
201
+ };
202
+ }
203
+ }, []);
204
+ // 样式注册
205
+ var context = useContext(ConfigProvider.ConfigContext);
206
+ var baseClassName = context === null || context === void 0 ? void 0 : context.getPrefixCls('funnel-chart-container');
207
+ var _useStyle = useStyle(baseClassName), hashId = _useStyle.hashId, wrapSSR = _useStyle.wrapSSR;
208
+ var chartRef = useRef(null);
209
+ var _useState1 = _sliced_to_array(useState(true), 2), showTrapezoid = _useState1[0], setShowTrapezoid = _useState1[1];
210
+ var _useState2 = _sliced_to_array(useState(0), 2), pluginToggleKey = _useState2[0], setPluginToggleKey = _useState2[1];
211
+ // 类别筛选(外层)
212
+ var categories = useMemo(function() {
213
+ return _to_consumable_array(new Set(safeData.map(function(d) {
214
+ return d.category;
215
+ })));
216
+ }, [
217
+ safeData
218
+ ]);
219
+ // 状态
220
+ var _useState3 = _sliced_to_array(useState(categories.find(Boolean) || ''), 2), selectedFilter = _useState3[0], setSelectedFilter = _useState3[1];
221
+ var _useState4 = _sliced_to_array(useState(undefined), 2), selectedFilterLabel = _useState4[0], setSelectedFilterLabel = _useState4[1];
222
+ // 二级筛选(可选)- 仅基于当前选中 category 的可用标签
223
+ var filterLabels = useMemo(function() {
224
+ var labels = safeData.filter(function(d) {
225
+ return !selectedFilter || d.category === selectedFilter;
226
+ }).map(function(d) {
227
+ return d.filterLabel;
228
+ }).filter(function(v) {
229
+ return v !== undefined;
230
+ });
231
+ return labels.length > 0 ? _to_consumable_array(new Set(labels)) : undefined;
232
+ }, [
233
+ safeData,
234
+ selectedFilter
235
+ ]);
236
+ // 当切换 category 时,如当前二级筛选不在可选列表中,则重置为该类目第一项或清空
237
+ useEffect(function() {
238
+ var first = filterLabels && filterLabels.length > 0 ? filterLabels[0] : undefined;
239
+ if (!filterLabels || filterLabels.length === 0) {
240
+ if (selectedFilterLabel !== undefined) setSelectedFilterLabel(undefined);
396
241
  return;
397
- }
398
- const defaultClick = ChartJS.defaults.plugins.legend.onClick;
399
- if (typeof defaultClick === "function")
400
- defaultClick.call(legend, e, legendItem, legend);
401
242
  }
402
- },
403
- tooltip: {
404
- backgroundColor: isLight ? "rgba(255,255,255,0.95)" : "rgba(0,0,0,0.85)",
405
- titleColor: isLight ? "#333" : "#fff",
406
- bodyColor: isLight ? "#333" : "#fff",
407
- borderColor: isLight ? "rgba(0,0,0,0.12)" : "rgba(255,255,255,0.2)",
408
- borderWidth: 1,
409
- cornerRadius: isMobile ? 6 : 8,
410
- padding: 8,
411
- displayColors: false,
412
- callbacks: {
413
- title: (items) => {
414
- const it = items == null ? void 0 : items[0];
415
- return (it == null ? void 0 : it.label) ? String(it.label) : "";
416
- },
417
- label: (ctx) => {
418
- var _a2, _b2;
419
- const idx = (_a2 = ctx.dataIndex) != null ? _a2 : 0;
420
- const originalValue = (_b2 = originalValues == null ? void 0 : originalValues[idx]) != null ? _b2 : 0;
421
- const percentStr = ratioDisplay == null ? void 0 : ratioDisplay[idx];
422
- if (showPercent === false || !percentStr) {
423
- return `${originalValue}`;
424
- }
425
- return `${originalValue}(${percentStr})`;
426
- }
243
+ if (!selectedFilterLabel || !filterLabels.includes(selectedFilterLabel)) {
244
+ setSelectedFilterLabel(first);
427
245
  }
428
- }
429
- },
430
- scales: {
431
- y: {
432
- grid: { display: false },
433
- ticks: { display: false },
434
- title: { display: false },
435
- border: { display: false },
436
- afterFit: (scale) => {
437
- const rows = Math.max(1, stages.length);
438
- const per = BAR_THICKNESS + ROW_GAP;
439
- const total = rows * per;
440
- scale.height = total;
246
+ }, [
247
+ filterLabels
248
+ ]);
249
+ // 数据筛选
250
+ var filteredData = useMemo(function() {
251
+ var base = selectedFilter ? safeData.filter(function(d) {
252
+ return d.category === selectedFilter;
253
+ }) : safeData;
254
+ var withFilterLabel = !filterLabels || !selectedFilterLabel ? base : base.filter(function(d) {
255
+ return d.filterLabel === selectedFilterLabel;
256
+ });
257
+ // 统一过滤掉 x 为空(null/undefined)的数据,避免后续 toString 报错
258
+ return withFilterLabel.filter(function(d) {
259
+ return d.x !== null && d.x !== undefined;
260
+ });
261
+ }, [
262
+ safeData,
263
+ selectedFilter,
264
+ filterLabels,
265
+ selectedFilterLabel
266
+ ]);
267
+ // 阶段(使用 x 值作为阶段名称),按 y 从大到小排序以符合漏斗习惯
268
+ var stages = useMemo(function() {
269
+ var unique = _to_consumable_array(new Set(filteredData.map(function(d) {
270
+ return d.x;
271
+ }).filter(function(x) {
272
+ return x !== null && x !== undefined;
273
+ })));
274
+ // 映射阶段 -> 数值
275
+ var values = unique.map(function(x) {
276
+ var dp = findDataPointByXValue(filteredData, x);
277
+ var n = toNumber(dp === null || dp === void 0 ? void 0 : dp.y, 0);
278
+ return {
279
+ x: x,
280
+ n: n
281
+ };
282
+ });
283
+ // 降序
284
+ values.sort(function(a, b) {
285
+ return b.n - a.n;
286
+ });
287
+ return values.map(function(v) {
288
+ return v.x;
289
+ });
290
+ }, [
291
+ filteredData
292
+ ]);
293
+ var BAR_THICKNESS = 30;
294
+ var ROW_GAP = 24;
295
+ var PADDING_Y = isMobile ? 48 : 64;
296
+ // 计算图表高度
297
+ var chartHeight = useMemo(function() {
298
+ var rows = Math.max(1, stages.length);
299
+ return rows * (BAR_THICKNESS + ROW_GAP) + PADDING_Y;
300
+ }, [
301
+ stages.length,
302
+ PADDING_Y
303
+ ]);
304
+ // 最终高度计算逻辑
305
+ var finalHeight = useMemo(function() {
306
+ if (typeof height === 'number') {
307
+ return height;
308
+ } else if (typeof height === 'string' && height.includes('px')) {
309
+ return parseInt(height, 10) || chartHeight;
441
310
  }
442
- },
443
- x: {
444
- beginAtZero: true,
445
- grid: {
446
- display: false
311
+ return chartHeight;
312
+ }, [
313
+ height,
314
+ chartHeight
315
+ ]);
316
+ // 原始值
317
+ var originalValues = useMemo(function() {
318
+ return stages.map(function(x) {
319
+ var dp = findDataPointByXValue(filteredData, x);
320
+ return toNumber(dp === null || dp === void 0 ? void 0 : dp.y, 0);
321
+ });
322
+ }, [
323
+ filteredData,
324
+ stages
325
+ ]);
326
+ // 计算数据:使用浮动条 [-w/2, w/2] 居中呈现,形成对称“漏斗条”
327
+ var processedData = useMemo(function() {
328
+ var baseColor = color || defaultColorList[0];
329
+ var labels = stages.map(function(x) {
330
+ return x.toString();
331
+ });
332
+ var values = stages.map(function(x) {
333
+ var dp = findDataPointByXValue(filteredData, x);
334
+ var n = toNumber(dp === null || dp === void 0 ? void 0 : dp.y, 0);
335
+ return n;
336
+ });
337
+ // 取当前数据的类型名作为数据集 label
338
+ var typeName = (typeNames === null || typeNames === void 0 ? void 0 : typeNames.name) || '转化';
339
+ // 应用最小宽度约束
340
+ var adjustedValues = function() {
341
+ var _Math, _Math1;
342
+ // 非法值(≤0 或 >1)都视为不限制
343
+ if (bottomLayerMinWidth <= 0 || bottomLayerMinWidth > 1 || values.length === 0) {
344
+ return values;
345
+ }
346
+ var maxValue = (_Math = Math).max.apply(_Math, _to_consumable_array(values));
347
+ var minValue = (_Math1 = Math).min.apply(_Math1, _to_consumable_array(values));
348
+ // 如果最小值已经满足最小宽度要求,无需调整
349
+ if (minValue >= maxValue * bottomLayerMinWidth) {
350
+ return values;
351
+ }
352
+ // 线性映射到 [minWidth, maxValue] 区间
353
+ var minWidth = bottomLayerMinWidth * maxValue;
354
+ var range = maxValue - minValue;
355
+ return values.map(function(v) {
356
+ if (range === 0) return maxValue;
357
+ var normalized = (v - minValue) / range;
358
+ return minWidth + normalized * (maxValue - minWidth);
359
+ });
360
+ }();
361
+ // 中心对称的浮动条:[-v/2, v/2]
362
+ var datasetData = adjustedValues.map(function(v) {
363
+ return [
364
+ -v / 2,
365
+ v / 2
366
+ ];
367
+ });
368
+ // 生成从上到下由深到浅的颜色
369
+ var hexToRgb = function(hex) {
370
+ var s = hex.replace('#', '');
371
+ var bigint = parseInt(s, 16);
372
+ return {
373
+ r: bigint >> 16 & 255,
374
+ g: bigint >> 8 & 255,
375
+ b: bigint & 255
376
+ };
377
+ };
378
+ var rgbToHex = function(r, g, b) {
379
+ return "#".concat([
380
+ r,
381
+ g,
382
+ b
383
+ ].map(function(v) {
384
+ return Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0');
385
+ }).join(''));
386
+ };
387
+ var lighten = function(hex, t) {
388
+ var _hexToRgb = hexToRgb(hex), r = _hexToRgb.r, g = _hexToRgb.g, b = _hexToRgb.b;
389
+ var lr = r + (255 - r) * t;
390
+ var lg = g + (255 - g) * t;
391
+ var lb = b + (255 - b) * t;
392
+ return rgbToHex(lr, lg, lb);
393
+ };
394
+ var count = Math.max(1, stages.length - 1);
395
+ var colorList = stages.map(function(_, i) {
396
+ var t = i / count * 0.6; // 限制变浅上限,避免变白
397
+ return lighten(baseColor, t);
398
+ });
399
+ return {
400
+ labels: labels,
401
+ datasets: [
402
+ {
403
+ label: typeName,
404
+ data: datasetData,
405
+ backgroundColor: colorList,
406
+ borderColor: colorList,
407
+ borderWidth: 0,
408
+ borderRadius: 0,
409
+ borderSkipped: false,
410
+ barThickness: BAR_THICKNESS,
411
+ categoryPercentage: 1,
412
+ barPercentage: 1
413
+ }
414
+ ]
415
+ };
416
+ }, [
417
+ filteredData,
418
+ stages,
419
+ bottomLayerMinWidth,
420
+ color,
421
+ typeNames
422
+ ]);
423
+ var ratioDisplay = useMemo(function() {
424
+ var formatRaw = function(v) {
425
+ if (v === null || v === undefined) return undefined;
426
+ if (typeof v === 'string') {
427
+ var s = v.trim();
428
+ if (!s) return undefined;
429
+ return s.endsWith('%') ? s : "".concat(s, "%");
430
+ }
431
+ if (typeof v === 'number' && Number.isFinite(v)) {
432
+ return "".concat(String(v), "%");
433
+ }
434
+ return undefined;
435
+ };
436
+ // 检查除顶层外,是否至少有一层提供了 ratio
437
+ var anyNonTopProvided = stages.some(function(_, i) {
438
+ if (i === 0) return false;
439
+ var prevStage = stages[i - 1];
440
+ var dp = (filteredData || []).find(function(d) {
441
+ return isXValueEqual(d.x, prevStage);
442
+ });
443
+ var v = dp === null || dp === void 0 ? void 0 : dp.ratio;
444
+ if (v === null || v === undefined) return false;
445
+ if (typeof v === 'string') return v.trim() !== '';
446
+ return true;
447
+ });
448
+ return stages.map(function(_, i) {
449
+ if (i === 0) return anyNonTopProvided ? '100%' : undefined;
450
+ var prevStage = stages[i - 1];
451
+ var dp = (filteredData || []).find(function(d) {
452
+ return isXValueEqual(d.x, prevStage);
453
+ });
454
+ return formatRaw(dp === null || dp === void 0 ? void 0 : dp.ratio);
455
+ });
456
+ }, [
457
+ filteredData,
458
+ stages
459
+ ]);
460
+ var ratioProvided = useMemo(function() {
461
+ return stages.map(function(_, i) {
462
+ if (i === 0) return false;
463
+ var prevStage = stages[i - 1];
464
+ var dp = (filteredData || []).find(function(d) {
465
+ return isXValueEqual(d.x, prevStage);
466
+ });
467
+ var v = dp === null || dp === void 0 ? void 0 : dp.ratio;
468
+ if (v === null || v === undefined) return false;
469
+ if (typeof v === 'string') return v.trim() !== '';
470
+ return true;
471
+ });
472
+ }, [
473
+ filteredData,
474
+ stages
475
+ ]);
476
+ // 过滤器选项
477
+ var filterOptions = useMemo(function() {
478
+ return categories.map(function(c) {
479
+ return {
480
+ label: c || '默认',
481
+ value: c || '默认'
482
+ };
483
+ });
484
+ }, [
485
+ categories
486
+ ]);
487
+ var customOptions = useMemo(function() {
488
+ return filterLabels === null || filterLabels === void 0 ? void 0 : filterLabels.map(function(l) {
489
+ return {
490
+ key: l,
491
+ label: l
492
+ };
493
+ });
494
+ }, [
495
+ filterLabels
496
+ ]);
497
+ var isLight = theme === 'light';
498
+ var axisTextColor = isLight ? 'rgba(0, 25, 61, 0.3255)' : 'rgba(255, 255, 255, 0.8)';
499
+ var options = {
500
+ responsive: true,
501
+ maintainAspectRatio: false,
502
+ indexAxis: 'y',
503
+ layout: {
504
+ padding: {
505
+ left: 8,
506
+ right: isMobile ? 72 : 96,
507
+ top: 8,
508
+ bottom: 8
509
+ }
447
510
  },
448
- ticks: {
449
- display: false
511
+ parsing: {
512
+ // 允许使用 [start, end] 浮动条
513
+ xAxisKey: undefined,
514
+ yAxisKey: undefined
450
515
  },
451
- title: {
452
- display: false
516
+ plugins: {
517
+ legend: {
518
+ display: showLegend,
519
+ position: legendPosition,
520
+ align: legendAlign,
521
+ labels: {
522
+ color: axisTextColor,
523
+ font: {
524
+ size: isMobile ? 10 : 12,
525
+ weight: 'normal'
526
+ },
527
+ padding: isMobile ? 10 : 12,
528
+ usePointStyle: true,
529
+ pointStyle: 'rectRounded',
530
+ generateLabels: function(chart) {
531
+ // @ts-ignore
532
+ var base = (ChartJS.defaults.plugins.legend.labels.generateLabels(chart) || []).map(function(it) {
533
+ return _object_spread_props(_object_spread({}, it), {
534
+ pointStyle: 'rectRounded'
535
+ });
536
+ });
537
+ // 若除顶层外没有任何 ratio,则移除“转化率”图例
538
+ var anyNonTopProvided = stages.some(function(_, i) {
539
+ if (i === 0) return false;
540
+ var prevStage = stages[i - 1];
541
+ var dp = (filteredData || []).find(function(d) {
542
+ return isXValueEqual(d.x, prevStage);
543
+ });
544
+ var v = dp === null || dp === void 0 ? void 0 : dp.ratio;
545
+ if (v === null || v === undefined) return false;
546
+ if (typeof v === 'string') return v.trim() !== '';
547
+ return true;
548
+ });
549
+ if (!anyNonTopProvided) return base;
550
+ return _to_consumable_array(base).concat([
551
+ {
552
+ text: (typeNames === null || typeNames === void 0 ? void 0 : typeNames.rate) || '转化率',
553
+ fillStyle: '#F1F2F4',
554
+ strokeStyle: '#F1F2F4',
555
+ lineWidth: 0,
556
+ hidden: !showTrapezoid,
557
+ datasetIndex: chart.data.datasets.length,
558
+ pointStyle: 'rectRounded'
559
+ }
560
+ ]);
561
+ }
562
+ },
563
+ onClick: function(e, legendItem, legend) {
564
+ if (legendItem.text === ((typeNames === null || typeNames === void 0 ? void 0 : typeNames.rate) || '转化率')) {
565
+ setShowTrapezoid(function(v) {
566
+ return !v;
567
+ });
568
+ setPluginToggleKey(function(k) {
569
+ return k + 1;
570
+ });
571
+ return;
572
+ }
573
+ // 其它保持默认行为
574
+ // @ts-ignore
575
+ var defaultClick = ChartJS.defaults.plugins.legend.onClick;
576
+ if (typeof defaultClick === 'function') defaultClick.call(legend, e, legendItem, legend);
577
+ }
578
+ },
579
+ tooltip: {
580
+ backgroundColor: isLight ? 'rgba(255,255,255,0.95)' : 'rgba(0,0,0,0.85)',
581
+ titleColor: isLight ? '#333' : '#fff',
582
+ bodyColor: isLight ? '#333' : '#fff',
583
+ borderColor: isLight ? 'rgba(0,0,0,0.12)' : 'rgba(255,255,255,0.2)',
584
+ borderWidth: 1,
585
+ cornerRadius: isMobile ? 6 : 8,
586
+ padding: 8,
587
+ displayColors: false,
588
+ callbacks: {
589
+ title: function(items) {
590
+ var it = items === null || items === void 0 ? void 0 : items[0];
591
+ return (it === null || it === void 0 ? void 0 : it.label) ? String(it.label) : '';
592
+ },
593
+ label: function(ctx) {
594
+ var _ctx_dataIndex;
595
+ // 使用原始值而非调整后的视觉宽度
596
+ var idx = (_ctx_dataIndex = ctx.dataIndex) !== null && _ctx_dataIndex !== void 0 ? _ctx_dataIndex : 0;
597
+ var _originalValues_idx;
598
+ var originalValue = (_originalValues_idx = originalValues === null || originalValues === void 0 ? void 0 : originalValues[idx]) !== null && _originalValues_idx !== void 0 ? _originalValues_idx : 0;
599
+ var percentStr = ratioDisplay === null || ratioDisplay === void 0 ? void 0 : ratioDisplay[idx];
600
+ // 仅当传入了 ratio 时展示百分比,否则只展示数值
601
+ if (showPercent === false || !percentStr) {
602
+ return "".concat(originalValue);
603
+ }
604
+ return "".concat(originalValue, "(").concat(percentStr, ")");
605
+ }
606
+ }
607
+ }
453
608
  },
454
- border: { display: false }
455
- }
456
- }
457
- };
458
- const handleDownload = () => downloadChart(chartRef.current, "funnel-chart");
459
- const trapezoidPlugin = useMemo(() => {
460
- return {
461
- id: "funnelTrapezoidLabels",
462
- afterDatasetsDraw: (chart) => {
463
- var _a2, _b2, _c, _d, _e, _f, _g;
464
- if (!showTrapezoid)
465
- return;
466
- const { ctx, data: cdata, scales } = chart;
467
- const meta = chart.getDatasetMeta(0);
468
- if (!meta)
469
- return;
470
- const xScale = scales == null ? void 0 : scales.x;
471
- const ds = ((_b2 = (_a2 = cdata == null ? void 0 : cdata.datasets) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.data) || [];
472
- const providedRatioText = ratioDisplay;
473
- const providedFlags = ratioProvided;
474
- const centerX = (xScale == null ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(0) : void 0;
475
- for (let i = 0; i < meta.data.length - 1; i++) {
476
- const elTop = meta.data[i];
477
- const elBot = meta.data[i + 1];
478
- const rawTop = ds == null ? void 0 : ds[i];
479
- const rawBot = ds == null ? void 0 : ds[i + 1];
480
- if (!Array.isArray(rawTop) || !Array.isArray(rawBot))
481
- continue;
482
- const [sTop, eTop] = [Number((_c = rawTop[0]) != null ? _c : 0), Number((_d = rawTop[1]) != null ? _d : 0)];
483
- const [sBot, eBot] = [Number((_e = rawBot[0]) != null ? _e : 0), Number((_f = rawBot[1]) != null ? _f : 0)];
484
- const topLx = (xScale == null ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(Math.min(sTop, eTop)) : elTop.x - Math.abs(eTop - sTop) / 2;
485
- const topRx = (xScale == null ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(Math.max(sTop, eTop)) : elTop.x + Math.abs(eTop - sTop) / 2;
486
- const botLx = (xScale == null ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(Math.min(sBot, eBot)) : elBot.x - Math.abs(eBot - sBot) / 2;
487
- const botRx = (xScale == null ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(Math.max(sBot, eBot)) : elBot.x + Math.abs(eBot - sBot) / 2;
488
- const dpr = typeof window !== "undefined" && (window.devicePixelRatio || 1) || 1;
489
- const seam = (isMobile ? 0.25 : 0.35) / dpr;
490
- const joinTop = elTop.y + elTop.height / 2;
491
- const joinBot = elBot.y - elBot.height / 2;
492
- const topY = joinTop + seam;
493
- const botY = joinBot - seam;
494
- if (!(providedFlags == null ? void 0 : providedFlags[i + 1])) {
495
- continue;
496
- }
497
- const ratioText = (_g = providedRatioText == null ? void 0 : providedRatioText[i + 1]) != null ? _g : "0%";
498
- const topL = Math.min(topLx, topRx);
499
- const topR = Math.max(topLx, topRx);
500
- const botL = Math.min(botLx, botRx);
501
- const botR = Math.max(botLx, botRx);
502
- ctx.save();
503
- ctx.beginPath();
504
- ctx.moveTo(topL, topY);
505
- ctx.lineTo(topR, topY);
506
- ctx.lineTo(botR, botY);
507
- ctx.lineTo(botL, botY);
508
- ctx.closePath();
509
- ctx.fillStyle = "#F1F2F4";
510
- ctx.fill();
511
- const midY = (topY + botY) / 2;
512
- const cx = centerX != null ? centerX : (Math.min(topL, botL) + Math.max(topR, botR)) / 2;
513
- ctx.fillStyle = "#626F86";
514
- ctx.font = `${isMobile ? 10 : 12}px sans-serif`;
515
- ctx.textAlign = "center";
516
- ctx.textBaseline = "middle";
517
- ctx.fillText(String(ratioText), cx, midY);
518
- ctx.restore();
609
+ scales: {
610
+ y: {
611
+ grid: {
612
+ display: false
613
+ },
614
+ ticks: {
615
+ display: false
616
+ },
617
+ title: {
618
+ display: false
619
+ },
620
+ border: {
621
+ display: false
622
+ },
623
+ afterFit: function(scale) {
624
+ var rows = Math.max(1, stages.length);
625
+ var per = BAR_THICKNESS + ROW_GAP;
626
+ var total = rows * per;
627
+ scale.height = total;
628
+ }
629
+ },
630
+ x: {
631
+ beginAtZero: true,
632
+ grid: {
633
+ display: false
634
+ },
635
+ ticks: {
636
+ display: false
637
+ },
638
+ title: {
639
+ display: false
640
+ },
641
+ border: {
642
+ display: false
643
+ }
644
+ }
519
645
  }
520
- }
521
646
  };
522
- }, [
523
- isMobile,
524
- showTrapezoid,
525
- JSON.stringify(filteredData.map((d) => d == null ? void 0 : d.ratio))
526
- ]);
527
- const rightLabelPlugin = useMemo(() => {
528
- return {
529
- id: "funnelRightLabels",
530
- afterDatasetsDraw: (chart) => {
531
- var _a2, _b2;
532
- const { ctx, data: data2, scales } = chart;
533
- const meta = chart.getDatasetMeta(0);
534
- if (!meta)
535
- return;
536
- const xScale = scales == null ? void 0 : scales.x;
537
- const labels = (data2 == null ? void 0 : data2.labels) || [];
538
- ctx.save();
539
- ctx.fillStyle = axisTextColor;
540
- ctx.font = `${isMobile ? 10 : 12}px sans-serif`;
541
- ctx.textAlign = "left";
542
- ctx.textBaseline = "middle";
543
- const ds = ((_b2 = (_a2 = data2 == null ? void 0 : data2.datasets) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.data) || [];
544
- const ends = meta.data.map((el, i) => {
545
- var _a3;
546
- const raw = ds == null ? void 0 : ds[i];
547
- if (!raw || !Array.isArray(raw))
548
- return el.x;
549
- const end = Number((_a3 = raw[1]) != null ? _a3 : 0);
550
- return (xScale == null ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(end) : el.x + Math.max(0, el.width / 2);
551
- });
552
- const maxEnd = Math.max(...ends);
553
- const padding = 12;
554
- meta.data.forEach((el, i) => {
555
- var _a3, _b3, _c, _d;
556
- const raw = ds == null ? void 0 : ds[i];
557
- if (!raw || !Array.isArray(raw))
558
- return;
559
- const y = el.y;
560
- const label = (_a3 = labels == null ? void 0 : labels[i]) != null ? _a3 : "";
561
- ctx.fillText(label, maxEnd + padding, y);
562
- const start = Number((_b3 = raw[0]) != null ? _b3 : 0);
563
- const end = Number((_c = raw[1]) != null ? _c : 0);
564
- const mid = (start + end) / 2;
565
- const originalValue = (_d = originalValues == null ? void 0 : originalValues[i]) != null ? _d : 0;
566
- const cx = (xScale == null ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(mid) : el.x;
567
- ctx.save();
568
- ctx.fillStyle = "#fff";
569
- ctx.textAlign = "center";
570
- ctx.fillText(String(Math.round(originalValue)), cx, y);
571
- ctx.restore();
572
- });
573
- ctx.restore();
574
- }
647
+ var handleDownload = function() {
648
+ return downloadChart(chartRef.current, 'funnel-chart');
575
649
  };
576
- }, [isMobile, axisTextColor, originalValues]);
577
- const containerClassName = useMemo(() => {
578
- if (isMobile)
579
- return "w-full";
580
- if (typeof width === "number")
581
- return "";
582
- if (typeof width === "string" && width === "100%")
583
- return "w-full";
584
- return "";
585
- }, [isMobile, width]);
586
- const containerStyle = useMemo(() => {
587
- if (isMobile)
588
- return void 0;
589
- if (typeof width === "number")
590
- return { width };
591
- if (typeof width === "string" && width !== "100%")
592
- return { width };
593
- return void 0;
594
- }, [isMobile, width]);
595
- return wrapSSR(
596
- /* @__PURE__ */ React.createElement(
597
- ChartContainer,
598
- {
599
- baseClassName,
600
- className: `${className || ""} ${containerClassName}`.trim(),
601
- theme,
650
+ // 中间梯形 + 比率文本(梯形 #F1F2F4,文本 #626F86)
651
+ var trapezoidPlugin = useMemo(function() {
652
+ return {
653
+ id: 'funnelTrapezoidLabels',
654
+ afterDatasetsDraw: function(chart) {
655
+ var _cdata_datasets_, _cdata_datasets;
656
+ if (!showTrapezoid) return;
657
+ var ctx = chart.ctx, cdata = chart.data, scales = chart.scales;
658
+ var meta = chart.getDatasetMeta(0);
659
+ if (!meta) return;
660
+ var xScale = scales === null || scales === void 0 ? void 0 : scales.x;
661
+ var ds = (cdata === null || cdata === void 0 ? void 0 : (_cdata_datasets = cdata.datasets) === null || _cdata_datasets === void 0 ? void 0 : (_cdata_datasets_ = _cdata_datasets[0]) === null || _cdata_datasets_ === void 0 ? void 0 : _cdata_datasets_.data) || [];
662
+ var providedRatioText = ratioDisplay;
663
+ var providedFlags = ratioProvided;
664
+ var centerX = (xScale === null || xScale === void 0 ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(0) : undefined;
665
+ // 逐对绘制 i i+1 之间的梯形
666
+ for(var i = 0; i < meta.data.length - 1; i++){
667
+ var elTop = meta.data[i];
668
+ var elBot = meta.data[i + 1];
669
+ var rawTop = ds === null || ds === void 0 ? void 0 : ds[i];
670
+ var rawBot = ds === null || ds === void 0 ? void 0 : ds[i + 1];
671
+ if (!Array.isArray(rawTop) || !Array.isArray(rawBot)) continue;
672
+ var _rawTop_, _rawTop_1;
673
+ // 顶部、底部条的像素左右与宽度
674
+ var _ref = [
675
+ Number((_rawTop_ = rawTop[0]) !== null && _rawTop_ !== void 0 ? _rawTop_ : 0),
676
+ Number((_rawTop_1 = rawTop[1]) !== null && _rawTop_1 !== void 0 ? _rawTop_1 : 0)
677
+ ], sTop = _ref[0], eTop = _ref[1];
678
+ var _rawBot_, _rawBot_1;
679
+ var _ref1 = [
680
+ Number((_rawBot_ = rawBot[0]) !== null && _rawBot_ !== void 0 ? _rawBot_ : 0),
681
+ Number((_rawBot_1 = rawBot[1]) !== null && _rawBot_1 !== void 0 ? _rawBot_1 : 0)
682
+ ], sBot = _ref1[0], eBot = _ref1[1];
683
+ var topLx = (xScale === null || xScale === void 0 ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(Math.min(sTop, eTop)) : elTop.x - Math.abs(eTop - sTop) / 2;
684
+ var topRx = (xScale === null || xScale === void 0 ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(Math.max(sTop, eTop)) : elTop.x + Math.abs(eTop - sTop) / 2;
685
+ var botLx = (xScale === null || xScale === void 0 ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(Math.min(sBot, eBot)) : elBot.x - Math.abs(eBot - sBot) / 2;
686
+ var botRx = (xScale === null || xScale === void 0 ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(Math.max(sBot, eBot)) : elBot.x + Math.abs(eBot - sBot) / 2;
687
+ var dpr = typeof window !== 'undefined' && (window.devicePixelRatio || 1) || 1;
688
+ var seam = (isMobile ? 0.25 : 0.35) / dpr;
689
+ var joinTop = elTop.y + elTop.height / 2;
690
+ var joinBot = elBot.y - elBot.height / 2;
691
+ var topY = joinTop + seam;
692
+ var botY = joinBot - seam;
693
+ // 如果该层未显式提供 ratio,则不绘制梯形
694
+ if (!(providedFlags === null || providedFlags === void 0 ? void 0 : providedFlags[i + 1])) {
695
+ continue;
696
+ }
697
+ var _providedRatioText_;
698
+ var ratioText = (_providedRatioText_ = providedRatioText === null || providedRatioText === void 0 ? void 0 : providedRatioText[i + 1]) !== null && _providedRatioText_ !== void 0 ? _providedRatioText_ : '0%';
699
+ // 梯形边与上下柱完全对齐
700
+ var topL = Math.min(topLx, topRx);
701
+ var topR = Math.max(topLx, topRx);
702
+ var botL = Math.min(botLx, botRx);
703
+ var botR = Math.max(botLx, botRx);
704
+ // 绘制梯形
705
+ ctx.save();
706
+ ctx.beginPath();
707
+ ctx.moveTo(topL, topY);
708
+ ctx.lineTo(topR, topY);
709
+ ctx.lineTo(botR, botY);
710
+ ctx.lineTo(botL, botY);
711
+ ctx.closePath();
712
+ ctx.fillStyle = '#F1F2F4';
713
+ ctx.fill();
714
+ // 文本(展示该比率)
715
+ var midY = (topY + botY) / 2;
716
+ var cx = centerX !== null && centerX !== void 0 ? centerX : (Math.min(topL, botL) + Math.max(topR, botR)) / 2;
717
+ ctx.fillStyle = '#626F86';
718
+ ctx.font = "".concat(isMobile ? 10 : 12, "px sans-serif");
719
+ ctx.textAlign = 'center';
720
+ ctx.textBaseline = 'middle';
721
+ ctx.fillText(String(ratioText), cx, midY);
722
+ ctx.restore();
723
+ }
724
+ }
725
+ };
726
+ }, [
602
727
  isMobile,
728
+ showTrapezoid,
729
+ JSON.stringify(filteredData.map(function(d) {
730
+ return d === null || d === void 0 ? void 0 : d.ratio;
731
+ }))
732
+ ]);
733
+ // 右侧阶段文本标签(跟随每个柱,显示 stage 名称)
734
+ var rightLabelPlugin = useMemo(function() {
735
+ return {
736
+ id: 'funnelRightLabels',
737
+ afterDatasetsDraw: function(chart) {
738
+ var _Math;
739
+ var _data_datasets_, _data_datasets;
740
+ var ctx = chart.ctx, data = chart.data, scales = chart.scales;
741
+ var meta = chart.getDatasetMeta(0);
742
+ if (!meta) return;
743
+ var xScale = scales === null || scales === void 0 ? void 0 : scales.x;
744
+ var labels = (data === null || data === void 0 ? void 0 : data.labels) || [];
745
+ ctx.save();
746
+ ctx.fillStyle = axisTextColor;
747
+ ctx.font = "".concat(isMobile ? 10 : 12, "px sans-serif");
748
+ ctx.textAlign = 'left';
749
+ ctx.textBaseline = 'middle';
750
+ var ds = (data === null || data === void 0 ? void 0 : (_data_datasets = data.datasets) === null || _data_datasets === void 0 ? void 0 : (_data_datasets_ = _data_datasets[0]) === null || _data_datasets_ === void 0 ? void 0 : _data_datasets_.data) || [];
751
+ // 计算所有条末端的像素坐标,找最大值作为对齐基准
752
+ var ends = meta.data.map(function(el, i) {
753
+ var raw = ds === null || ds === void 0 ? void 0 : ds[i];
754
+ if (!raw || !Array.isArray(raw)) return el.x;
755
+ var _raw_;
756
+ var end = Number((_raw_ = raw[1]) !== null && _raw_ !== void 0 ? _raw_ : 0);
757
+ return (xScale === null || xScale === void 0 ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(end) : el.x + Math.max(0, el.width / 2);
758
+ });
759
+ var maxEnd = (_Math = Math).max.apply(_Math, _to_consumable_array(ends));
760
+ var padding = 12;
761
+ meta.data.forEach(function(el, i) {
762
+ var raw = ds === null || ds === void 0 ? void 0 : ds[i];
763
+ if (!raw || !Array.isArray(raw)) return;
764
+ var y = el.y;
765
+ var _labels_i;
766
+ var label = (_labels_i = labels === null || labels === void 0 ? void 0 : labels[i]) !== null && _labels_i !== void 0 ? _labels_i : '';
767
+ ctx.fillText(label, maxEnd + padding, y);
768
+ var _raw_;
769
+ // 在柱体中心绘制数值文本(白色)- 使用原始值
770
+ var start = Number((_raw_ = raw[0]) !== null && _raw_ !== void 0 ? _raw_ : 0);
771
+ var _raw_1;
772
+ var end = Number((_raw_1 = raw[1]) !== null && _raw_1 !== void 0 ? _raw_1 : 0);
773
+ var mid = (start + end) / 2;
774
+ var _originalValues_i;
775
+ var originalValue = (_originalValues_i = originalValues === null || originalValues === void 0 ? void 0 : originalValues[i]) !== null && _originalValues_i !== void 0 ? _originalValues_i : 0;
776
+ var cx = (xScale === null || xScale === void 0 ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(mid) : el.x;
777
+ ctx.save();
778
+ ctx.fillStyle = '#fff';
779
+ ctx.textAlign = 'center';
780
+ ctx.fillText(String(Math.round(originalValue)), cx, y);
781
+ ctx.restore();
782
+ });
783
+ ctx.restore();
784
+ }
785
+ };
786
+ }, [
787
+ isMobile,
788
+ axisTextColor,
789
+ originalValues
790
+ ]);
791
+ var containerClassName = useMemo(function() {
792
+ if (isMobile) return 'w-full';
793
+ if (typeof width === 'number') return '';
794
+ if (typeof width === 'string' && width === '100%') return 'w-full';
795
+ return '';
796
+ }, [
797
+ isMobile,
798
+ width
799
+ ]);
800
+ var containerStyle = useMemo(function() {
801
+ if (isMobile) return undefined;
802
+ if (typeof width === 'number') return {
803
+ width: width
804
+ };
805
+ if (typeof width === 'string' && width !== '100%') return {
806
+ width: width
807
+ };
808
+ return undefined;
809
+ }, [
810
+ isMobile,
811
+ width
812
+ ]);
813
+ return wrapSSR(/*#__PURE__*/ React.createElement(ChartContainer, {
814
+ baseClassName: baseClassName,
815
+ className: "".concat(className || '', " ").concat(containerClassName).trim(),
816
+ theme: theme,
817
+ isMobile: isMobile,
603
818
  variant: props.variant,
604
819
  style: containerStyle
605
- },
606
- /* @__PURE__ */ React.createElement(
607
- ChartToolBar,
608
- {
609
- title,
610
- theme,
611
- onDownload: handleDownload,
612
- dataTime,
613
- extra: toolbarExtra,
614
- filter: renderFilterInToolbar && filterOptions && filterOptions.length > 1 ? /* @__PURE__ */ React.createElement(
615
- ChartFilter,
616
- __spreadProps(__spreadValues({
617
- filterOptions,
618
- selectedFilter,
619
- onFilterChange: setSelectedFilter
620
- }, customOptions && {
621
- customOptions,
622
- selectedCustomSelection: selectedFilterLabel,
623
- onSelectionChange: setSelectedFilterLabel
624
- }), {
625
- theme,
626
- variant: "compact"
627
- })
628
- ) : void 0
629
- }
630
- ),
631
- !renderFilterInToolbar && filterOptions && filterOptions.length > 1 && /* @__PURE__ */ React.createElement(
632
- ChartFilter,
633
- __spreadProps(__spreadValues({
634
- filterOptions,
635
- selectedFilter,
636
- onFilterChange: setSelectedFilter
820
+ }, /*#__PURE__*/ React.createElement(ChartToolBar, {
821
+ title: title,
822
+ theme: theme,
823
+ onDownload: handleDownload,
824
+ dataTime: dataTime,
825
+ extra: toolbarExtra,
826
+ filter: renderFilterInToolbar && filterOptions && filterOptions.length > 1 ? /*#__PURE__*/ React.createElement(ChartFilter, _object_spread_props(_object_spread({
827
+ filterOptions: filterOptions,
828
+ selectedFilter: selectedFilter,
829
+ onFilterChange: setSelectedFilter
637
830
  }, customOptions && {
638
- customOptions,
639
- selectedCustomSelection: selectedFilterLabel,
640
- onSelectionChange: setSelectedFilterLabel
831
+ customOptions: customOptions,
832
+ selectedCustomSelection: selectedFilterLabel,
833
+ onSelectionChange: setSelectedFilterLabel
641
834
  }), {
642
- theme
643
- })
644
- ),
645
- statistics && /* @__PURE__ */ React.createElement(
646
- "div",
647
- {
648
- className: classNames(`${baseClassName}-statistic-container`, hashId)
649
- },
650
- statistics.map((config, index) => /* @__PURE__ */ React.createElement(ChartStatistic, __spreadProps(__spreadValues({ key: index }, config), { theme })))
651
- ),
652
- /* @__PURE__ */ React.createElement(
653
- "div",
654
- {
655
- className: classNames(`${baseClassName}-wrapper`, hashId),
656
- style: { height: finalHeight }
657
- },
658
- /* @__PURE__ */ React.createElement(
659
- Bar,
660
- {
661
- key: `funnel-${pluginToggleKey}`,
662
- ref: chartRef,
663
- data: processedData,
664
- options,
665
- plugins: [trapezoidPlugin, rightLabelPlugin]
666
- }
667
- )
668
- )
669
- )
670
- );
671
- };
672
- var FunnelChart_default = FunnelChart;
673
- export {
674
- FunnelChart_default as default
835
+ theme: theme,
836
+ variant: "compact"
837
+ })) : undefined
838
+ }), !renderFilterInToolbar && filterOptions && filterOptions.length > 1 && /*#__PURE__*/ React.createElement(ChartFilter, _object_spread_props(_object_spread({
839
+ filterOptions: filterOptions,
840
+ selectedFilter: selectedFilter,
841
+ onFilterChange: setSelectedFilter
842
+ }, customOptions && {
843
+ customOptions: customOptions,
844
+ selectedCustomSelection: selectedFilterLabel,
845
+ onSelectionChange: setSelectedFilterLabel
846
+ }), {
847
+ theme: theme
848
+ })), statistics && /*#__PURE__*/ React.createElement("div", {
849
+ className: classNames("".concat(baseClassName, "-statistic-container"), hashId)
850
+ }, statistics.map(function(config, index) {
851
+ return /*#__PURE__*/ React.createElement(ChartStatistic, _object_spread_props(_object_spread({
852
+ key: index
853
+ }, config), {
854
+ theme: theme
855
+ }));
856
+ })), /*#__PURE__*/ React.createElement("div", {
857
+ className: classNames("".concat(baseClassName, "-wrapper"), hashId),
858
+ style: {
859
+ height: finalHeight
860
+ }
861
+ }, /*#__PURE__*/ React.createElement(Bar, {
862
+ key: "funnel-".concat(pluginToggleKey),
863
+ ref: chartRef,
864
+ data: processedData,
865
+ options: options,
866
+ plugins: [
867
+ trapezoidPlugin,
868
+ rightLabelPlugin
869
+ ]
870
+ }))));
675
871
  };
872
+ export default FunnelChart;