@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,1120 +1,1681 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
1
+ /**
2
+ * 基于 Proxy 的沙箱实现
3
+ *
4
+ * 这个模块提供了一个安全的代码执行环境,通过 Proxy 劫持全局对象的访问,
5
+ * 防止恶意代码对宿主环境造成破坏,同时提供受控的 API 访问。
6
+ *
7
+ * 主要特性:
8
+ * - 全局对象隔离
9
+ * - API 访问控制
10
+ * - 内存管理
11
+ * - 错误捕获和处理
12
+ * - 执行超时控制
13
+ *
14
+ * @author md-editor
15
+ * @version 1.0.0
16
+ */ /**
17
+ * 沙箱配置接口
18
+ */ function _array_like_to_array(arr, len) {
19
+ if (len == null || len > arr.length) len = arr.length;
20
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
21
+ return arr2;
22
+ }
23
+ function _array_with_holes(arr) {
24
+ if (Array.isArray(arr)) return arr;
25
+ }
26
+ function _array_without_holes(arr) {
27
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
28
+ }
29
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
30
+ try {
31
+ var info = gen[key](arg);
32
+ var value = info.value;
33
+ } catch (error) {
34
+ reject(error);
35
+ return;
14
36
  }
15
- return a;
16
- };
17
- var __async = (__this, __arguments, generator) => {
18
- return new Promise((resolve, reject) => {
19
- var fulfilled = (value) => {
20
- try {
21
- step(generator.next(value));
22
- } catch (e) {
23
- reject(e);
24
- }
37
+ if (info.done) {
38
+ resolve(value);
39
+ } else {
40
+ Promise.resolve(value).then(_next, _throw);
41
+ }
42
+ }
43
+ function _async_to_generator(fn) {
44
+ return function() {
45
+ var self = this, args = arguments;
46
+ return new Promise(function(resolve, reject) {
47
+ var gen = fn.apply(self, args);
48
+ function _next(value) {
49
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
50
+ }
51
+ function _throw(err) {
52
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
53
+ }
54
+ _next(undefined);
55
+ });
25
56
  };
26
- var rejected = (value) => {
27
- try {
28
- step(generator.throw(value));
29
- } catch (e) {
30
- reject(e);
31
- }
57
+ }
58
+ function _class_call_check(instance, Constructor) {
59
+ if (!(instance instanceof Constructor)) {
60
+ throw new TypeError("Cannot call a class as a function");
61
+ }
62
+ }
63
+ function _defineProperties(target, props) {
64
+ for(var i = 0; i < props.length; i++){
65
+ var descriptor = props[i];
66
+ descriptor.enumerable = descriptor.enumerable || false;
67
+ descriptor.configurable = true;
68
+ if ("value" in descriptor) descriptor.writable = true;
69
+ Object.defineProperty(target, descriptor.key, descriptor);
70
+ }
71
+ }
72
+ function _create_class(Constructor, protoProps, staticProps) {
73
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
74
+ if (staticProps) _defineProperties(Constructor, staticProps);
75
+ return Constructor;
76
+ }
77
+ function _define_property(obj, key, value) {
78
+ if (key in obj) {
79
+ Object.defineProperty(obj, key, {
80
+ value: value,
81
+ enumerable: true,
82
+ configurable: true,
83
+ writable: true
84
+ });
85
+ } else {
86
+ obj[key] = value;
87
+ }
88
+ return obj;
89
+ }
90
+ function _iterable_to_array(iter) {
91
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
92
+ }
93
+ function _iterable_to_array_limit(arr, i) {
94
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
95
+ if (_i == null) return;
96
+ var _arr = [];
97
+ var _n = true;
98
+ var _d = false;
99
+ var _s, _e;
100
+ try {
101
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
102
+ _arr.push(_s.value);
103
+ if (i && _arr.length === i) break;
104
+ }
105
+ } catch (err) {
106
+ _d = true;
107
+ _e = err;
108
+ } finally{
109
+ try {
110
+ if (!_n && _i["return"] != null) _i["return"]();
111
+ } finally{
112
+ if (_d) throw _e;
113
+ }
114
+ }
115
+ return _arr;
116
+ }
117
+ function _non_iterable_rest() {
118
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
119
+ }
120
+ function _non_iterable_spread() {
121
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
122
+ }
123
+ function _object_spread(target) {
124
+ for(var i = 1; i < arguments.length; i++){
125
+ var source = arguments[i] != null ? arguments[i] : {};
126
+ var ownKeys = Object.keys(source);
127
+ if (typeof Object.getOwnPropertySymbols === "function") {
128
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
129
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
130
+ }));
131
+ }
132
+ ownKeys.forEach(function(key) {
133
+ _define_property(target, key, source[key]);
134
+ });
135
+ }
136
+ return target;
137
+ }
138
+ function _sliced_to_array(arr, i) {
139
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
140
+ }
141
+ function _to_consumable_array(arr) {
142
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
143
+ }
144
+ function _unsupported_iterable_to_array(o, minLen) {
145
+ if (!o) return;
146
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
147
+ var n = Object.prototype.toString.call(o).slice(8, -1);
148
+ if (n === "Object" && o.constructor) n = o.constructor.name;
149
+ if (n === "Map" || n === "Set") return Array.from(n);
150
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
151
+ }
152
+ function _ts_generator(thisArg, body) {
153
+ var f, y, t, g, _ = {
154
+ label: 0,
155
+ sent: function() {
156
+ if (t[0] & 1) throw t[1];
157
+ return t[1];
158
+ },
159
+ trys: [],
160
+ ops: []
32
161
  };
33
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
- step((generator = generator.apply(__this, __arguments)).next());
35
- });
36
- };
37
-
38
- // src/Utils/proxySandbox/ProxySandbox.ts
162
+ return g = {
163
+ next: verb(0),
164
+ "throw": verb(1),
165
+ "return": verb(2)
166
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
167
+ return this;
168
+ }), g;
169
+ function verb(n) {
170
+ return function(v) {
171
+ return step([
172
+ n,
173
+ v
174
+ ]);
175
+ };
176
+ }
177
+ function step(op) {
178
+ if (f) throw new TypeError("Generator is already executing.");
179
+ while(_)try {
180
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
181
+ if (y = 0, t) op = [
182
+ op[0] & 2,
183
+ t.value
184
+ ];
185
+ switch(op[0]){
186
+ case 0:
187
+ case 1:
188
+ t = op;
189
+ break;
190
+ case 4:
191
+ _.label++;
192
+ return {
193
+ value: op[1],
194
+ done: false
195
+ };
196
+ case 5:
197
+ _.label++;
198
+ y = op[1];
199
+ op = [
200
+ 0
201
+ ];
202
+ continue;
203
+ case 7:
204
+ op = _.ops.pop();
205
+ _.trys.pop();
206
+ continue;
207
+ default:
208
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
209
+ _ = 0;
210
+ continue;
211
+ }
212
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
213
+ _.label = op[1];
214
+ break;
215
+ }
216
+ if (op[0] === 6 && _.label < t[1]) {
217
+ _.label = t[1];
218
+ t = op;
219
+ break;
220
+ }
221
+ if (t && _.label < t[2]) {
222
+ _.label = t[2];
223
+ _.ops.push(op);
224
+ break;
225
+ }
226
+ if (t[2]) _.ops.pop();
227
+ _.trys.pop();
228
+ continue;
229
+ }
230
+ op = body.call(thisArg, _);
231
+ } catch (e) {
232
+ op = [
233
+ 6,
234
+ e
235
+ ];
236
+ y = 0;
237
+ } finally{
238
+ f = t = 0;
239
+ }
240
+ if (op[0] & 5) throw op[1];
241
+ return {
242
+ value: op[0] ? op[1] : void 0,
243
+ done: true
244
+ };
245
+ }
246
+ }
247
+ /**
248
+ * 默认的危险全局对象列表
249
+ */ // 危险的全局变量(完全禁止访问)
39
250
  var DANGEROUS_GLOBALS = [
40
- "eval",
41
- "Function",
42
- "constructor",
43
- "__proto__",
44
- "prototype",
45
- "global",
46
- "globalThis",
47
- "self",
48
- "parent",
49
- "top",
50
- "frames",
51
- "location",
52
- "history",
53
- "navigator",
54
- "screen",
55
- "localStorage",
56
- "sessionStorage",
57
- "indexedDB",
58
- "WebSocket",
59
- "XMLHttpRequest",
60
- "fetch",
61
- "Request",
62
- "Response",
63
- "Headers",
64
- "URL",
65
- "URLSearchParams",
66
- "Blob",
67
- "File",
68
- "FileReader",
69
- "FormData",
70
- "Worker",
71
- "SharedWorker",
72
- "ServiceWorker",
73
- "MessageChannel",
74
- "MessagePort",
75
- "BroadcastChannel",
76
- "WebRTC",
77
- "MediaStream",
78
- "process",
79
- "require",
80
- "module",
81
- "exports",
82
- "Buffer",
83
- "global",
84
- "setImmediate",
85
- "clearImmediate",
86
- "setInterval",
87
- "clearInterval",
88
- "setTimeout",
89
- "clearTimeout",
90
- "queueMicrotask",
91
- "requestAnimationFrame",
92
- "cancelAnimationFrame",
93
- "requestIdleCallback",
94
- "cancelIdleCallback",
95
- "crypto",
96
- "SubtleCrypto",
97
- "performance",
98
- "PerformanceObserver",
99
- "IntersectionObserver",
100
- "MutationObserver",
101
- "ResizeObserver",
102
- "AbortController",
103
- "AbortSignal",
104
- "EventSource",
105
- "CloseEvent",
106
- "CustomEvent",
107
- "ErrorEvent",
108
- "Event",
109
- "EventTarget",
110
- "MessageEvent",
111
- "ProgressEvent",
112
- "PromiseRejectionEvent",
113
- "alert",
114
- "confirm",
115
- "prompt",
116
- "open",
117
- "close",
118
- "print",
119
- "focus",
120
- "blur",
121
- "getSelection",
122
- "getComputedStyle",
123
- "matchMedia",
124
- "moveBy",
125
- "moveTo",
126
- "resizeBy",
127
- "resizeTo",
128
- "scroll",
129
- "scrollBy",
130
- "scrollTo",
131
- "stop",
132
- "Notification",
133
- "webkitNotifications",
134
- "external",
135
- "chrome",
136
- "safari",
137
- "opera",
138
- "moz"
251
+ 'eval',
252
+ 'Function',
253
+ 'constructor',
254
+ '__proto__',
255
+ 'prototype',
256
+ 'global',
257
+ 'globalThis',
258
+ 'self',
259
+ 'parent',
260
+ 'top',
261
+ 'frames',
262
+ 'location',
263
+ 'history',
264
+ 'navigator',
265
+ 'screen',
266
+ 'localStorage',
267
+ 'sessionStorage',
268
+ 'indexedDB',
269
+ 'WebSocket',
270
+ 'XMLHttpRequest',
271
+ 'fetch',
272
+ 'Request',
273
+ 'Response',
274
+ 'Headers',
275
+ 'URL',
276
+ 'URLSearchParams',
277
+ 'Blob',
278
+ 'File',
279
+ 'FileReader',
280
+ 'FormData',
281
+ 'Worker',
282
+ 'SharedWorker',
283
+ 'ServiceWorker',
284
+ 'MessageChannel',
285
+ 'MessagePort',
286
+ 'BroadcastChannel',
287
+ 'WebRTC',
288
+ 'MediaStream',
289
+ 'process',
290
+ 'require',
291
+ 'module',
292
+ 'exports',
293
+ 'Buffer',
294
+ 'global',
295
+ 'setImmediate',
296
+ 'clearImmediate',
297
+ 'setInterval',
298
+ 'clearInterval',
299
+ 'setTimeout',
300
+ 'clearTimeout',
301
+ 'queueMicrotask',
302
+ 'requestAnimationFrame',
303
+ 'cancelAnimationFrame',
304
+ 'requestIdleCallback',
305
+ 'cancelIdleCallback',
306
+ 'crypto',
307
+ 'SubtleCrypto',
308
+ 'performance',
309
+ 'PerformanceObserver',
310
+ 'IntersectionObserver',
311
+ 'MutationObserver',
312
+ 'ResizeObserver',
313
+ 'AbortController',
314
+ 'AbortSignal',
315
+ 'EventSource',
316
+ 'CloseEvent',
317
+ 'CustomEvent',
318
+ 'ErrorEvent',
319
+ 'Event',
320
+ 'EventTarget',
321
+ 'MessageEvent',
322
+ 'ProgressEvent',
323
+ 'PromiseRejectionEvent',
324
+ 'alert',
325
+ 'confirm',
326
+ 'prompt',
327
+ 'open',
328
+ 'close',
329
+ 'print',
330
+ 'focus',
331
+ 'blur',
332
+ 'getSelection',
333
+ 'getComputedStyle',
334
+ 'matchMedia',
335
+ 'moveBy',
336
+ 'moveTo',
337
+ 'resizeBy',
338
+ 'resizeTo',
339
+ 'scroll',
340
+ 'scrollBy',
341
+ 'scrollTo',
342
+ 'stop',
343
+ 'Notification',
344
+ 'webkitNotifications',
345
+ 'external',
346
+ 'chrome',
347
+ 'safari',
348
+ 'opera',
349
+ 'moz'
139
350
  ];
140
- var SAFE_GLOBALS = [
141
- "console",
142
- "setTimeout",
143
- "setInterval",
144
- "clearTimeout",
145
- "clearInterval",
146
- "Math",
147
- "Date",
148
- "JSON",
149
- "parseInt",
150
- "parseFloat",
151
- "isNaN",
152
- "isFinite",
153
- "encodeURIComponent",
154
- "decodeURIComponent",
155
- "encodeURI",
156
- "decodeURI",
157
- "String",
158
- "Number",
159
- "Boolean",
160
- "Array",
161
- "Object",
162
- "RegExp",
163
- "Error",
164
- "TypeError",
165
- "ReferenceError",
166
- "SyntaxError"
351
+ /**
352
+ * 安全的全局对象列表
353
+ */ var SAFE_GLOBALS = [
354
+ 'console',
355
+ 'setTimeout',
356
+ 'setInterval',
357
+ 'clearTimeout',
358
+ 'clearInterval',
359
+ 'Math',
360
+ 'Date',
361
+ 'JSON',
362
+ 'parseInt',
363
+ 'parseFloat',
364
+ 'isNaN',
365
+ 'isFinite',
366
+ 'encodeURIComponent',
367
+ 'decodeURIComponent',
368
+ 'encodeURI',
369
+ 'decodeURI',
370
+ 'String',
371
+ 'Number',
372
+ 'Boolean',
373
+ 'Array',
374
+ 'Object',
375
+ 'RegExp',
376
+ 'Error',
377
+ 'TypeError',
378
+ 'ReferenceError',
379
+ 'SyntaxError'
167
380
  ];
168
- var ProxySandbox = class {
169
- constructor(config = {}) {
170
- this.isActive = false;
171
- this.timeoutId = null;
172
- this.startTime = 0;
173
- var _a, _b, _c, _d;
174
- this.config = {
175
- allowedGlobals: config.allowedGlobals || SAFE_GLOBALS,
176
- forbiddenGlobals: config.forbiddenGlobals || DANGEROUS_GLOBALS,
177
- allowConsole: (_a = config.allowConsole) != null ? _a : true,
178
- allowTimers: (_b = config.allowTimers) != null ? _b : true,
179
- timeout: config.timeout || 5e3,
180
- strictMode: (_c = config.strictMode) != null ? _c : true,
181
- customGlobals: config.customGlobals || {},
182
- allowDOM: (_d = config.allowDOM) != null ? _d : false,
183
- maxMemoryUsage: config.maxMemoryUsage || 10 * 1024 * 1024
184
- // 10MB
185
- };
186
- this.sandboxGlobal = this.createSandboxGlobal();
187
- this.globalProxy = this.createGlobalProxy();
188
- }
189
- /**
381
+ /**
382
+ * 基于 Proxy 的沙箱类
383
+ */ export var ProxySandbox = /*#__PURE__*/ function() {
384
+ "use strict";
385
+ function ProxySandbox() {
386
+ var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
387
+ _class_call_check(this, ProxySandbox);
388
+ _define_property(this, "config", void 0);
389
+ _define_property(this, "globalProxy", void 0);
390
+ _define_property(this, "sandboxGlobal", void 0);
391
+ _define_property(this, "isActive", false);
392
+ _define_property(this, "timeoutId", null);
393
+ _define_property(this, "startTime", 0);
394
+ var _config_allowConsole, _config_allowTimers, _config_strictMode, _config_allowDOM;
395
+ this.config = {
396
+ allowedGlobals: config.allowedGlobals || SAFE_GLOBALS,
397
+ forbiddenGlobals: config.forbiddenGlobals || DANGEROUS_GLOBALS,
398
+ allowConsole: (_config_allowConsole = config.allowConsole) !== null && _config_allowConsole !== void 0 ? _config_allowConsole : true,
399
+ allowTimers: (_config_allowTimers = config.allowTimers) !== null && _config_allowTimers !== void 0 ? _config_allowTimers : true,
400
+ timeout: config.timeout || 5000,
401
+ strictMode: (_config_strictMode = config.strictMode) !== null && _config_strictMode !== void 0 ? _config_strictMode : true,
402
+ customGlobals: config.customGlobals || {},
403
+ allowDOM: (_config_allowDOM = config.allowDOM) !== null && _config_allowDOM !== void 0 ? _config_allowDOM : false,
404
+ maxMemoryUsage: config.maxMemoryUsage || 10 * 1024 * 1024
405
+ };
406
+ this.sandboxGlobal = this.createSandboxGlobal();
407
+ this.globalProxy = this.createGlobalProxy();
408
+ }
409
+ _create_class(ProxySandbox, [
410
+ {
411
+ key: "createSafeDocument",
412
+ value: /**
190
413
  * 创建安全的 document 代理对象
191
414
  * 允许访问 document 但限制敏感操作
192
- */
193
- createSafeDocument() {
194
- const safeDocument = {};
195
- safeDocument.title = "Sandbox Document";
196
- safeDocument.readyState = "complete";
197
- safeDocument.documentURI = "about:blank";
198
- safeDocument.URL = "about:blank";
199
- safeDocument.domain = "";
200
- safeDocument.origin = "null";
201
- safeDocument.doctype = null;
202
- safeDocument.documentElement = null;
203
- safeDocument.body = null;
204
- safeDocument.head = null;
205
- Object.defineProperty(safeDocument, "cookie", {
206
- get: () => "",
207
- set: () => {
208
- },
209
- // 静默忽略设置
210
- enumerable: true,
211
- configurable: false
212
- });
213
- safeDocument.getElementById = () => null;
214
- safeDocument.getElementsByClassName = () => [];
215
- safeDocument.getElementsByTagName = () => [];
216
- safeDocument.getElementsByName = () => [];
217
- safeDocument.querySelector = () => null;
218
- safeDocument.querySelectorAll = () => [];
219
- safeDocument.createElement = (tagName) => ({
220
- tagName: tagName.toUpperCase(),
221
- id: "",
222
- className: "",
223
- innerHTML: "",
224
- textContent: "",
225
- setAttribute: () => {
226
- },
227
- getAttribute: () => null,
228
- removeAttribute: () => {
229
- },
230
- appendChild: () => {
231
- },
232
- removeChild: () => {
233
- },
234
- addEventListener: () => {
235
- },
236
- removeEventListener: () => {
237
- }
238
- });
239
- safeDocument.createTextNode = (data) => ({
240
- nodeType: 3,
241
- textContent: data,
242
- data
243
- });
244
- safeDocument.createDocumentFragment = () => ({
245
- nodeType: 11,
246
- appendChild: () => {
247
- },
248
- querySelector: () => null,
249
- querySelectorAll: () => []
250
- });
251
- return new Proxy(safeDocument, {
252
- get: (target, prop, receiver) => {
253
- const propStr = String(prop);
254
- const dangerousDocumentProps = [
255
- "location",
256
- "defaultView",
257
- "parentWindow",
258
- "implementation",
259
- "documentURI",
260
- "execCommand",
261
- "write",
262
- "writeln",
263
- "open",
264
- "close",
265
- "evaluate",
266
- "createRange",
267
- "getSelection",
268
- "elementsFromPoint",
269
- "elementFromPoint",
270
- "hasFocus",
271
- "hidden",
272
- "visibilityState"
273
- ];
274
- if (dangerousDocumentProps.includes(propStr)) {
275
- return void 0;
276
- }
277
- if (propStr in target) {
278
- return Reflect.get(target, prop, receiver);
279
- }
280
- return void 0;
281
- },
282
- set: (target, prop, value, receiver) => {
283
- const propStr = String(prop);
284
- const readOnlyProps = [
285
- "title",
286
- "readyState",
287
- "documentURI",
288
- "URL",
289
- "domain",
290
- "origin"
291
- ];
292
- if (readOnlyProps.includes(propStr)) {
293
- return false;
294
- }
295
- return Reflect.set(target, prop, value, receiver);
296
- },
297
- has: (target, prop) => {
298
- const propStr = String(prop);
299
- const dangerousDocumentProps = [
300
- "location",
301
- "defaultView",
302
- "parentWindow",
303
- "implementation",
304
- "execCommand",
305
- "write",
306
- "writeln",
307
- "open",
308
- "close"
309
- ];
310
- if (dangerousDocumentProps.includes(propStr)) {
311
- return false;
312
- }
313
- return Reflect.has(target, prop);
314
- }
315
- });
316
- }
317
- /**
415
+ */ function createSafeDocument() {
416
+ // 创建基础的安全 document 对象
417
+ var safeDocument = {};
418
+ // 安全的只读属性
419
+ safeDocument.title = 'Sandbox Document';
420
+ safeDocument.readyState = 'complete';
421
+ safeDocument.documentURI = 'about:blank';
422
+ safeDocument.URL = 'about:blank';
423
+ safeDocument.domain = '';
424
+ safeDocument.origin = 'null';
425
+ // 安全的文档信息
426
+ safeDocument.doctype = null;
427
+ safeDocument.documentElement = null;
428
+ safeDocument.body = null;
429
+ safeDocument.head = null;
430
+ // 模拟安全的 cookie(空)
431
+ Object.defineProperty(safeDocument, 'cookie', {
432
+ get: function() {
433
+ return '';
434
+ },
435
+ set: function() {},
436
+ enumerable: true,
437
+ configurable: false
438
+ });
439
+ // 提供安全的查询方法(返回 null 或空结果)
440
+ safeDocument.getElementById = function() {
441
+ return null;
442
+ };
443
+ safeDocument.getElementsByClassName = function() {
444
+ return [];
445
+ };
446
+ safeDocument.getElementsByTagName = function() {
447
+ return [];
448
+ };
449
+ safeDocument.getElementsByName = function() {
450
+ return [];
451
+ };
452
+ safeDocument.querySelector = function() {
453
+ return null;
454
+ };
455
+ safeDocument.querySelectorAll = function() {
456
+ return [];
457
+ };
458
+ // 提供安全的创建方法(返回模拟元素)
459
+ safeDocument.createElement = function(tagName) {
460
+ return {
461
+ tagName: tagName.toUpperCase(),
462
+ id: '',
463
+ className: '',
464
+ innerHTML: '',
465
+ textContent: '',
466
+ setAttribute: function() {},
467
+ getAttribute: function() {
468
+ return null;
469
+ },
470
+ removeAttribute: function() {},
471
+ appendChild: function() {},
472
+ removeChild: function() {},
473
+ addEventListener: function() {},
474
+ removeEventListener: function() {}
475
+ };
476
+ };
477
+ safeDocument.createTextNode = function(data) {
478
+ return {
479
+ nodeType: 3,
480
+ textContent: data,
481
+ data: data
482
+ };
483
+ };
484
+ safeDocument.createDocumentFragment = function() {
485
+ return {
486
+ nodeType: 11,
487
+ appendChild: function() {},
488
+ querySelector: function() {
489
+ return null;
490
+ },
491
+ querySelectorAll: function() {
492
+ return [];
493
+ }
494
+ };
495
+ };
496
+ // 创建代理来拦截其他属性访问
497
+ return new Proxy(safeDocument, {
498
+ get: function(target, prop, receiver) {
499
+ var propStr = String(prop);
500
+ // 阻止访问危险属性
501
+ var dangerousDocumentProps = [
502
+ 'location',
503
+ 'defaultView',
504
+ 'parentWindow',
505
+ 'implementation',
506
+ 'documentURI',
507
+ 'execCommand',
508
+ 'write',
509
+ 'writeln',
510
+ 'open',
511
+ 'close',
512
+ 'evaluate',
513
+ 'createRange',
514
+ 'getSelection',
515
+ 'elementsFromPoint',
516
+ 'elementFromPoint',
517
+ 'hasFocus',
518
+ 'hidden',
519
+ 'visibilityState'
520
+ ];
521
+ if (dangerousDocumentProps.includes(propStr)) {
522
+ return undefined;
523
+ }
524
+ // 对于已定义的安全属性,返回实际值
525
+ if (propStr in target) {
526
+ return Reflect.get(target, prop, receiver);
527
+ }
528
+ // 对于其他属性,返回 undefined
529
+ return undefined;
530
+ },
531
+ set: function(target, prop, value, receiver) {
532
+ var propStr = String(prop);
533
+ // 阻止设置敏感属性
534
+ var readOnlyProps = [
535
+ 'title',
536
+ 'readyState',
537
+ 'documentURI',
538
+ 'URL',
539
+ 'domain',
540
+ 'origin'
541
+ ];
542
+ if (readOnlyProps.includes(propStr)) {
543
+ return false; // 静默失败
544
+ }
545
+ // 允许设置其他属性(在沙箱对象内)
546
+ return Reflect.set(target, prop, value, receiver);
547
+ },
548
+ has: function(target, prop) {
549
+ var propStr = String(prop);
550
+ // 危险属性始终返回 false
551
+ var dangerousDocumentProps = [
552
+ 'location',
553
+ 'defaultView',
554
+ 'parentWindow',
555
+ 'implementation',
556
+ 'execCommand',
557
+ 'write',
558
+ 'writeln',
559
+ 'open',
560
+ 'close'
561
+ ];
562
+ if (dangerousDocumentProps.includes(propStr)) {
563
+ return false;
564
+ }
565
+ return Reflect.has(target, prop);
566
+ }
567
+ });
568
+ }
569
+ },
570
+ {
571
+ key: "createSafeWindow",
572
+ value: /**
318
573
  * 创建安全的 window 代理对象
319
574
  * 允许访问 window 但限制敏感信息
320
- */
321
- createSafeWindow(safeDocument) {
322
- const sensitiveProperties = [
323
- "cookie",
324
- "localStorage",
325
- "sessionStorage",
326
- "indexedDB",
327
- "location",
328
- "history",
329
- "navigator",
330
- "parent",
331
- "top",
332
- "frames",
333
- "opener",
334
- "external",
335
- "chrome",
336
- "safari",
337
- "opera",
338
- "moz"
339
- ];
340
- const safeWindow = {};
341
- if (typeof window !== "undefined") {
342
- safeWindow.innerWidth = 1024;
343
- safeWindow.innerHeight = 768;
344
- safeWindow.outerWidth = 1024;
345
- safeWindow.outerHeight = 768;
346
- safeWindow.devicePixelRatio = 1;
347
- safeWindow.screen = {
348
- width: 1920,
349
- height: 1080,
350
- availWidth: 1920,
351
- availHeight: 1040,
352
- colorDepth: 24,
353
- pixelDepth: 24
354
- };
355
- }
356
- safeWindow.Array = Array;
357
- safeWindow.Object = Object;
358
- safeWindow.String = String;
359
- safeWindow.Number = Number;
360
- safeWindow.Boolean = Boolean;
361
- safeWindow.Date = Date;
362
- safeWindow.Math = Math;
363
- safeWindow.JSON = JSON;
364
- safeWindow.RegExp = RegExp;
365
- safeWindow.Error = Error;
366
- safeWindow.TypeError = TypeError;
367
- safeWindow.ReferenceError = ReferenceError;
368
- safeWindow.SyntaxError = SyntaxError;
369
- safeWindow.parseInt = parseInt;
370
- safeWindow.parseFloat = parseFloat;
371
- safeWindow.isNaN = isNaN;
372
- safeWindow.isFinite = isFinite;
373
- safeWindow.encodeURIComponent = encodeURIComponent;
374
- safeWindow.decodeURIComponent = decodeURIComponent;
375
- safeWindow.encodeURI = encodeURI;
376
- safeWindow.decodeURI = decodeURI;
377
- safeWindow.document = safeDocument || this.createSafeDocument();
378
- if (this.config.allowConsole) {
379
- safeWindow.console = {
380
- log: console.log.bind(console),
381
- warn: console.warn.bind(console),
382
- error: console.error.bind(console),
383
- info: console.info.bind(console),
384
- debug: console.debug.bind(console)
385
- };
386
- }
387
- return new Proxy(safeWindow, {
388
- get: (target, prop, receiver) => {
389
- const propStr = String(prop);
390
- if (sensitiveProperties.includes(propStr)) {
391
- switch (propStr) {
392
- case "cookie":
393
- return "";
394
- case "localStorage":
395
- case "sessionStorage":
396
- return {
397
- length: 0,
398
- getItem: () => null,
399
- setItem: () => {
400
- },
401
- removeItem: () => {
402
- },
403
- clear: () => {
404
- },
405
- key: () => null
406
- };
407
- case "location":
408
- return {
409
- href: "about:blank",
410
- origin: "null",
411
- protocol: "about:",
412
- host: "",
413
- hostname: "",
414
- port: "",
415
- pathname: "blank",
416
- search: "",
417
- hash: ""
418
- };
419
- case "navigator":
420
- return {
421
- userAgent: "Sandbox/1.0",
422
- language: "en-US",
423
- languages: ["en-US"],
424
- platform: "Sandbox",
425
- cookieEnabled: false,
426
- onLine: true
427
- };
428
- default:
429
- return void 0;
430
- }
431
- }
432
- if (propStr in target) {
433
- return Reflect.get(target, prop, receiver);
434
- }
435
- return void 0;
436
- },
437
- set: (target, prop, value, receiver) => {
438
- const propStr = String(prop);
439
- if (sensitiveProperties.includes(propStr)) {
440
- return false;
441
- }
442
- return Reflect.set(target, prop, value, receiver);
443
- },
444
- has: (target, prop) => {
445
- const propStr = String(prop);
446
- if (sensitiveProperties.includes(propStr)) {
447
- return false;
448
- }
449
- return Reflect.has(target, prop);
450
- },
451
- ownKeys: (target) => {
452
- const allKeys = Reflect.ownKeys(target);
453
- return allKeys.filter(
454
- (key) => !sensitiveProperties.includes(String(key))
455
- );
456
- },
457
- getOwnPropertyDescriptor: (target, prop) => {
458
- const propStr = String(prop);
459
- if (sensitiveProperties.includes(propStr)) {
460
- return void 0;
461
- }
462
- return Reflect.getOwnPropertyDescriptor(target, prop);
463
- }
464
- });
465
- }
466
- /**
575
+ */ function createSafeWindow(safeDocument) {
576
+ // 敏感属性列表(将被设置为空或限制访问)
577
+ var sensitiveProperties = [
578
+ 'cookie',
579
+ 'localStorage',
580
+ 'sessionStorage',
581
+ 'indexedDB',
582
+ 'location',
583
+ 'history',
584
+ 'navigator',
585
+ 'parent',
586
+ 'top',
587
+ 'frames',
588
+ 'opener',
589
+ 'external',
590
+ 'chrome',
591
+ 'safari',
592
+ 'opera',
593
+ 'moz'
594
+ ];
595
+ // 创建基础的安全对象
596
+ var safeWindow = {};
597
+ // 如果在浏览器环境中,添加一些安全的 window 属性
598
+ if (typeof window !== 'undefined') {
599
+ // 添加安全的尺寸信息
600
+ safeWindow.innerWidth = 1024; // 默认值
601
+ safeWindow.innerHeight = 768;
602
+ safeWindow.outerWidth = 1024;
603
+ safeWindow.outerHeight = 768;
604
+ safeWindow.devicePixelRatio = 1;
605
+ // 添加安全的 screen 信息(静态值)
606
+ safeWindow.screen = {
607
+ width: 1920,
608
+ height: 1080,
609
+ availWidth: 1920,
610
+ availHeight: 1040,
611
+ colorDepth: 24,
612
+ pixelDepth: 24
613
+ };
614
+ }
615
+ // 添加标准的 JavaScript 全局对象
616
+ safeWindow.Array = Array;
617
+ safeWindow.Object = Object;
618
+ safeWindow.String = String;
619
+ safeWindow.Number = Number;
620
+ safeWindow.Boolean = Boolean;
621
+ safeWindow.Date = Date;
622
+ safeWindow.Math = Math;
623
+ safeWindow.JSON = JSON;
624
+ safeWindow.RegExp = RegExp;
625
+ safeWindow.Error = Error;
626
+ safeWindow.TypeError = TypeError;
627
+ safeWindow.ReferenceError = ReferenceError;
628
+ safeWindow.SyntaxError = SyntaxError;
629
+ safeWindow.parseInt = parseInt;
630
+ safeWindow.parseFloat = parseFloat;
631
+ safeWindow.isNaN = isNaN;
632
+ safeWindow.isFinite = isFinite;
633
+ safeWindow.encodeURIComponent = encodeURIComponent;
634
+ safeWindow.decodeURIComponent = decodeURIComponent;
635
+ safeWindow.encodeURI = encodeURI;
636
+ safeWindow.decodeURI = decodeURI;
637
+ // 添加安全的 document 对象(使用传入的或创建新的)
638
+ safeWindow.document = safeDocument || this.createSafeDocument();
639
+ // 提供安全的控制台(如果允许)
640
+ if (this.config.allowConsole) {
641
+ safeWindow.console = {
642
+ log: console.log.bind(console),
643
+ warn: console.warn.bind(console),
644
+ error: console.error.bind(console),
645
+ info: console.info.bind(console),
646
+ debug: console.debug.bind(console)
647
+ };
648
+ }
649
+ // 创建代理来拦截属性访问
650
+ return new Proxy(safeWindow, {
651
+ get: function(target, prop, receiver) {
652
+ var propStr = String(prop);
653
+ // 检查是否是敏感属性
654
+ if (sensitiveProperties.includes(propStr)) {
655
+ // 为敏感属性返回空或安全的默认值
656
+ switch(propStr){
657
+ case 'cookie':
658
+ return ''; // 空 cookie
659
+ case 'localStorage':
660
+ case 'sessionStorage':
661
+ // 返回一个模拟的空存储对象
662
+ return {
663
+ length: 0,
664
+ getItem: function() {
665
+ return null;
666
+ },
667
+ setItem: function() {},
668
+ removeItem: function() {},
669
+ clear: function() {},
670
+ key: function() {
671
+ return null;
672
+ }
673
+ };
674
+ case 'location':
675
+ return {
676
+ href: 'about:blank',
677
+ origin: 'null',
678
+ protocol: 'about:',
679
+ host: '',
680
+ hostname: '',
681
+ port: '',
682
+ pathname: 'blank',
683
+ search: '',
684
+ hash: ''
685
+ };
686
+ case 'navigator':
687
+ return {
688
+ userAgent: 'Sandbox/1.0',
689
+ language: 'en-US',
690
+ languages: [
691
+ 'en-US'
692
+ ],
693
+ platform: 'Sandbox',
694
+ cookieEnabled: false,
695
+ onLine: true
696
+ };
697
+ default:
698
+ return undefined;
699
+ }
700
+ }
701
+ // 对于安全属性,返回实际值
702
+ if (propStr in target) {
703
+ return Reflect.get(target, prop, receiver);
704
+ }
705
+ // 对于其他属性,返回 undefined
706
+ return undefined;
707
+ },
708
+ set: function(target, prop, value, receiver) {
709
+ var propStr = String(prop);
710
+ // 禁止设置敏感属性
711
+ if (sensitiveProperties.includes(propStr)) {
712
+ return false; // 静默失败
713
+ }
714
+ // 允许设置其他属性(在沙箱对象内)
715
+ return Reflect.set(target, prop, value, receiver);
716
+ },
717
+ has: function(target, prop) {
718
+ var propStr = String(prop);
719
+ // 敏感属性始终返回 false
720
+ if (sensitiveProperties.includes(propStr)) {
721
+ return false;
722
+ }
723
+ return Reflect.has(target, prop);
724
+ },
725
+ ownKeys: function(target) {
726
+ // 只返回安全属性的键
727
+ var allKeys = Reflect.ownKeys(target);
728
+ return allKeys.filter(function(key) {
729
+ return !sensitiveProperties.includes(String(key));
730
+ });
731
+ },
732
+ getOwnPropertyDescriptor: function(target, prop) {
733
+ var propStr = String(prop);
734
+ if (sensitiveProperties.includes(propStr)) {
735
+ return undefined;
736
+ }
737
+ return Reflect.getOwnPropertyDescriptor(target, prop);
738
+ }
739
+ });
740
+ }
741
+ },
742
+ {
743
+ key: "createSandboxGlobal",
744
+ value: /**
467
745
  * 创建安全的沙箱全局对象
468
- */
469
- createSandboxGlobal() {
470
- const sandboxGlobal = {};
471
- for (const globalName of this.config.allowedGlobals) {
472
- if (globalName in globalThis) {
473
- sandboxGlobal[globalName] = globalThis[globalName];
474
- }
475
- }
476
- Object.assign(sandboxGlobal, this.config.customGlobals);
477
- const safeDocument = this.createSafeDocument();
478
- const safeWindow = this.createSafeWindow(safeDocument);
479
- sandboxGlobal.window = safeWindow;
480
- sandboxGlobal.document = safeDocument;
481
- if (this.config.allowConsole) {
482
- sandboxGlobal.console = this.createSafeConsole();
483
- }
484
- if (this.config.allowTimers) {
485
- sandboxGlobal.setTimeout = this.createSafeTimeout();
486
- sandboxGlobal.setInterval = this.createSafeInterval();
487
- sandboxGlobal.clearTimeout = clearTimeout;
488
- sandboxGlobal.clearInterval = clearInterval;
489
- }
490
- sandboxGlobal.__checkInstructions = () => {
491
- };
492
- return sandboxGlobal;
493
- }
494
- /**
746
+ */ function createSandboxGlobal() {
747
+ var sandboxGlobal = {};
748
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
749
+ try {
750
+ // 添加允许的全局对象
751
+ for(var _iterator = this.config.allowedGlobals[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
752
+ var globalName = _step.value;
753
+ if (globalName in globalThis) {
754
+ sandboxGlobal[globalName] = globalThis[globalName];
755
+ }
756
+ }
757
+ } catch (err) {
758
+ _didIteratorError = true;
759
+ _iteratorError = err;
760
+ } finally{
761
+ try {
762
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
763
+ _iterator.return();
764
+ }
765
+ } finally{
766
+ if (_didIteratorError) {
767
+ throw _iteratorError;
768
+ }
769
+ }
770
+ }
771
+ // 添加自定义全局变量
772
+ Object.assign(sandboxGlobal, this.config.customGlobals);
773
+ // 创建安全的 document 对象(确保只创建一次)
774
+ var safeDocument = this.createSafeDocument();
775
+ // 添加安全的 window 对象(总是可用)
776
+ var safeWindow = this.createSafeWindow(safeDocument);
777
+ sandboxGlobal.window = safeWindow;
778
+ // 添加安全的 document 对象(总是可用)
779
+ sandboxGlobal.document = safeDocument;
780
+ // 条件性添加 console
781
+ if (this.config.allowConsole) {
782
+ sandboxGlobal.console = this.createSafeConsole();
783
+ }
784
+ // 条件性添加定时器
785
+ if (this.config.allowTimers) {
786
+ sandboxGlobal.setTimeout = this.createSafeTimeout();
787
+ sandboxGlobal.setInterval = this.createSafeInterval();
788
+ sandboxGlobal.clearTimeout = clearTimeout;
789
+ sandboxGlobal.clearInterval = clearInterval;
790
+ }
791
+ // 添加指令检查函数(用于超时控制)
792
+ sandboxGlobal.__checkInstructions = function() {
793
+ // 这个函数会在 executeWithInstructionLimit 中被替换
794
+ };
795
+ return sandboxGlobal;
796
+ }
797
+ },
798
+ {
799
+ key: "createSafeConsole",
800
+ value: /**
495
801
  * 创建安全的 console 对象
496
- */
497
- createSafeConsole() {
498
- return {
499
- log: (...args) => console.log("[Sandbox]", ...args),
500
- warn: (...args) => console.warn("[Sandbox]", ...args),
501
- error: (...args) => console.error("[Sandbox]", ...args),
502
- info: (...args) => console.info("[Sandbox]", ...args),
503
- debug: (...args) => console.debug("[Sandbox]", ...args)
504
- };
505
- }
506
- /**
802
+ */ function createSafeConsole() {
803
+ var _console, _console1, _console2, _console3, _console4;
804
+ return {
805
+ log: function() {
806
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
807
+ args[_key] = arguments[_key];
808
+ }
809
+ return (_console = console).log.apply(_console, [
810
+ '[Sandbox]'
811
+ ].concat(_to_consumable_array(args)));
812
+ },
813
+ warn: function() {
814
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
815
+ args[_key] = arguments[_key];
816
+ }
817
+ return (_console1 = console).warn.apply(_console1, [
818
+ '[Sandbox]'
819
+ ].concat(_to_consumable_array(args)));
820
+ },
821
+ error: function() {
822
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
823
+ args[_key] = arguments[_key];
824
+ }
825
+ return (_console2 = console).error.apply(_console2, [
826
+ '[Sandbox]'
827
+ ].concat(_to_consumable_array(args)));
828
+ },
829
+ info: function() {
830
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
831
+ args[_key] = arguments[_key];
832
+ }
833
+ return (_console3 = console).info.apply(_console3, [
834
+ '[Sandbox]'
835
+ ].concat(_to_consumable_array(args)));
836
+ },
837
+ debug: function() {
838
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
839
+ args[_key] = arguments[_key];
840
+ }
841
+ return (_console4 = console).debug.apply(_console4, [
842
+ '[Sandbox]'
843
+ ].concat(_to_consumable_array(args)));
844
+ }
845
+ };
846
+ }
847
+ },
848
+ {
849
+ key: "createSafeTimeout",
850
+ value: /**
507
851
  * 创建安全的 setTimeout
508
- */
509
- createSafeTimeout() {
510
- return (callback, delay, ...args) => {
511
- if (typeof callback !== "function") {
512
- throw new TypeError("Callback must be a function");
513
- }
514
- const safeCallback = () => {
515
- try {
516
- callback.apply(null, args);
517
- } catch (error) {
518
- console.error("[Sandbox] Timer callback error:", error);
519
- }
520
- };
521
- return setTimeout(safeCallback, Math.min(delay, 1e3));
522
- };
523
- }
524
- /**
852
+ */ function createSafeTimeout() {
853
+ return function(callback, delay) {
854
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
855
+ args[_key - 2] = arguments[_key];
856
+ }
857
+ if (typeof callback !== 'function') {
858
+ throw new TypeError('Callback must be a function');
859
+ }
860
+ var safeCallback = function() {
861
+ try {
862
+ callback.apply(null, args);
863
+ } catch (error) {
864
+ console.error('[Sandbox] Timer callback error:', error);
865
+ }
866
+ };
867
+ return setTimeout(safeCallback, Math.min(delay, 1000)); // 最大延迟1秒
868
+ };
869
+ }
870
+ },
871
+ {
872
+ key: "createSafeInterval",
873
+ value: /**
525
874
  * 创建安全的 setInterval
526
- */
527
- createSafeInterval() {
528
- return (callback, delay, ...args) => {
529
- if (typeof callback !== "function") {
530
- throw new TypeError("Callback must be a function");
531
- }
532
- const safeCallback = () => {
533
- try {
534
- callback.apply(null, args);
535
- } catch (error) {
536
- console.error("[Sandbox] Interval callback error:", error);
537
- }
538
- };
539
- return setInterval(safeCallback, Math.max(delay, 100));
540
- };
541
- }
542
- /**
875
+ */ function createSafeInterval() {
876
+ return function(callback, delay) {
877
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
878
+ args[_key - 2] = arguments[_key];
879
+ }
880
+ if (typeof callback !== 'function') {
881
+ throw new TypeError('Callback must be a function');
882
+ }
883
+ var safeCallback = function() {
884
+ try {
885
+ callback.apply(null, args);
886
+ } catch (error) {
887
+ console.error('[Sandbox] Interval callback error:', error);
888
+ }
889
+ };
890
+ return setInterval(safeCallback, Math.max(delay, 100)); // 最小间隔100ms
891
+ };
892
+ }
893
+ },
894
+ {
895
+ key: "createGlobalProxy",
896
+ value: /**
543
897
  * 创建全局对象的 Proxy
544
- */
545
- createGlobalProxy() {
546
- return new Proxy(this.sandboxGlobal, {
547
- get: (target, prop, receiver) => {
548
- const propStr = String(prop);
549
- if (this.config.forbiddenGlobals.includes(propStr)) {
550
- throw new ReferenceError(
551
- `Access to '${propStr}' is not allowed in sandbox`
552
- );
553
- }
554
- if (propStr === "__checkInstructions") {
555
- return Reflect.get(target, prop, receiver);
556
- }
557
- if (this.config.allowedGlobals.includes(propStr)) {
558
- if (propStr in target) {
559
- return Reflect.get(target, prop, receiver);
560
- }
561
- if (propStr === "window" || propStr === "global" || propStr === "globalThis") {
562
- return receiver;
563
- }
564
- }
565
- if (propStr in this.config.customGlobals) {
566
- return Reflect.get(target, prop, receiver);
567
- }
568
- return void 0;
569
- },
570
- set: (target, prop, value, receiver) => {
571
- const propStr = String(prop);
572
- if (this.config.forbiddenGlobals.includes(propStr)) {
573
- throw new ReferenceError(
574
- `Setting '${propStr}' is not allowed in sandbox`
575
- );
576
- }
577
- return Reflect.set(target, prop, value, receiver);
578
- },
579
- has: (target, prop) => {
580
- const propStr = String(prop);
581
- if (this.config.forbiddenGlobals.includes(propStr)) {
582
- return false;
583
- }
584
- return this.config.allowedGlobals.includes(propStr) || Reflect.has(target, prop);
585
- },
586
- ownKeys: (target) => {
587
- const allKeys = Reflect.ownKeys(target);
588
- return allKeys.filter(
589
- (key) => !this.config.forbiddenGlobals.includes(String(key))
590
- );
591
- },
592
- getOwnPropertyDescriptor: (target, prop) => {
593
- const propStr = String(prop);
594
- if (this.config.forbiddenGlobals.includes(propStr)) {
595
- return void 0;
596
- }
597
- return Reflect.getOwnPropertyDescriptor(target, prop);
598
- }
599
- });
600
- }
601
- /**
898
+ */ function createGlobalProxy() {
899
+ var _this = this;
900
+ return new Proxy(this.sandboxGlobal, {
901
+ get: function(target, prop, receiver) {
902
+ var propStr = String(prop);
903
+ // 检查是否在禁止列表中
904
+ if (_this.config.forbiddenGlobals.includes(propStr)) {
905
+ throw new ReferenceError("Access to '".concat(propStr, "' is not allowed in sandbox"));
906
+ }
907
+ // 允许访问内部功能函数
908
+ if (propStr === '__checkInstructions') {
909
+ return Reflect.get(target, prop, receiver);
910
+ }
911
+ // 检查是否在允许列表中
912
+ if (_this.config.allowedGlobals.includes(propStr)) {
913
+ if (propStr in target) {
914
+ return Reflect.get(target, prop, receiver);
915
+ }
916
+ // 某些特殊的全局对象需要特殊处理
917
+ if (propStr === 'window' || propStr === 'global' || propStr === 'globalThis') {
918
+ return receiver; // 返回代理对象本身
919
+ }
920
+ }
921
+ // 检查自定义全局变量
922
+ if (propStr in _this.config.customGlobals) {
923
+ return Reflect.get(target, prop, receiver);
924
+ }
925
+ // 如果不在任何允许的列表中,返回 undefined
926
+ return undefined;
927
+ },
928
+ set: function(target, prop, value, receiver) {
929
+ var propStr = String(prop);
930
+ // 检查是否在禁止列表中
931
+ if (_this.config.forbiddenGlobals.includes(propStr)) {
932
+ throw new ReferenceError("Setting '".concat(propStr, "' is not allowed in sandbox"));
933
+ }
934
+ // 只允许设置已存在的属性或新的变量
935
+ return Reflect.set(target, prop, value, receiver);
936
+ },
937
+ has: function(target, prop) {
938
+ var propStr = String(prop);
939
+ // 如果在禁止列表中,返回 false
940
+ if (_this.config.forbiddenGlobals.includes(propStr)) {
941
+ return false;
942
+ }
943
+ // 如果在允许列表中或目标对象中,返回 true
944
+ return _this.config.allowedGlobals.includes(propStr) || Reflect.has(target, prop);
945
+ },
946
+ ownKeys: function(target) {
947
+ // 只返回允许的属性键
948
+ var allKeys = Reflect.ownKeys(target);
949
+ return allKeys.filter(function(key) {
950
+ return !_this.config.forbiddenGlobals.includes(String(key));
951
+ });
952
+ },
953
+ getOwnPropertyDescriptor: function(target, prop) {
954
+ var propStr = String(prop);
955
+ if (_this.config.forbiddenGlobals.includes(propStr)) {
956
+ return undefined;
957
+ }
958
+ return Reflect.getOwnPropertyDescriptor(target, prop);
959
+ }
960
+ });
961
+ }
962
+ },
963
+ {
964
+ key: "execute",
965
+ value: /**
602
966
  * 在沙箱中执行代码
603
- */
604
- execute(code, injectedParams) {
605
- return __async(this, null, function* () {
606
- this.startTime = performance.now();
607
- this.isActive = true;
608
- let result;
609
- let error;
610
- let success = false;
611
- try {
612
- if (typeof Worker !== "undefined" && typeof URL !== "undefined") {
613
- result = yield this.executeWithWorker(code, injectedParams);
614
- } else {
615
- if (this.isObviousInfiniteLoop(code)) {
616
- result = yield this.executeWithInstructionLimit(code, injectedParams);
617
- } else {
618
- result = yield this.executeWithTimeout(code, injectedParams);
619
- }
620
- }
621
- success = true;
622
- } catch (err) {
623
- error = err instanceof Error ? err : new Error(String(err));
624
- success = false;
625
- } finally {
626
- this.cleanup();
627
- }
628
- const executionTime = performance.now() - this.startTime;
629
- return {
630
- result,
631
- success,
632
- error,
633
- executionTime,
634
- memoryUsage: this.getMemoryUsage()
635
- };
636
- });
637
- }
638
- /**
967
+ */ function execute(code, injectedParams) {
968
+ var _this = this;
969
+ return _async_to_generator(function() {
970
+ var result, error, success, err, executionTime;
971
+ return _ts_generator(this, function(_state) {
972
+ switch(_state.label){
973
+ case 0:
974
+ _this.startTime = performance.now();
975
+ _this.isActive = true;
976
+ success = false;
977
+ _state.label = 1;
978
+ case 1:
979
+ _state.trys.push([
980
+ 1,
981
+ 8,
982
+ 9,
983
+ 10
984
+ ]);
985
+ if (!(typeof Worker !== 'undefined' && typeof URL !== 'undefined')) return [
986
+ 3,
987
+ 3
988
+ ];
989
+ return [
990
+ 4,
991
+ _this.executeWithWorker(code, injectedParams)
992
+ ];
993
+ case 2:
994
+ result = _state.sent();
995
+ return [
996
+ 3,
997
+ 7
998
+ ];
999
+ case 3:
1000
+ if (!_this.isObviousInfiniteLoop(code)) return [
1001
+ 3,
1002
+ 5
1003
+ ];
1004
+ return [
1005
+ 4,
1006
+ _this.executeWithInstructionLimit(code, injectedParams)
1007
+ ];
1008
+ case 4:
1009
+ // 只对明显的死循环使用指令计数
1010
+ result = _state.sent();
1011
+ return [
1012
+ 3,
1013
+ 7
1014
+ ];
1015
+ case 5:
1016
+ return [
1017
+ 4,
1018
+ _this.executeWithTimeout(code, injectedParams)
1019
+ ];
1020
+ case 6:
1021
+ // 对正常代码直接执行,但有超时保护
1022
+ result = _state.sent();
1023
+ _state.label = 7;
1024
+ case 7:
1025
+ success = true;
1026
+ return [
1027
+ 3,
1028
+ 10
1029
+ ];
1030
+ case 8:
1031
+ err = _state.sent();
1032
+ error = err instanceof Error ? err : new Error(String(err));
1033
+ success = false;
1034
+ return [
1035
+ 3,
1036
+ 10
1037
+ ];
1038
+ case 9:
1039
+ _this.cleanup();
1040
+ return [
1041
+ 7
1042
+ ];
1043
+ case 10:
1044
+ executionTime = performance.now() - _this.startTime;
1045
+ return [
1046
+ 2,
1047
+ {
1048
+ result: result,
1049
+ success: success,
1050
+ error: error,
1051
+ executionTime: executionTime,
1052
+ memoryUsage: _this.getMemoryUsage()
1053
+ }
1054
+ ];
1055
+ }
1056
+ });
1057
+ })();
1058
+ }
1059
+ },
1060
+ {
1061
+ key: "isObviousInfiniteLoop",
1062
+ value: /**
639
1063
  * 检查是否是明显的死循环
640
- */
641
- isObviousInfiniteLoop(code) {
642
- const infiniteLoopPatterns = [
643
- /while\s*\(\s*true\s*\)/,
644
- /for\s*\(\s*;\s*;\s*\)/,
645
- /while\s*\(\s*1\s*\)/,
646
- /while\s*\(\s*!false\s*\)/,
647
- /do\s*\{[^}]*\}\s*while\s*\(\s*true\s*\)/,
648
- /do\s*\{[^}]*\}\s*while\s*\(\s*1\s*\)/
649
- ];
650
- return infiniteLoopPatterns.some((pattern) => pattern.test(code));
651
- }
652
- /**
1064
+ */ function isObviousInfiniteLoop(code) {
1065
+ // 简单的模式匹配检测明显的死循环
1066
+ var infiniteLoopPatterns = [
1067
+ /while\s*\(\s*true\s*\)/,
1068
+ /for\s*\(\s*;\s*;\s*\)/,
1069
+ /while\s*\(\s*1\s*\)/,
1070
+ /while\s*\(\s*!false\s*\)/,
1071
+ /do\s*\{[^}]*\}\s*while\s*\(\s*true\s*\)/,
1072
+ /do\s*\{[^}]*\}\s*while\s*\(\s*1\s*\)/
1073
+ ];
1074
+ return infiniteLoopPatterns.some(function(pattern) {
1075
+ return pattern.test(code);
1076
+ });
1077
+ }
1078
+ },
1079
+ {
1080
+ key: "executeWithTimeout",
1081
+ value: /**
653
1082
  * 带超时的普通执行
654
1083
  * 注意:对于同步死循环,setTimeout 无法中断,需要使用 Worker 或指令计数
655
1084
  * 这个方法只适用于不包含死循环的代码
656
- */
657
- executeWithTimeout(code, injectedParams) {
658
- return __async(this, null, function* () {
659
- return new Promise((resolve, reject) => {
660
- const timeoutId = setTimeout(() => {
661
- reject(
662
- new Error(`Code execution timeout after ${this.config.timeout}ms`)
663
- );
664
- }, this.config.timeout);
665
- try {
666
- const result = this.executeCode(code, injectedParams);
667
- clearTimeout(timeoutId);
668
- resolve(result);
669
- } catch (error) {
670
- clearTimeout(timeoutId);
671
- reject(error);
672
- }
673
- });
674
- });
675
- }
676
- /**
1085
+ */ function executeWithTimeout(code, injectedParams) {
1086
+ var _this = this;
1087
+ return _async_to_generator(function() {
1088
+ return _ts_generator(this, function(_state) {
1089
+ return [
1090
+ 2,
1091
+ new Promise(function(resolve, reject) {
1092
+ var timeoutId = setTimeout(function() {
1093
+ reject(new Error("Code execution timeout after ".concat(_this.config.timeout, "ms")));
1094
+ }, _this.config.timeout);
1095
+ try {
1096
+ var result = _this.executeCode(code, injectedParams);
1097
+ clearTimeout(timeoutId);
1098
+ resolve(result);
1099
+ } catch (error) {
1100
+ clearTimeout(timeoutId);
1101
+ reject(error);
1102
+ }
1103
+ })
1104
+ ];
1105
+ });
1106
+ })();
1107
+ }
1108
+ },
1109
+ {
1110
+ key: "executeWithInstructionLimit",
1111
+ value: /**
677
1112
  * 使用指令计数限制执行时间
678
1113
  * 这是处理同步死循环的唯一方法(在不使用 Worker 的情况下)
679
- */
680
- executeWithInstructionLimit(code, injectedParams) {
681
- return __async(this, null, function* () {
682
- return new Promise((resolve, reject) => {
683
- const maxInstructions = 1e4;
684
- let instructionCount = 0;
685
- const startTime = performance.now();
686
- let timeoutId = null;
687
- const instrumentedCode = this.instrumentCode(code);
688
- const originalGlobal = this.sandboxGlobal.__checkInstructions;
689
- this.sandboxGlobal.__checkInstructions = () => {
690
- instructionCount++;
691
- const elapsed = performance.now() - startTime;
692
- if (elapsed > this.config.timeout) {
693
- throw new Error(
694
- `Code execution timeout after ${this.config.timeout}ms`
695
- );
696
- }
697
- if (instructionCount > maxInstructions) {
698
- throw new Error(
699
- `Code execution exceeded maximum instruction limit (${maxInstructions})`
700
- );
701
- }
702
- };
703
- timeoutId = setTimeout(() => {
704
- reject(
705
- new Error(`Code execution timeout after ${this.config.timeout}ms`)
706
- );
707
- }, this.config.timeout);
708
- try {
709
- const result = this.executeCode(instrumentedCode, injectedParams);
710
- if (timeoutId)
711
- clearTimeout(timeoutId);
712
- resolve(result);
713
- } catch (error) {
714
- if (timeoutId)
715
- clearTimeout(timeoutId);
716
- reject(error);
717
- } finally {
718
- if (originalGlobal) {
719
- this.sandboxGlobal.__checkInstructions = originalGlobal;
720
- } else {
721
- delete this.sandboxGlobal.__checkInstructions;
722
- }
723
- }
724
- });
725
- });
726
- }
727
- /**
1114
+ */ function executeWithInstructionLimit(code, injectedParams) {
1115
+ var _this = this;
1116
+ return _async_to_generator(function() {
1117
+ return _ts_generator(this, function(_state) {
1118
+ return [
1119
+ 2,
1120
+ new Promise(function(resolve, reject) {
1121
+ var maxInstructions = 10000; // 降低最大指令数,更快检测死循环
1122
+ var instructionCount = 0;
1123
+ var startTime = performance.now();
1124
+ var timeoutId = null;
1125
+ // 注入指令计数器
1126
+ var instrumentedCode = _this.instrumentCode(code);
1127
+ // 创建全局计数器函数
1128
+ var originalGlobal = _this.sandboxGlobal.__checkInstructions;
1129
+ _this.sandboxGlobal.__checkInstructions = function() {
1130
+ instructionCount++;
1131
+ var elapsed = performance.now() - startTime;
1132
+ // 检查时间超时
1133
+ if (elapsed > _this.config.timeout) {
1134
+ throw new Error("Code execution timeout after ".concat(_this.config.timeout, "ms"));
1135
+ }
1136
+ // 如果指令数超过限制,说明可能是死循环
1137
+ if (instructionCount > maxInstructions) {
1138
+ throw new Error("Code execution exceeded maximum instruction limit (".concat(maxInstructions, ")"));
1139
+ }
1140
+ };
1141
+ // 设置超时保护,防止指令检查没有被调用
1142
+ timeoutId = setTimeout(function() {
1143
+ reject(new Error("Code execution timeout after ".concat(_this.config.timeout, "ms")));
1144
+ }, _this.config.timeout);
1145
+ try {
1146
+ var result = _this.executeCode(instrumentedCode, injectedParams);
1147
+ if (timeoutId) clearTimeout(timeoutId);
1148
+ resolve(result);
1149
+ } catch (error) {
1150
+ if (timeoutId) clearTimeout(timeoutId);
1151
+ reject(error);
1152
+ } finally{
1153
+ // 恢复原始状态
1154
+ if (originalGlobal) {
1155
+ _this.sandboxGlobal.__checkInstructions = originalGlobal;
1156
+ } else {
1157
+ delete _this.sandboxGlobal.__checkInstructions;
1158
+ }
1159
+ }
1160
+ })
1161
+ ];
1162
+ });
1163
+ })();
1164
+ }
1165
+ },
1166
+ {
1167
+ key: "instrumentCode",
1168
+ value: /**
728
1169
  * 在代码中注入指令计数器
729
1170
  * 在循环体内部注入检查点,确保死循环能够被检测到
730
- */
731
- instrumentCode(code) {
732
- let instrumented = code;
733
- instrumented = instrumented.replace(
734
- /(\bfor\s*\([^)]*\)\s*\{)/g,
735
- "$1\n __checkInstructions();"
736
- );
737
- instrumented = instrumented.replace(
738
- /(\bwhile\s*\([^)]*\)\s*\{)/g,
739
- "$1\n __checkInstructions();"
740
- );
741
- instrumented = instrumented.replace(
742
- /(\bdo\s*\{)/g,
743
- "$1\n __checkInstructions();"
744
- );
745
- return `__checkInstructions();
746
- ${instrumented}`;
747
- }
748
- /**
1171
+ */ function instrumentCode(code) {
1172
+ // 简化的指令注入,在循环结构中添加检查
1173
+ var instrumented = code;
1174
+ // for 循环体注入检查(在开括号后)
1175
+ instrumented = instrumented.replace(/(\bfor\s*\([^)]*\)\s*\{)/g, '$1\n __checkInstructions();');
1176
+ // 为 while 循环体注入检查(在开括号后)
1177
+ instrumented = instrumented.replace(/(\bwhile\s*\([^)]*\)\s*\{)/g, '$1\n __checkInstructions();');
1178
+ // do-while 循环体注入检查
1179
+ instrumented = instrumented.replace(/(\bdo\s*\{)/g, '$1\n __checkInstructions();');
1180
+ // 在代码开始处插入检查,确保即使没有循环也能检测超时
1181
+ return "__checkInstructions();\n".concat(instrumented);
1182
+ }
1183
+ },
1184
+ {
1185
+ key: "executeWithWorker",
1186
+ value: /**
749
1187
  * 使用 Worker 执行代码以实现真正的超时控制
750
- */
751
- executeWithWorker(code, injectedParams) {
752
- return new Promise((resolve, reject) => {
753
- const serializableParams = this.trySerializeParams(
754
- injectedParams,
755
- code,
756
- resolve,
757
- reject
758
- );
759
- if (!serializableParams)
760
- return;
761
- const { worker, workerUrl, timeoutId } = this.createWorkerInstance(
762
- code,
763
- serializableParams,
764
- resolve,
765
- reject
766
- );
767
- if (!worker)
768
- return;
769
- this.setupWorkerHandlers(worker, workerUrl, timeoutId, resolve, reject);
770
- });
771
- }
772
- /**
1188
+ */ function executeWithWorker(code, injectedParams) {
1189
+ var _this = this;
1190
+ return new Promise(function(resolve, reject) {
1191
+ // 尝试序列化参数,失败则回退
1192
+ var serializableParams = _this.trySerializeParams(injectedParams, code, resolve, reject);
1193
+ if (!serializableParams) return; // 已经回退处理
1194
+ // 创建 Worker
1195
+ var _this_createWorkerInstance = _this.createWorkerInstance(code, serializableParams, resolve, reject), worker = _this_createWorkerInstance.worker, workerUrl = _this_createWorkerInstance.workerUrl, timeoutId = _this_createWorkerInstance.timeoutId;
1196
+ // Worker 创建失败,已经回退
1197
+ if (!worker) return;
1198
+ // 设置消息处理
1199
+ _this.setupWorkerHandlers(worker, workerUrl, timeoutId, resolve, reject);
1200
+ });
1201
+ }
1202
+ },
1203
+ {
1204
+ key: "trySerializeParams",
1205
+ value: /**
773
1206
  * 尝试序列化参数,失败则回退到同步执行
774
- */
775
- trySerializeParams(injectedParams, code, resolve, reject) {
776
- if (!injectedParams)
777
- return {};
778
- const serializableParams = {};
779
- for (const [key, value] of Object.entries(injectedParams)) {
780
- try {
781
- JSON.stringify(value);
782
- serializableParams[key] = value;
783
- } catch (e) {
784
- console.warn(`无法序列化注入参数 "${key}",回退到同步执行`);
785
- this.fallbackToSyncExecution(code, injectedParams, resolve, reject);
786
- return null;
787
- }
788
- }
789
- return serializableParams;
790
- }
791
- /**
1207
+ */ function trySerializeParams(injectedParams, code, resolve, reject) {
1208
+ if (!injectedParams) return {};
1209
+ var serializableParams = {};
1210
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1211
+ try {
1212
+ for(var _iterator = Object.entries(injectedParams)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1213
+ var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
1214
+ try {
1215
+ JSON.stringify(value);
1216
+ serializableParams[key] = value;
1217
+ } catch (e) {
1218
+ console.warn('无法序列化注入参数 "'.concat(key, '",回退到同步执行'));
1219
+ this.fallbackToSyncExecution(code, injectedParams, resolve, reject);
1220
+ return null;
1221
+ }
1222
+ }
1223
+ } catch (err) {
1224
+ _didIteratorError = true;
1225
+ _iteratorError = err;
1226
+ } finally{
1227
+ try {
1228
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1229
+ _iterator.return();
1230
+ }
1231
+ } finally{
1232
+ if (_didIteratorError) {
1233
+ throw _iteratorError;
1234
+ }
1235
+ }
1236
+ }
1237
+ return serializableParams;
1238
+ }
1239
+ },
1240
+ {
1241
+ key: "fallbackToSyncExecution",
1242
+ value: /**
792
1243
  * 回退到同步执行
793
- */
794
- fallbackToSyncExecution(code, injectedParams, resolve, reject) {
795
- if (this.isObviousInfiniteLoop(code)) {
796
- this.executeWithInstructionLimit(code, injectedParams).then(resolve).catch(reject);
797
- return;
798
- }
799
- this.executeWithTimeout(code, injectedParams).then(resolve).catch(reject);
800
- }
801
- /**
1244
+ */ function fallbackToSyncExecution(code, injectedParams, resolve, reject) {
1245
+ // 检查是否是死循环,如果是则使用指令计数方法
1246
+ if (this.isObviousInfiniteLoop(code)) {
1247
+ this.executeWithInstructionLimit(code, injectedParams).then(resolve).catch(reject);
1248
+ return;
1249
+ }
1250
+ // 对正常代码使用超时保护
1251
+ this.executeWithTimeout(code, injectedParams).then(resolve).catch(reject);
1252
+ }
1253
+ },
1254
+ {
1255
+ key: "createWorkerInstance",
1256
+ value: /**
802
1257
  * 创建 Worker 实例
803
- */
804
- createWorkerInstance(code, serializableParams, resolve, reject) {
805
- const workerCode = this.generateWorkerCode();
806
- const blob = new Blob([workerCode], { type: "application/javascript" });
807
- const workerUrl = URL.createObjectURL(blob);
808
- try {
809
- const worker = new Worker(workerUrl);
810
- const timeoutId = this.setupWorkerTimeout(worker, workerUrl, reject);
811
- worker.postMessage({
812
- code,
813
- config: this.config,
814
- injectedParams: serializableParams
815
- });
816
- return { worker, workerUrl, timeoutId };
817
- } catch (error) {
818
- URL.revokeObjectURL(workerUrl);
819
- console.warn("Worker 创建失败,回退到同步执行");
820
- this.fallbackToSyncExecution(code, serializableParams, resolve, reject);
821
- return { worker: null, workerUrl, timeoutId: 0 };
822
- }
823
- }
824
- /**
1258
+ */ function createWorkerInstance(code, serializableParams, resolve, reject) {
1259
+ var workerCode = this.generateWorkerCode();
1260
+ var blob = new Blob([
1261
+ workerCode
1262
+ ], {
1263
+ type: 'application/javascript'
1264
+ });
1265
+ var workerUrl = URL.createObjectURL(blob);
1266
+ try {
1267
+ var worker = new Worker(workerUrl);
1268
+ var timeoutId = this.setupWorkerTimeout(worker, workerUrl, reject);
1269
+ // 发送代码到 Worker
1270
+ worker.postMessage({
1271
+ code: code,
1272
+ config: this.config,
1273
+ injectedParams: serializableParams
1274
+ });
1275
+ return {
1276
+ worker: worker,
1277
+ workerUrl: workerUrl,
1278
+ timeoutId: timeoutId
1279
+ };
1280
+ } catch (error) {
1281
+ URL.revokeObjectURL(workerUrl);
1282
+ console.warn('Worker 创建失败,回退到同步执行');
1283
+ this.fallbackToSyncExecution(code, serializableParams, resolve, reject);
1284
+ return {
1285
+ worker: null,
1286
+ workerUrl: workerUrl,
1287
+ timeoutId: 0
1288
+ };
1289
+ }
1290
+ }
1291
+ },
1292
+ {
1293
+ key: "generateWorkerCode",
1294
+ value: /**
825
1295
  * 生成 Worker 代码
826
- */
827
- generateWorkerCode() {
828
- return `
829
- self.onmessage = function(e) {
830
- const { code, config, injectedParams } = e.data;
831
-
832
- try {
833
- // 创建安全的执行环境
834
- const safeGlobals = {
835
- Math, Date, JSON, parseInt, parseFloat, isNaN, isFinite,
836
- encodeURIComponent, decodeURIComponent, encodeURI, decodeURI,
837
- String, Number, Boolean, Array, Object, RegExp,
838
- Error, TypeError, ReferenceError, SyntaxError
839
- };
840
-
841
- // 添加自定义全局变量
842
- Object.assign(safeGlobals, config.customGlobals || {});
843
-
844
- // 添加注入的参数
845
- Object.assign(safeGlobals, injectedParams || {});
846
-
847
- // 添加 console(如果允许)
848
- if (config.allowConsole) {
849
- safeGlobals.console = {
850
- log: (...args) => self.postMessage({ type: 'log', data: args }),
851
- warn: (...args) => self.postMessage({ type: 'warn', data: args }),
852
- error: (...args) => self.postMessage({ type: 'error', data: args }),
853
- info: (...args) => self.postMessage({ type: 'info', data: args }),
854
- debug: (...args) => self.postMessage({ type: 'debug', data: args })
855
- };
856
- }
857
-
858
- // 创建执行函数
859
- const wrappedCode = config.strictMode ? "'use strict';\\n" + code : code;
860
- const func = new Function(...Object.keys(safeGlobals), 'return (function() { ' + wrappedCode + ' })()');
861
-
862
- // 执行代码
863
- const result = func(...Object.values(safeGlobals));
864
-
865
- self.postMessage({ type: 'result', data: result });
866
- } catch (error) {
867
- self.postMessage({ type: 'error', data: { message: error.message, stack: error.stack } });
868
- }
869
- };
870
- `;
871
- }
872
- /**
1296
+ */ function generateWorkerCode() {
1297
+ return "\n self.onmessage = function(e) {\n const { code, config, injectedParams } = e.data;\n \n try {\n // 创建安全的执行环境\n const safeGlobals = {\n Math, Date, JSON, parseInt, parseFloat, isNaN, isFinite,\n encodeURIComponent, decodeURIComponent, encodeURI, decodeURI,\n String, Number, Boolean, Array, Object, RegExp,\n Error, TypeError, ReferenceError, SyntaxError\n };\n \n // 添加自定义全局变量\n Object.assign(safeGlobals, config.customGlobals || {});\n \n // 添加注入的参数\n Object.assign(safeGlobals, injectedParams || {});\n \n // 添加 console(如果允许)\n if (config.allowConsole) {\n safeGlobals.console = {\n log: (...args) => self.postMessage({ type: 'log', data: args }),\n warn: (...args) => self.postMessage({ type: 'warn', data: args }),\n error: (...args) => self.postMessage({ type: 'error', data: args }),\n info: (...args) => self.postMessage({ type: 'info', data: args }),\n debug: (...args) => self.postMessage({ type: 'debug', data: args })\n };\n }\n \n // 创建执行函数\n const wrappedCode = config.strictMode ? \"'use strict';\\n\" + code : code;\n const func = new Function(...Object.keys(safeGlobals), 'return (function() { ' + wrappedCode + ' })()');\n \n // 执行代码\n const result = func(...Object.values(safeGlobals));\n \n self.postMessage({ type: 'result', data: result });\n } catch (error) {\n self.postMessage({ type: 'error', data: { message: error.message, stack: error.stack } });\n }\n };\n ";
1298
+ }
1299
+ },
1300
+ {
1301
+ key: "setupWorkerTimeout",
1302
+ value: /**
873
1303
  * 设置 Worker 超时
874
- */
875
- setupWorkerTimeout(worker, workerUrl, reject) {
876
- return window.setTimeout(() => {
877
- worker.terminate();
878
- URL.revokeObjectURL(workerUrl);
879
- reject(
880
- new Error(`Code execution timeout after ${this.config.timeout}ms`)
881
- );
882
- }, this.config.timeout);
883
- }
884
- /**
1304
+ */ function setupWorkerTimeout(worker, workerUrl, reject) {
1305
+ var _this = this;
1306
+ return window.setTimeout(function() {
1307
+ worker.terminate();
1308
+ URL.revokeObjectURL(workerUrl);
1309
+ reject(new Error("Code execution timeout after ".concat(_this.config.timeout, "ms")));
1310
+ }, this.config.timeout);
1311
+ }
1312
+ },
1313
+ {
1314
+ key: "setupWorkerHandlers",
1315
+ value: /**
885
1316
  * 设置 Worker 消息处理器
886
- */
887
- setupWorkerHandlers(worker, workerUrl, timeoutId, resolve, reject) {
888
- worker.onmessage = (e) => {
889
- const { type, data } = e.data;
890
- if (type === "result") {
891
- this.cleanupWorker(worker, workerUrl, timeoutId);
892
- resolve(data);
893
- return;
894
- }
895
- if (type === "error") {
896
- this.cleanupWorker(worker, workerUrl, timeoutId);
897
- reject(new Error(data.message));
898
- return;
899
- }
900
- this.handleConsoleMessage(type, data);
901
- };
902
- worker.onerror = (error) => {
903
- this.cleanupWorker(worker, workerUrl, timeoutId);
904
- reject(new Error(`Worker error: ${error.message}`));
905
- };
906
- }
907
- /**
1317
+ */ function setupWorkerHandlers(worker, workerUrl, timeoutId, resolve, reject) {
1318
+ var _this = this;
1319
+ worker.onmessage = function(e) {
1320
+ var _e_data = e.data, type = _e_data.type, data = _e_data.data;
1321
+ if (type === 'result') {
1322
+ _this.cleanupWorker(worker, workerUrl, timeoutId);
1323
+ resolve(data);
1324
+ return;
1325
+ }
1326
+ if (type === 'error') {
1327
+ _this.cleanupWorker(worker, workerUrl, timeoutId);
1328
+ reject(new Error(data.message));
1329
+ return;
1330
+ }
1331
+ // 处理控制台输出
1332
+ _this.handleConsoleMessage(type, data);
1333
+ };
1334
+ worker.onerror = function(error) {
1335
+ _this.cleanupWorker(worker, workerUrl, timeoutId);
1336
+ reject(new Error("Worker error: ".concat(error.message)));
1337
+ };
1338
+ }
1339
+ },
1340
+ {
1341
+ key: "handleConsoleMessage",
1342
+ value: /**
908
1343
  * 处理控制台消息
909
- */
910
- handleConsoleMessage(type, data) {
911
- if (!this.config.allowConsole)
912
- return;
913
- const consoleTypes = ["log", "warn", "error", "info", "debug"];
914
- if (!consoleTypes.includes(type))
915
- return;
916
- const consoleMethod = console[type];
917
- if (typeof consoleMethod === "function") {
918
- consoleMethod("[Sandbox]", ...data);
919
- }
920
- }
921
- /**
1344
+ */ function handleConsoleMessage(type, data) {
1345
+ if (!this.config.allowConsole) return;
1346
+ var consoleTypes = [
1347
+ 'log',
1348
+ 'warn',
1349
+ 'error',
1350
+ 'info',
1351
+ 'debug'
1352
+ ];
1353
+ if (!consoleTypes.includes(type)) return;
1354
+ var consoleMethod = console[type];
1355
+ if (typeof consoleMethod === 'function') {
1356
+ consoleMethod.apply(void 0, [
1357
+ '[Sandbox]'
1358
+ ].concat(_to_consumable_array(data)));
1359
+ }
1360
+ }
1361
+ },
1362
+ {
1363
+ key: "cleanupWorker",
1364
+ value: /**
922
1365
  * 清理 Worker 资源
923
- */
924
- cleanupWorker(worker, workerUrl, timeoutId) {
925
- clearTimeout(timeoutId);
926
- worker.terminate();
927
- URL.revokeObjectURL(workerUrl);
928
- }
929
- /**
1366
+ */ function cleanupWorker(worker, workerUrl, timeoutId) {
1367
+ clearTimeout(timeoutId);
1368
+ worker.terminate();
1369
+ URL.revokeObjectURL(workerUrl);
1370
+ }
1371
+ },
1372
+ {
1373
+ key: "executeCode",
1374
+ value: /**
930
1375
  * 执行代码的核心方法(同步版本)
931
- */
932
- executeCode(code, injectedParams) {
933
- const wrappedCode = this.config.strictMode ? `'use strict';
934
- ${code}` : code;
935
- this.validateCode(wrappedCode);
936
- const allGlobals = __spreadValues(__spreadValues(__spreadValues({}, this.sandboxGlobal), this.config.customGlobals), injectedParams || {});
937
- const allowedKeys = Object.keys(allGlobals);
938
- const allowedValues = allowedKeys.map((key) => allGlobals[key]);
939
- const funcCode = `
940
- return (function(${allowedKeys.join(", ")}) {
941
- ${wrappedCode}
942
- })(${allowedKeys.map((_, index) => `arguments[${index}]`).join(", ")});
943
- `;
944
- try {
945
- const func = new Function(funcCode);
946
- return func.apply(null, allowedValues);
947
- } catch (error) {
948
- if (error instanceof ReferenceError) {
949
- const match = error.message.match(/(\w+) is not defined/);
950
- if (match) {
951
- const varName = match[1];
952
- if (this.config.forbiddenGlobals.includes(varName)) {
953
- throw new ReferenceError(
954
- `Access to '${varName}' is not allowed in sandbox`
955
- );
956
- }
957
- }
958
- }
959
- throw error;
960
- }
961
- }
962
- /**
1376
+ */ function executeCode(code, injectedParams) {
1377
+ // 添加严格模式
1378
+ var wrappedCode = this.config.strictMode ? "'use strict';\n".concat(code) : code;
1379
+ // 预处理代码以检测和阻止危险操作
1380
+ this.validateCode(wrappedCode);
1381
+ // 获取允许的全局变量名和值
1382
+ // 合并沙箱全局变量、自定义全局变量和注入参数
1383
+ var allGlobals = _object_spread({}, this.sandboxGlobal, this.config.customGlobals, injectedParams || {});
1384
+ var allowedKeys = Object.keys(allGlobals);
1385
+ var allowedValues = allowedKeys.map(function(key) {
1386
+ return allGlobals[key];
1387
+ });
1388
+ // 创建安全的执行环境
1389
+ // 通过参数传递的方式提供沙箱全局变量,而不是通过全局对象访问
1390
+ var funcCode = "\n return (function(".concat(allowedKeys.join(', '), ") {\n ").concat(wrappedCode, "\n })(").concat(allowedKeys.map(function(_, index) {
1391
+ return "arguments[".concat(index, "]");
1392
+ }).join(', '), ");\n ");
1393
+ try {
1394
+ // 使用 Function 构造函数创建执行函数
1395
+ // 不传递任何全局变量名,强制代码只能使用参数提供的变量
1396
+ var func = new Function(funcCode);
1397
+ // 执行函数,传入沙箱全局变量
1398
+ return func.apply(null, allowedValues);
1399
+ } catch (error) {
1400
+ // 检查是否是因为试图访问被禁止的全局变量
1401
+ if (error instanceof ReferenceError) {
1402
+ var match = error.message.match(/(\w+) is not defined/);
1403
+ if (match) {
1404
+ var varName = match[1];
1405
+ if (this.config.forbiddenGlobals.includes(varName)) {
1406
+ throw new ReferenceError("Access to '".concat(varName, "' is not allowed in sandbox"));
1407
+ }
1408
+ }
1409
+ }
1410
+ throw error;
1411
+ }
1412
+ }
1413
+ },
1414
+ {
1415
+ key: "validateCode",
1416
+ value: /**
963
1417
  * 验证代码安全性
964
- */
965
- validateCode(code) {
966
- const dangerousPatterns = [
967
- /\beval\s*\(/,
968
- /\bFunction\s*\(/,
969
- /new\s+Function\s*\(/,
970
- /\.constructor/,
971
- // 直接检查 .constructor 访问
972
- /\.__proto__/,
973
- /\.prototype\./,
974
- /\bglobal\s*[.[]/,
975
- /\bself\s*[.[]/,
976
- /\bprocess\s*[.[]/,
977
- /\brequire\s*\(/,
978
- /\bimport\s*\(/,
979
- /\bimportScripts\s*\(/
980
- ];
981
- const globalThisPatterns = [
982
- /\bglobalThis\s*\.\s*[a-zA-Z_$]/,
983
- // globalThis.someProperty
984
- /\bglobalThis\s*\[/,
985
- // globalThis[someIndex]
986
- /=\s*globalThis\b/,
987
- // = globalThis
988
- /\breturn\s+globalThis\b/
989
- // return globalThis
990
- ];
991
- for (const pattern of globalThisPatterns) {
992
- if (pattern.test(code)) {
993
- throw new Error(
994
- "Code contains dangerous pattern: globalThis property access"
995
- );
996
- }
997
- }
998
- for (const pattern of dangerousPatterns) {
999
- if (pattern.test(code)) {
1000
- throw new Error(`Code contains dangerous pattern: ${pattern.source}`);
1001
- }
1002
- }
1003
- const criticalForbiddenGlobals = [
1004
- "eval",
1005
- "Function",
1006
- "constructor",
1007
- "__proto__",
1008
- "global",
1009
- "self",
1010
- "process",
1011
- "require",
1012
- "module",
1013
- "exports",
1014
- "Buffer",
1015
- "XMLHttpRequest",
1016
- "fetch",
1017
- "WebSocket",
1018
- "Worker",
1019
- "SharedArrayBuffer",
1020
- "Atomics",
1021
- "WebAssembly"
1022
- ];
1023
- for (const forbiddenGlobal of criticalForbiddenGlobals) {
1024
- const patterns = [
1025
- new RegExp(`\\b${forbiddenGlobal}\\s*\\(`, "g"),
1026
- // 函数调用
1027
- new RegExp(`\\b${forbiddenGlobal}\\s*\\.`, "g"),
1028
- // 属性访问
1029
- new RegExp(`\\b${forbiddenGlobal}\\s*\\[`, "g"),
1030
- // 索引访问
1031
- new RegExp(`\\breturn\\s+${forbiddenGlobal}\\b`, "g"),
1032
- // 直接返回
1033
- new RegExp(`=\\s*${forbiddenGlobal}\\b`, "g")
1034
- // 赋值
1035
- ];
1036
- for (const pattern of patterns) {
1037
- if (pattern.test(code)) {
1038
- throw new ReferenceError(
1039
- `Access to '${forbiddenGlobal}' is not allowed in sandbox`
1040
- );
1041
- }
1042
- }
1043
- }
1044
- }
1045
- /**
1418
+ */ function validateCode(code) {
1419
+ // 检查是否包含危险的模式
1420
+ var dangerousPatterns = [
1421
+ /\beval\s*\(/,
1422
+ /\bFunction\s*\(/,
1423
+ /new\s+Function\s*\(/,
1424
+ /\.constructor/,
1425
+ /\.__proto__/,
1426
+ /\.prototype\./,
1427
+ /\bglobal\s*[.[]/,
1428
+ /\bself\s*[.[]/,
1429
+ /\bprocess\s*[.[]/,
1430
+ /\brequire\s*\(/,
1431
+ /\bimport\s*\(/,
1432
+ /\bimportScripts\s*\(/
1433
+ ];
1434
+ // 对于 globalThis,只在直接访问属性时才阻止,允许 typeof 检查
1435
+ // 检查是否有恶意的 globalThis 访问(排除 typeof 检查)
1436
+ var globalThisPatterns = [
1437
+ /\bglobalThis\s*\.\s*[a-zA-Z_$]/,
1438
+ /\bglobalThis\s*\[/,
1439
+ /=\s*globalThis\b/,
1440
+ /\breturn\s+globalThis\b/
1441
+ ];
1442
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1443
+ try {
1444
+ for(var _iterator = globalThisPatterns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1445
+ var pattern = _step.value;
1446
+ if (pattern.test(code)) {
1447
+ throw new Error('Code contains dangerous pattern: globalThis property access');
1448
+ }
1449
+ }
1450
+ } catch (err) {
1451
+ _didIteratorError = true;
1452
+ _iteratorError = err;
1453
+ } finally{
1454
+ try {
1455
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1456
+ _iterator.return();
1457
+ }
1458
+ } finally{
1459
+ if (_didIteratorError) {
1460
+ throw _iteratorError;
1461
+ }
1462
+ }
1463
+ }
1464
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
1465
+ try {
1466
+ for(var _iterator1 = dangerousPatterns[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1467
+ var pattern1 = _step1.value;
1468
+ if (pattern1.test(code)) {
1469
+ throw new Error("Code contains dangerous pattern: ".concat(pattern1.source));
1470
+ }
1471
+ }
1472
+ } catch (err) {
1473
+ _didIteratorError1 = true;
1474
+ _iteratorError1 = err;
1475
+ } finally{
1476
+ try {
1477
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1478
+ _iterator1.return();
1479
+ }
1480
+ } finally{
1481
+ if (_didIteratorError1) {
1482
+ throw _iteratorError1;
1483
+ }
1484
+ }
1485
+ }
1486
+ // 检查特定的被禁止的全局变量名(只检查明确的危险变量)
1487
+ var criticalForbiddenGlobals = [
1488
+ 'eval',
1489
+ 'Function',
1490
+ 'constructor',
1491
+ '__proto__',
1492
+ 'global',
1493
+ 'self',
1494
+ 'process',
1495
+ 'require',
1496
+ 'module',
1497
+ 'exports',
1498
+ 'Buffer',
1499
+ 'XMLHttpRequest',
1500
+ 'fetch',
1501
+ 'WebSocket',
1502
+ 'Worker',
1503
+ 'SharedArrayBuffer',
1504
+ 'Atomics',
1505
+ 'WebAssembly'
1506
+ ];
1507
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
1508
+ try {
1509
+ for(var _iterator2 = criticalForbiddenGlobals[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
1510
+ var forbiddenGlobal = _step2.value;
1511
+ // 只检查作为独立标识符或对象访问的情况
1512
+ var patterns = [
1513
+ new RegExp("\\b".concat(forbiddenGlobal, "\\s*\\("), 'g'),
1514
+ new RegExp("\\b".concat(forbiddenGlobal, "\\s*\\."), 'g'),
1515
+ new RegExp("\\b".concat(forbiddenGlobal, "\\s*\\["), 'g'),
1516
+ new RegExp("\\breturn\\s+".concat(forbiddenGlobal, "\\b"), 'g'),
1517
+ new RegExp("=\\s*".concat(forbiddenGlobal, "\\b"), 'g')
1518
+ ];
1519
+ var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined;
1520
+ try {
1521
+ for(var _iterator3 = patterns[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true){
1522
+ var pattern2 = _step3.value;
1523
+ if (pattern2.test(code)) {
1524
+ throw new ReferenceError("Access to '".concat(forbiddenGlobal, "' is not allowed in sandbox"));
1525
+ }
1526
+ }
1527
+ } catch (err) {
1528
+ _didIteratorError3 = true;
1529
+ _iteratorError3 = err;
1530
+ } finally{
1531
+ try {
1532
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
1533
+ _iterator3.return();
1534
+ }
1535
+ } finally{
1536
+ if (_didIteratorError3) {
1537
+ throw _iteratorError3;
1538
+ }
1539
+ }
1540
+ }
1541
+ }
1542
+ } catch (err) {
1543
+ _didIteratorError2 = true;
1544
+ _iteratorError2 = err;
1545
+ } finally{
1546
+ try {
1547
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
1548
+ _iterator2.return();
1549
+ }
1550
+ } finally{
1551
+ if (_didIteratorError2) {
1552
+ throw _iteratorError2;
1553
+ }
1554
+ }
1555
+ }
1556
+ }
1557
+ },
1558
+ {
1559
+ key: "getMemoryUsage",
1560
+ value: /**
1046
1561
  * 获取内存使用情况
1047
- */
1048
- getMemoryUsage() {
1049
- if ("memory" in performance) {
1050
- return performance.memory.usedJSHeapSize;
1051
- }
1052
- return 0;
1053
- }
1054
- /**
1562
+ */ function getMemoryUsage() {
1563
+ if ('memory' in performance) {
1564
+ return performance.memory.usedJSHeapSize;
1565
+ }
1566
+ return 0;
1567
+ }
1568
+ },
1569
+ {
1570
+ key: "cleanup",
1571
+ value: /**
1055
1572
  * 清理资源
1056
- */
1057
- cleanup() {
1058
- this.isActive = false;
1059
- if (this.timeoutId !== null) {
1060
- clearTimeout(this.timeoutId);
1061
- this.timeoutId = null;
1062
- }
1063
- }
1064
- /**
1573
+ */ function cleanup() {
1574
+ this.isActive = false;
1575
+ if (this.timeoutId !== null) {
1576
+ clearTimeout(this.timeoutId);
1577
+ this.timeoutId = null;
1578
+ }
1579
+ }
1580
+ },
1581
+ {
1582
+ /**
1065
1583
  * 销毁沙箱
1066
- */
1067
- destroy() {
1068
- this.cleanup();
1069
- Object.keys(this.sandboxGlobal).forEach((key) => {
1070
- delete this.sandboxGlobal[key];
1071
- });
1072
- }
1073
- /**
1584
+ */ key: "destroy",
1585
+ value: function destroy() {
1586
+ var _this = this;
1587
+ this.cleanup();
1588
+ // 清理全局对象
1589
+ Object.keys(this.sandboxGlobal).forEach(function(key) {
1590
+ delete _this.sandboxGlobal[key];
1591
+ });
1592
+ }
1593
+ },
1594
+ {
1595
+ /**
1074
1596
  * 检查沙箱是否处于活动状态
1075
- */
1076
- isRunning() {
1077
- return this.isActive;
1078
- }
1079
- /**
1597
+ */ key: "isRunning",
1598
+ value: function isRunning() {
1599
+ return this.isActive;
1600
+ }
1601
+ },
1602
+ {
1603
+ /**
1080
1604
  * 添加自定义全局变量
1081
- */
1082
- addGlobal(name, value) {
1083
- if (this.config.forbiddenGlobals.includes(name)) {
1084
- throw new Error(`Cannot add forbidden global: ${name}`);
1085
- }
1086
- this.sandboxGlobal[name] = value;
1087
- this.config.customGlobals[name] = value;
1088
- }
1089
- /**
1605
+ */ key: "addGlobal",
1606
+ value: function addGlobal(name, value) {
1607
+ if (this.config.forbiddenGlobals.includes(name)) {
1608
+ throw new Error("Cannot add forbidden global: ".concat(name));
1609
+ }
1610
+ this.sandboxGlobal[name] = value;
1611
+ this.config.customGlobals[name] = value;
1612
+ }
1613
+ },
1614
+ {
1615
+ /**
1090
1616
  * 移除自定义全局变量
1091
- */
1092
- removeGlobal(name) {
1093
- delete this.sandboxGlobal[name];
1094
- delete this.config.customGlobals[name];
1095
- }
1096
- /**
1617
+ */ key: "removeGlobal",
1618
+ value: function removeGlobal(name) {
1619
+ delete this.sandboxGlobal[name];
1620
+ delete this.config.customGlobals[name];
1621
+ }
1622
+ },
1623
+ {
1624
+ /**
1097
1625
  * 获取沙箱配置
1098
- */
1099
- getConfig() {
1100
- return __spreadValues({}, this.config);
1101
- }
1102
- };
1103
- function createSandbox(config) {
1104
- return new ProxySandbox(config);
1626
+ */ key: "getConfig",
1627
+ value: function getConfig() {
1628
+ return _object_spread({}, this.config);
1629
+ }
1630
+ }
1631
+ ]);
1632
+ return ProxySandbox;
1633
+ }();
1634
+ /**
1635
+ * 创建沙箱实例的工厂函数
1636
+ */ export function createSandbox(config) {
1637
+ return new ProxySandbox(config);
1105
1638
  }
1106
- function runInSandbox(code, config, injectedParams) {
1107
- return __async(this, null, function* () {
1108
- const sandbox = createSandbox(config);
1109
- try {
1110
- return yield sandbox.execute(code, injectedParams);
1111
- } finally {
1112
- sandbox.destroy();
1113
- }
1114
- });
1639
+ /**
1640
+ * 快速执行代码的工具函数
1641
+ */ export function runInSandbox(code, config, injectedParams) {
1642
+ return _runInSandbox.apply(this, arguments);
1643
+ }
1644
+ function _runInSandbox() {
1645
+ _runInSandbox = _async_to_generator(function(code, config, injectedParams) {
1646
+ var sandbox;
1647
+ return _ts_generator(this, function(_state) {
1648
+ switch(_state.label){
1649
+ case 0:
1650
+ sandbox = createSandbox(config);
1651
+ _state.label = 1;
1652
+ case 1:
1653
+ _state.trys.push([
1654
+ 1,
1655
+ ,
1656
+ 3,
1657
+ 4
1658
+ ]);
1659
+ return [
1660
+ 4,
1661
+ sandbox.execute(code, injectedParams)
1662
+ ];
1663
+ case 2:
1664
+ return [
1665
+ 2,
1666
+ _state.sent()
1667
+ ];
1668
+ case 3:
1669
+ sandbox.destroy();
1670
+ return [
1671
+ 7
1672
+ ];
1673
+ case 4:
1674
+ return [
1675
+ 2
1676
+ ];
1677
+ }
1678
+ });
1679
+ });
1680
+ return _runInSandbox.apply(this, arguments);
1115
1681
  }
1116
- export {
1117
- ProxySandbox,
1118
- createSandbox,
1119
- runInSandbox
1120
- };