@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.
- package/dist/AgentRunBar/Robot.js +105 -57
- package/dist/AgentRunBar/icons/PauseIcon.js +38 -38
- package/dist/AgentRunBar/icons/PlayIcon.js +38 -38
- package/dist/AgentRunBar/icons/SimplePauseIcon.js +38 -38
- package/dist/AgentRunBar/icons/SimplePlayIcon.js +38 -38
- package/dist/AgentRunBar/icons/SimpleStopIcon.js +38 -38
- package/dist/AgentRunBar/icons/StopIcon.js +41 -50
- package/dist/AgentRunBar/icons/index.js +0 -1
- package/dist/AgentRunBar/index.js +270 -237
- package/dist/AgentRunBar/style.js +273 -239
- package/dist/AgenticLayout/index.js +140 -85
- package/dist/AgenticLayout/style.js +126 -107
- package/dist/AnswerAlert/components/CloseIcon.js +12 -21
- package/dist/AnswerAlert/components/ErrorIcon.js +42 -38
- package/dist/AnswerAlert/components/InfoIcon.js +42 -38
- package/dist/AnswerAlert/components/LoaderIcon.js +12 -21
- package/dist/AnswerAlert/components/SuccessIcon.js +42 -38
- package/dist/AnswerAlert/components/WarningIcon.js +42 -38
- package/dist/AnswerAlert/index.js +155 -75
- package/dist/AnswerAlert/style.js +159 -147
- package/dist/BackTo/BackBottom.js +154 -70
- package/dist/BackTo/BackTop.js +148 -68
- package/dist/BackTo/ScrollVisibleButton.js +124 -98
- package/dist/BackTo/hooks/useScrollVisible.js +79 -33
- package/dist/BackTo/icons/BottomIcon.js +37 -37
- package/dist/BackTo/icons/TopIcon.js +37 -37
- package/dist/BackTo/index.js +22 -7
- package/dist/BackTo/style.js +93 -70
- package/dist/Bubble/AIBubble.js +469 -406
- package/dist/Bubble/Avatar/index.js +139 -85
- package/dist/Bubble/Avatar/isEmoji.js +2 -6
- package/dist/Bubble/Bubble.js +114 -38
- package/dist/Bubble/BubbleBeforeNode.js +104 -74
- package/dist/Bubble/BubbleConfigProvide.js +3 -7
- package/dist/Bubble/FileView.js +63 -69
- package/dist/Bubble/List/PureBubbleList.js +130 -131
- package/dist/Bubble/List/SkeletonList.js +33 -24
- package/dist/Bubble/List/index.js +187 -124
- package/dist/Bubble/List/style.js +76 -47
- package/dist/Bubble/MessagesContent/BubbleContext.js +6 -12
- package/dist/Bubble/MessagesContent/BubbleExtra.js +663 -355
- package/dist/Bubble/MessagesContent/CopyButton/index.js +326 -96
- package/dist/Bubble/MessagesContent/DocInfo.js +351 -386
- package/dist/Bubble/MessagesContent/EXCEPTION.js +42 -22
- package/dist/Bubble/MessagesContent/MarkdownPreview.js +206 -156
- package/dist/Bubble/MessagesContent/VoiceButton/index.js +213 -115
- package/dist/Bubble/MessagesContent/VoiceButton/style.js +129 -105
- package/dist/Bubble/MessagesContent/VoiceButton/types.js +9 -0
- package/dist/Bubble/MessagesContent/docInfoStyle.js +118 -88
- package/dist/Bubble/MessagesContent/icons.js +157 -57
- package/dist/Bubble/MessagesContent/index.js +609 -368
- package/dist/Bubble/PureBubble.js +439 -326
- package/dist/Bubble/Title.js +110 -87
- package/dist/Bubble/UserBubble.js +218 -279
- package/dist/Bubble/index.js +10 -16
- package/dist/Bubble/style.js +248 -227
- package/dist/Bubble/type.js +3 -0
- package/dist/Bubble/types/BubbleExtra.js +1 -0
- package/dist/Bubble/types/DocInfo.js +1 -0
- package/dist/ChatBootPage/ButtonTab.js +25 -45
- package/dist/ChatBootPage/ButtonTabGroup.js +74 -47
- package/dist/ChatBootPage/ButtonTabGroupStyle.js +73 -45
- package/dist/ChatBootPage/ButtonTabStyle.js +121 -98
- package/dist/ChatBootPage/CaseReply.js +119 -113
- package/dist/ChatBootPage/CaseReplyStyle.js +217 -189
- package/dist/ChatBootPage/Title.js +19 -23
- package/dist/ChatBootPage/index.js +9 -11
- package/dist/ChatBootPage/style.js +80 -50
- package/dist/ChatLayout/index.js +93 -57
- package/dist/ChatLayout/style.js +206 -176
- package/dist/ChatLayout/types.js +1 -0
- package/dist/Components/ActionIconBox/index.js +571 -197
- package/dist/Components/ActionIconBox/style.js +141 -111
- package/dist/Components/ActionItemBox/ActionItemBox.js +95 -149
- package/dist/Components/ActionItemBox/index.js +7 -7
- package/dist/Components/ActionItemBox/style.js +353 -361
- package/dist/Components/Button/IconButton/index.js +35 -43
- package/dist/Components/Button/IconButton/style.js +357 -331
- package/dist/Components/Button/SwitchButton/index.js +243 -87
- package/dist/Components/Button/SwitchButton/style.js +160 -146
- package/dist/Components/Button/ToggleButton/index.js +46 -57
- package/dist/Components/Button/ToggleButton/style.js +283 -258
- package/dist/Components/Button/index.js +6 -2
- package/dist/Components/GradientText/index.js +21 -27
- package/dist/Components/GradientText/style.js +88 -63
- package/dist/Components/ImageList.js +111 -133
- package/dist/Components/LayoutHeader/index.js +145 -81
- package/dist/Components/LayoutHeader/style.js +89 -64
- package/dist/Components/LayoutHeader/types.js +3 -0
- package/dist/Components/Loading/index.js +53 -22
- package/dist/Components/Robot/index.js +90 -56
- package/dist/Components/Robot/lotties/DazingLottie/index.js +78 -47
- package/dist/Components/Robot/lotties/ThinkingLottie/index.js +78 -47
- package/dist/Components/Robot/lotties/index.js +0 -1
- package/dist/Components/SuggestionList/index.js +354 -182
- package/dist/Components/SuggestionList/style.js +204 -186
- package/dist/Components/TextAnimate/index.js +494 -362
- package/dist/Components/TextAnimate/style.js +72 -48
- package/dist/Components/TypingAnimation/index.js +214 -169
- package/dist/Components/TypingAnimation/style.js +76 -52
- package/dist/Components/VisualList/index.js +267 -180
- package/dist/Components/VisualList/style.js +140 -124
- package/dist/Components/icons/LoadingSpinnerIcon.js +124 -73
- package/dist/Components/lotties/DazingLottie/index.js +78 -47
- package/dist/Components/lotties/LoadingLottie/index.js +82 -48
- package/dist/Components/lotties/TextLoading/index.js +73 -49
- package/dist/Components/lotties/TextLoading/style.js +95 -78
- package/dist/Components/lotties/ThinkingLottie/index.js +78 -47
- package/dist/Components/lotties/index.js +0 -1
- package/dist/Constants/colors.js +71 -97
- package/dist/History/components/HistoryActionsBox.js +407 -180
- package/dist/History/components/HistoryEmpty.js +38 -42
- package/dist/History/components/HistoryEmptyIcon.js +682 -964
- package/dist/History/components/HistoryItem.js +683 -471
- package/dist/History/components/HistoryList.js +170 -87
- package/dist/History/components/HistoryRunningIcon.js +160 -111
- package/dist/History/components/LoadMoreComponent.js +308 -103
- package/dist/History/components/NewChatComponent.js +261 -69
- package/dist/History/components/NewChatComponent.style.js +79 -53
- package/dist/History/components/SearchComponent.js +367 -156
- package/dist/History/components/index.js +11 -23
- package/dist/History/hooks/useHistory.js +404 -129
- package/dist/History/index.js +301 -186
- package/dist/History/menu.js +158 -212
- package/dist/History/style.js +282 -276
- package/dist/History/types/HistoryData.js +6 -10
- package/dist/History/types/HistoryList.js +3 -0
- package/dist/History/types/index.js +3 -0
- package/dist/History/utils/index.js +35 -32
- package/dist/Hooks/useAutoScroll.js +262 -84
- package/dist/Hooks/useClickAway.js +60 -21
- package/dist/Hooks/useCopied.js +72 -20
- package/dist/Hooks/useDebounceFn/index.js +213 -55
- package/dist/Hooks/useIntersectionOnce.js +163 -74
- package/dist/Hooks/useLanguage.d.ts +3 -0
- package/dist/Hooks/useLanguage.js +67 -26
- package/dist/Hooks/useRefFunction/index.js +76 -11
- package/dist/Hooks/useSpeechSynthesis.js +143 -99
- package/dist/Hooks/useStyle/index.js +95 -60
- package/dist/Hooks/useThrottleFn/index.js +41 -41
- package/dist/I18n/index.js +246 -109
- package/dist/I18n/locales.d.ts +3 -0
- package/dist/I18n/locales.js +724 -711
- package/dist/Icons/animated/VoicePlayLottie/index.js +75 -46
- package/dist/Icons/animated/VoicingLottie/index.js +78 -47
- package/dist/MarkdownEditor/BaseMarkdownEditor.js +421 -349
- package/dist/MarkdownEditor/editor/Editor.js +1160 -843
- package/dist/MarkdownEditor/editor/components/CommentList/index.js +407 -239
- package/dist/MarkdownEditor/editor/components/CommentList/style.js +119 -89
- package/dist/MarkdownEditor/editor/components/ContributorAvatar/index.js +61 -63
- package/dist/MarkdownEditor/editor/components/ContributorAvatar/style.js +82 -52
- package/dist/MarkdownEditor/editor/components/LazyElement/index.js +208 -106
- package/dist/MarkdownEditor/editor/components/LazyElement/style.js +69 -42
- package/dist/MarkdownEditor/editor/components/fntTag/index.js +7 -11
- package/dist/MarkdownEditor/editor/components/fntTag/style.js +66 -36
- package/dist/MarkdownEditor/editor/components/index.js +0 -1
- package/dist/MarkdownEditor/editor/elements/Blockquote.js +95 -37
- package/dist/MarkdownEditor/editor/elements/Break.js +56 -25
- package/dist/MarkdownEditor/editor/elements/Card/index.js +131 -52
- package/dist/MarkdownEditor/editor/elements/Code.js +89 -67
- package/dist/MarkdownEditor/editor/elements/Comment/index.js +79 -50
- package/dist/MarkdownEditor/editor/elements/ErrorBoundary.js +117 -21
- package/dist/MarkdownEditor/editor/elements/FootnoteDefinition.js +83 -64
- package/dist/MarkdownEditor/editor/elements/FootnoteReference.js +115 -41
- package/dist/MarkdownEditor/editor/elements/Head.js +131 -67
- package/dist/MarkdownEditor/editor/elements/Hr.js +63 -38
- package/dist/MarkdownEditor/editor/elements/Image/index.js +636 -494
- package/dist/MarkdownEditor/editor/elements/InlineKatex.js +60 -44
- package/dist/MarkdownEditor/editor/elements/Katex.js +71 -55
- package/dist/MarkdownEditor/editor/elements/LinkCard/index.js +79 -175
- package/dist/MarkdownEditor/editor/elements/LinkCard/style.js +130 -100
- package/dist/MarkdownEditor/editor/elements/List/List.js +96 -69
- package/dist/MarkdownEditor/editor/elements/List/ListItem.js +422 -247
- package/dist/MarkdownEditor/editor/elements/List/index.js +1 -5
- package/dist/MarkdownEditor/editor/elements/List/style.js +131 -117
- package/dist/MarkdownEditor/editor/elements/Media.js +637 -519
- package/dist/MarkdownEditor/editor/elements/Mermaid.js +79 -54
- package/dist/MarkdownEditor/editor/elements/Paragraph.js +144 -83
- package/dist/MarkdownEditor/editor/elements/Schema.js +167 -128
- package/dist/MarkdownEditor/editor/elements/Table/ReadonlyTableComponent.js +211 -178
- package/dist/MarkdownEditor/editor/elements/Table/SimpleTable.js +73 -49
- package/dist/MarkdownEditor/editor/elements/Table/Table.js +285 -204
- package/dist/MarkdownEditor/editor/elements/Table/TableCellIndex/index.js +397 -280
- package/dist/MarkdownEditor/editor/elements/Table/TableCellIndex/style.js +126 -101
- package/dist/MarkdownEditor/editor/elements/Table/TableCellIndexSpacer/index.js +381 -276
- package/dist/MarkdownEditor/editor/elements/Table/TableCellIndexSpacer/style.js +120 -98
- package/dist/MarkdownEditor/editor/elements/Table/TableContext.js +64 -21
- package/dist/MarkdownEditor/editor/elements/Table/TableRowIndex/index.js +52 -42
- package/dist/MarkdownEditor/editor/elements/Table/TableRowIndex/style.js +69 -39
- package/dist/MarkdownEditor/editor/elements/Table/Td/index.js +126 -72
- package/dist/MarkdownEditor/editor/elements/Table/Td/style.js +85 -55
- package/dist/MarkdownEditor/editor/elements/Table/index.js +204 -105
- package/dist/MarkdownEditor/editor/elements/Table/style.js +244 -233
- package/dist/MarkdownEditor/editor/elements/Table/useScrollShadow.js +119 -62
- package/dist/MarkdownEditor/editor/elements/TagPopup/index.js +438 -276
- package/dist/MarkdownEditor/editor/elements/TagPopup/style.js +103 -77
- package/dist/MarkdownEditor/editor/elements/index.js +437 -424
- package/dist/MarkdownEditor/editor/parser/json-parse.js +38 -9
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +1753 -1168
- package/dist/MarkdownEditor/editor/parser/parserMdToSchema.js +16 -20
- package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +1021 -606
- package/dist/MarkdownEditor/editor/parser/remarkParse.js +158 -102
- package/dist/MarkdownEditor/editor/plugins/catchError.js +78 -17
- package/dist/MarkdownEditor/editor/plugins/elements.js +458 -342
- package/dist/MarkdownEditor/editor/plugins/handlePaste.js +752 -300
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/arrow.js +215 -129
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/backspace.js +325 -180
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/enter.js +576 -418
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/match.js +157 -47
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/tab.js +331 -209
- package/dist/MarkdownEditor/editor/plugins/index.js +0 -1
- package/dist/MarkdownEditor/editor/plugins/insertParsedHtmlNodes.js +1245 -507
- package/dist/MarkdownEditor/editor/plugins/parseMarkdownToNodesAndInsert.js +36 -24
- package/dist/MarkdownEditor/editor/plugins/useHighlight.js +267 -116
- package/dist/MarkdownEditor/editor/plugins/useKeyboard.js +234 -160
- package/dist/MarkdownEditor/editor/plugins/useOnchange.js +253 -92
- package/dist/MarkdownEditor/editor/plugins/withMarkdown.js +728 -439
- package/dist/MarkdownEditor/editor/store.js +1819 -1389
- package/dist/MarkdownEditor/editor/style.js +551 -506
- package/dist/MarkdownEditor/editor/tagStyles.js +43 -43
- package/dist/MarkdownEditor/editor/tools/DragHandle.js +56 -54
- package/dist/MarkdownEditor/editor/tools/InsertAutocomplete.js +1049 -732
- package/dist/MarkdownEditor/editor/tools/InsertLink.js +232 -181
- package/dist/MarkdownEditor/editor/tools/Leading.js +566 -303
- package/dist/MarkdownEditor/editor/tools/ToolBar/BaseBar.js +415 -377
- package/dist/MarkdownEditor/editor/tools/ToolBar/FloatBar.js +162 -125
- package/dist/MarkdownEditor/editor/tools/ToolBar/ReadonlyBaseBar.js +480 -258
- package/dist/MarkdownEditor/editor/tools/ToolBar/ToolBar.js +44 -44
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/ClearFormatButton.js +20 -35
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/ColorPickerButton.js +69 -73
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/FormatButton.js +13 -19
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/FormattingTools.js +34 -41
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/HeadingDropdown.js +53 -47
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/LinkButton.js +11 -19
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/ToolBarItem.js +23 -43
- package/dist/MarkdownEditor/editor/tools/ToolBar/components/UndoRedoButtons.js +14 -25
- package/dist/MarkdownEditor/editor/tools/ToolBar/config/toolsConfig.js +139 -102
- package/dist/MarkdownEditor/editor/tools/ToolBar/floatBarStyle.js +95 -65
- package/dist/MarkdownEditor/editor/tools/ToolBar/hooks/useToolBarLogic.js +252 -161
- package/dist/MarkdownEditor/editor/tools/ToolBar/index.js +14 -24
- package/dist/MarkdownEditor/editor/tools/ToolBar/toolBarStyle.js +95 -65
- package/dist/MarkdownEditor/editor/tools/insertAutocompleteStyle.js +82 -52
- package/dist/MarkdownEditor/editor/types/Table.js +1 -0
- package/dist/MarkdownEditor/editor/utils/InlineChromiumBugfix.js +11 -16
- package/dist/MarkdownEditor/editor/utils/ace.js +136 -40
- package/dist/MarkdownEditor/editor/utils/docx/docxDeserializer.js +29 -32
- package/dist/MarkdownEditor/editor/utils/docx/index.js +0 -1
- package/dist/MarkdownEditor/editor/utils/docx/module.js +193 -164
- package/dist/MarkdownEditor/editor/utils/docx/utils.js +113 -98
- package/dist/MarkdownEditor/editor/utils/dom.js +119 -90
- package/dist/MarkdownEditor/editor/utils/editorUtils.js +1369 -906
- package/dist/MarkdownEditor/editor/utils/htmlToMarkdown.js +196 -184
- package/dist/MarkdownEditor/editor/utils/index.js +354 -215
- package/dist/MarkdownEditor/editor/utils/isMarkdown.js +56 -44
- package/dist/MarkdownEditor/editor/utils/keyboard.js +1229 -664
- package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +294 -76
- package/dist/MarkdownEditor/editor/utils/media.js +274 -99
- package/dist/MarkdownEditor/editor/utils/path.js +22 -16
- package/dist/MarkdownEditor/editor/utils/performanceMonitor.js +370 -168
- package/dist/MarkdownEditor/editor/utils/useLocalState.js +96 -37
- package/dist/MarkdownEditor/el.js +1 -0
- package/dist/MarkdownEditor/hooks/editor.js +123 -41
- package/dist/MarkdownEditor/hooks/subscribe.js +18 -15
- package/dist/MarkdownEditor/index.js +118 -30
- package/dist/MarkdownEditor/plugin.js +2 -5
- package/dist/MarkdownEditor/style.js +96 -66
- package/dist/MarkdownEditor/types.js +1 -0
- package/dist/MarkdownEditor/utils/exportHtml.js +42 -83
- package/dist/MarkdownEditor/utils/native-table/index.js +0 -1
- package/dist/MarkdownEditor/utils/native-table/native-table-editor.js +337 -222
- package/dist/MarkdownEditor/utils/native-table/native-table-keyboard.js +201 -113
- package/dist/MarkdownInputField/AttachmentButton/AttachmentButtonPopover.d.ts +4 -0
- package/dist/MarkdownInputField/AttachmentButton/AttachmentButtonPopover.js +277 -82
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileIcon.js +62 -33
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileListItem.js +147 -125
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/index.js +174 -129
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/style.js +263 -237
- package/dist/MarkdownInputField/AttachmentButton/index.js +480 -205
- package/dist/MarkdownInputField/AttachmentButton/style.js +143 -114
- package/dist/MarkdownInputField/AttachmentButton/types.js +3 -0
- package/dist/MarkdownInputField/AttachmentButton/utils.d.ts +60 -0
- package/dist/MarkdownInputField/AttachmentButton/utils.js +365 -33
- package/dist/MarkdownInputField/BeforeToolContainer/BeforeToolContainer.js +438 -404
- package/dist/MarkdownInputField/Enlargement/index.js +7 -17
- package/dist/MarkdownInputField/FileMapView/FileMapViewItem.js +193 -216
- package/dist/MarkdownInputField/FileMapView/index.js +387 -174
- package/dist/MarkdownInputField/FileMapView/style.js +281 -259
- package/dist/MarkdownInputField/FilePaste/index.js +239 -65
- package/dist/MarkdownInputField/FileUploadManager/index.js +504 -170
- package/dist/MarkdownInputField/MarkdownInputField.js +819 -549
- package/dist/MarkdownInputField/QuickActions/index.js +304 -134
- package/dist/MarkdownInputField/RefinePromptButton/index.js +24 -33
- package/dist/MarkdownInputField/RefinePromptButton/style.js +99 -73
- package/dist/MarkdownInputField/SendActions/index.js +179 -197
- package/dist/MarkdownInputField/SendButton/index.js +150 -110
- package/dist/MarkdownInputField/SendButton/style.js +95 -64
- package/dist/MarkdownInputField/SkillModeBar/hooks/index.js +3 -5
- package/dist/MarkdownInputField/SkillModeBar/hooks/useSkillModeState.js +51 -26
- package/dist/MarkdownInputField/SkillModeBar/index.js +119 -106
- package/dist/MarkdownInputField/SkillModeBar/style.js +124 -98
- package/dist/MarkdownInputField/Suggestion/index.js +391 -154
- package/dist/MarkdownInputField/TopOperatingArea/index.js +37 -44
- package/dist/MarkdownInputField/TopOperatingArea/style.js +98 -81
- package/dist/MarkdownInputField/VoiceInput/index.js +210 -82
- package/dist/MarkdownInputField/VoiceInput/style.js +85 -59
- package/dist/MarkdownInputField/VoiceInputManager/index.js +321 -94
- package/dist/MarkdownInputField/style.js +296 -233
- package/dist/Plugins/chart/AreaChart/index.js +541 -393
- package/dist/Plugins/chart/AreaChart/style.js +114 -90
- package/dist/Plugins/chart/BarChart/index.d.ts +4 -0
- package/dist/Plugins/chart/BarChart/index.js +865 -697
- package/dist/Plugins/chart/BarChart/style.js +114 -90
- package/dist/Plugins/chart/ChartAttrToolBar/ChartAttrToolBarStyle.js +82 -52
- package/dist/Plugins/chart/ChartAttrToolBar/index.js +94 -65
- package/dist/Plugins/chart/ChartMark/Area.js +176 -150
- package/dist/Plugins/chart/ChartMark/Bar.js +181 -152
- package/dist/Plugins/chart/ChartMark/Column.js +181 -151
- package/dist/Plugins/chart/ChartMark/Container.js +116 -75
- package/dist/Plugins/chart/ChartMark/Line.js +179 -151
- package/dist/Plugins/chart/ChartMark/Pie.js +79 -63
- package/dist/Plugins/chart/ChartMark/index.js +6 -13
- package/dist/Plugins/chart/ChartMark/useChart.js +1 -0
- package/dist/Plugins/chart/ChartRender.js +981 -696
- package/dist/Plugins/chart/ChartStatistic/index.js +47 -62
- package/dist/Plugins/chart/ChartStatistic/style.js +142 -143
- package/dist/Plugins/chart/ChartStatistic/utils.js +37 -27
- package/dist/Plugins/chart/DonutChart/Legend.js +94 -124
- package/dist/Plugins/chart/DonutChart/constants.js +4 -11
- package/dist/Plugins/chart/DonutChart/hooks.js +183 -112
- package/dist/Plugins/chart/DonutChart/index.js +588 -516
- package/dist/Plugins/chart/DonutChart/plugins.js +47 -44
- package/dist/Plugins/chart/DonutChart/style.js +186 -175
- package/dist/Plugins/chart/DonutChart/types.js +1 -0
- package/dist/Plugins/chart/FunnelChart/index.js +844 -647
- package/dist/Plugins/chart/FunnelChart/style.js +97 -71
- package/dist/Plugins/chart/LineChart/index.js +516 -393
- package/dist/Plugins/chart/LineChart/style.js +114 -90
- package/dist/Plugins/chart/RadarChart/index.js +580 -582
- package/dist/Plugins/chart/RadarChart/style.js +122 -112
- package/dist/Plugins/chart/ScatterChart/index.js +633 -640
- package/dist/Plugins/chart/ScatterChart/style.js +108 -94
- package/dist/Plugins/chart/components/ChartContainer/ChartContainer.js +151 -80
- package/dist/Plugins/chart/components/ChartContainer/ChartErrorBoundary.js +160 -41
- package/dist/Plugins/chart/components/ChartContainer/ChartErrorBoundaryExample.js +80 -62
- package/dist/Plugins/chart/components/ChartContainer/index.js +2 -7
- package/dist/Plugins/chart/components/ChartContainer/style.js +121 -91
- package/dist/Plugins/chart/components/ChartFilter/ChartFilter.js +58 -90
- package/dist/Plugins/chart/components/ChartFilter/style.js +169 -154
- package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.js +54 -59
- package/dist/Plugins/chart/components/ChartToolBar/style.js +132 -117
- package/dist/Plugins/chart/components/icons/TimeIcon.js +20 -26
- package/dist/Plugins/chart/components/index.js +32 -34
- package/dist/Plugins/chart/const.js +34 -25
- package/dist/Plugins/chart/hooks/useChartStatistic.js +1 -0
- package/dist/Plugins/chart/index.js +436 -339
- package/dist/Plugins/chart/loadChartRuntime.js +209 -110
- package/dist/Plugins/chart/utils.js +311 -87
- package/dist/Plugins/code/CodeUI/Katex/Katex.js +112 -66
- package/dist/Plugins/code/components/AceEditor.js +334 -237
- package/dist/Plugins/code/components/AceEditorContainer.js +23 -32
- package/dist/Plugins/code/components/CodeContainer.js +41 -56
- package/dist/Plugins/code/components/CodeRenderer.js +202 -155
- package/dist/Plugins/code/components/CodeToolbar.js +137 -181
- package/dist/Plugins/code/components/HtmlPreview.js +19 -22
- package/dist/Plugins/code/components/LanguageSelector.js +162 -96
- package/dist/Plugins/code/components/LoadImage.js +145 -46
- package/dist/Plugins/code/components/ThinkBlock.js +38 -42
- package/dist/Plugins/code/components/index.js +13 -23
- package/dist/Plugins/code/hooks/index.js +7 -9
- package/dist/Plugins/code/hooks/useCodeEditorState.js +139 -62
- package/dist/Plugins/code/hooks/useRenderConditions.js +31 -23
- package/dist/Plugins/code/hooks/useToolbarConfig.js +44 -46
- package/dist/Plugins/code/index.js +141 -89
- package/dist/Plugins/code/langIconMap.js +400 -108
- package/dist/Plugins/code/langIcons/AbapIcon.js +90 -57
- package/dist/Plugins/code/langIcons/ActionscriptIcon.js +89 -56
- package/dist/Plugins/code/langIcons/AdaIcon.js +89 -52
- package/dist/Plugins/code/langIcons/ApacheIcon.js +205 -254
- package/dist/Plugins/code/langIcons/ApexIcon.js +108 -82
- package/dist/Plugins/code/langIcons/AplIcon.js +90 -54
- package/dist/Plugins/code/langIcons/ApplescriptIcon.js +89 -56
- package/dist/Plugins/code/langIcons/AstroIcon.js +91 -58
- package/dist/Plugins/code/langIcons/AwkIcon.js +98 -68
- package/dist/Plugins/code/langIcons/BallerinaIcon.js +92 -59
- package/dist/Plugins/code/langIcons/BatIcon.js +158 -229
- package/dist/Plugins/code/langIcons/BicepIcon.js +91 -58
- package/dist/Plugins/code/langIcons/BladeIcon.js +90 -58
- package/dist/Plugins/code/langIcons/CIcon.js +90 -55
- package/dist/Plugins/code/langIcons/CadenceIcon.js +89 -56
- package/dist/Plugins/code/langIcons/ClojureIcon.js +96 -75
- package/dist/Plugins/code/langIcons/CmakeIcon.js +93 -62
- package/dist/Plugins/code/langIcons/CobolIcon.js +99 -70
- package/dist/Plugins/code/langIcons/CodeqlIcon.js +96 -76
- package/dist/Plugins/code/langIcons/CoffeeIcon.js +89 -56
- package/dist/Plugins/code/langIcons/ConsoleIcon.js +89 -56
- package/dist/Plugins/code/langIcons/CppIcon.js +90 -55
- package/dist/Plugins/code/langIcons/CrystalIcon.js +90 -57
- package/dist/Plugins/code/langIcons/CsharpIcon.js +90 -59
- package/dist/Plugins/code/langIcons/CssIcon.js +89 -52
- package/dist/Plugins/code/langIcons/DIcon.js +90 -53
- package/dist/Plugins/code/langIcons/DartIcon.js +92 -71
- package/dist/Plugins/code/langIcons/DatabaseIcon.js +90 -57
- package/dist/Plugins/code/langIcons/DiffIcon.js +90 -57
- package/dist/Plugins/code/langIcons/DockerIcon.js +89 -56
- package/dist/Plugins/code/langIcons/DotenvIcon.js +94 -56
- package/dist/Plugins/code/langIcons/ElixirIcon.js +91 -58
- package/dist/Plugins/code/langIcons/ElmIcon.js +105 -58
- package/dist/Plugins/code/langIcons/ErbIcon.js +90 -54
- package/dist/Plugins/code/langIcons/ErlangIcon.js +89 -56
- package/dist/Plugins/code/langIcons/FsharpIcon.js +93 -62
- package/dist/Plugins/code/langIcons/GdscriptIcon.js +96 -88
- package/dist/Plugins/code/langIcons/GlslIcon.js +90 -58
- package/dist/Plugins/code/langIcons/GnuplotIcon.js +98 -77
- package/dist/Plugins/code/langIcons/GoIcon.js +114 -93
- package/dist/Plugins/code/langIcons/GraphqlIcon.js +106 -66
- package/dist/Plugins/code/langIcons/GroovyIcon.js +89 -56
- package/dist/Plugins/code/langIcons/HackIcon.js +97 -64
- package/dist/Plugins/code/langIcons/HamlIcon.js +89 -56
- package/dist/Plugins/code/langIcons/HandlebarsIcon.js +89 -56
- package/dist/Plugins/code/langIcons/HaskellIcon.js +93 -64
- package/dist/Plugins/code/langIcons/HclIcon.js +118 -93
- package/dist/Plugins/code/langIcons/HclLightIcon.js +118 -97
- package/dist/Plugins/code/langIcons/HjsonIcon.js +94 -62
- package/dist/Plugins/code/langIcons/HlslIcon.js +96 -76
- package/dist/Plugins/code/langIcons/HtmlIcon.js +89 -56
- package/dist/Plugins/code/langIcons/HttpIcon.js +89 -56
- package/dist/Plugins/code/langIcons/ImbaIcon.js +98 -65
- package/dist/Plugins/code/langIcons/IniIcon.js +90 -54
- package/dist/Plugins/code/langIcons/JavaIcon.js +89 -56
- package/dist/Plugins/code/langIcons/JavascriptIcon.js +89 -56
- package/dist/Plugins/code/langIcons/JinjaIcon.js +100 -68
- package/dist/Plugins/code/langIcons/Json5Icon.js +100 -82
- package/dist/Plugins/code/langIcons/JsonIcon.js +89 -56
- package/dist/Plugins/code/langIcons/JsonnetIcon.js +102 -86
- package/dist/Plugins/code/langIcons/JuliaIcon.js +105 -52
- package/dist/Plugins/code/langIcons/KotlinIcon.js +104 -74
- package/dist/Plugins/code/langIcons/KustoIcon.js +90 -57
- package/dist/Plugins/code/langIcons/LessIcon.js +90 -57
- package/dist/Plugins/code/langIcons/LiquidIcon.js +91 -58
- package/dist/Plugins/code/langIcons/LispIcon.js +89 -56
- package/dist/Plugins/code/langIcons/LuaIcon.js +93 -60
- package/dist/Plugins/code/langIcons/MakefileIcon.js +91 -58
- package/dist/Plugins/code/langIcons/MarkdownIcon.js +89 -56
- package/dist/Plugins/code/langIcons/MarkojsIcon.js +96 -73
- package/dist/Plugins/code/langIcons/MatlabIcon.js +93 -64
- package/dist/Plugins/code/langIcons/MdxIcon.js +90 -53
- package/dist/Plugins/code/langIcons/MermaidIcon.js +95 -64
- package/dist/Plugins/code/langIcons/MojoIcon.js +95 -62
- package/dist/Plugins/code/langIcons/NginxIcon.js +94 -61
- package/dist/Plugins/code/langIcons/NimIcon.js +91 -54
- package/dist/Plugins/code/langIcons/NixIcon.js +92 -56
- package/dist/Plugins/code/langIcons/ObjectiveCIcon.js +90 -59
- package/dist/Plugins/code/langIcons/ObjectiveCppIcon.js +90 -57
- package/dist/Plugins/code/langIcons/OcamlIcon.js +90 -61
- package/dist/Plugins/code/langIcons/PascalIcon.js +95 -55
- package/dist/Plugins/code/langIcons/Perl6Icon.js +299 -320
- package/dist/Plugins/code/langIcons/PerlIcon.js +89 -56
- package/dist/Plugins/code/langIcons/PhpIcon.js +89 -52
- package/dist/Plugins/code/langIcons/PostcssIcon.js +130 -113
- package/dist/Plugins/code/langIcons/PowershellIcon.js +91 -58
- package/dist/Plugins/code/langIcons/PrismaIcon.js +97 -68
- package/dist/Plugins/code/langIcons/PrologIcon.js +91 -58
- package/dist/Plugins/code/langIcons/ProtoIcon.js +94 -68
- package/dist/Plugins/code/langIcons/PugIcon.js +177 -145
- package/dist/Plugins/code/langIcons/PuppetIcon.js +96 -52
- package/dist/Plugins/code/langIcons/PurescriptIcon.js +93 -61
- package/dist/Plugins/code/langIcons/PythonIcon.js +90 -61
- package/dist/Plugins/code/langIcons/RIcon.js +89 -52
- package/dist/Plugins/code/langIcons/RazorIcon.js +90 -57
- package/dist/Plugins/code/langIcons/ReactIcon.js +89 -56
- package/dist/Plugins/code/langIcons/ReactTsIcon.js +90 -57
- package/dist/Plugins/code/langIcons/RubyIcon.js +91 -58
- package/dist/Plugins/code/langIcons/RustIcon.js +89 -56
- package/dist/Plugins/code/langIcons/SasIcon.js +89 -52
- package/dist/Plugins/code/langIcons/SassIcon.js +90 -57
- package/dist/Plugins/code/langIcons/ScalaIcon.js +96 -53
- package/dist/Plugins/code/langIcons/SchemeIcon.js +91 -58
- package/dist/Plugins/code/langIcons/ShaderlabIcon.js +89 -56
- package/dist/Plugins/code/langIcons/SolidityIcon.js +94 -52
- package/dist/Plugins/code/langIcons/SparqlIcon.js +94 -64
- package/dist/Plugins/code/langIcons/StataIcon.js +126 -108
- package/dist/Plugins/code/langIcons/StylusIcon.js +92 -59
- package/dist/Plugins/code/langIcons/SvelteIcon.js +91 -58
- package/dist/Plugins/code/langIcons/SwiftIcon.js +90 -57
- package/dist/Plugins/code/langIcons/SystemverilogIcon.js +115 -102
- package/dist/Plugins/code/langIcons/TclIcon.js +89 -52
- package/dist/Plugins/code/langIcons/TexIcon.js +99 -65
- package/dist/Plugins/code/langIcons/TomlIcon.js +94 -70
- package/dist/Plugins/code/langIcons/TwigIcon.js +89 -56
- package/dist/Plugins/code/langIcons/TypescriptIcon.js +93 -60
- package/dist/Plugins/code/langIcons/VerilogIcon.js +89 -56
- package/dist/Plugins/code/langIcons/VhdlIcon.js +94 -64
- package/dist/Plugins/code/langIcons/VimIcon.js +278 -420
- package/dist/Plugins/code/langIcons/VueIcon.js +92 -59
- package/dist/Plugins/code/langIcons/WebassemblyIcon.js +103 -76
- package/dist/Plugins/code/langIcons/WenyanIcon.js +104 -100
- package/dist/Plugins/code/langIcons/WgslIcon.js +93 -77
- package/dist/Plugins/code/langIcons/WolframlanguageIcon.js +100 -71
- package/dist/Plugins/code/langIcons/XmlIcon.js +89 -52
- package/dist/Plugins/code/langIcons/XslIcon.js +94 -66
- package/dist/Plugins/code/langIcons/YamlIcon.js +89 -56
- package/dist/Plugins/code/langIcons/ZigIcon.js +106 -81
- package/dist/Plugins/code/langIcons/index.js +128 -259
- package/dist/Plugins/code/utils/index.js +5 -5
- package/dist/Plugins/code/utils/langOptions.js +86 -11
- package/dist/Plugins/defaultPlugins.js +9 -13
- package/dist/Plugins/formatter/index.js +205 -105
- package/dist/Plugins/index.js +6 -2
- package/dist/Plugins/katex/InlineKatex.js +196 -107
- package/dist/Plugins/katex/Katex.js +139 -65
- package/dist/Plugins/katex/index.js +163 -103
- package/dist/Plugins/mermaid/Mermaid.js +472 -197
- package/dist/Plugins/mermaid/index.js +237 -142
- package/dist/Quote/index.js +112 -73
- package/dist/Quote/style.js +176 -160
- package/dist/Schema/SchemaEditor/AceEditorWrapper.js +163 -119
- package/dist/Schema/SchemaEditor/index.js +385 -275
- package/dist/Schema/SchemaEditor/style.js +261 -269
- package/dist/Schema/SchemaForm/index.js +443 -268
- package/dist/Schema/SchemaForm/types.js +1 -0
- package/dist/Schema/SchemaRenderer/index.js +973 -588
- package/dist/Schema/SchemaRenderer/templateEngine.js +106 -26
- package/dist/Schema/index.js +7 -11
- package/dist/Schema/types.js +1 -0
- package/dist/Schema/validator.js +74 -36
- package/dist/TaskList/index.js +197 -142
- package/dist/TaskList/style.js +143 -122
- package/dist/ThoughtChainList/CostMillis.js +88 -54
- package/dist/ThoughtChainList/DeepThink.js +187 -152
- package/dist/ThoughtChainList/DotAni/index.js +29 -14
- package/dist/ThoughtChainList/DotAni/style.js +82 -50
- package/dist/ThoughtChainList/FlipText/index.js +74 -30
- package/dist/ThoughtChainList/MarkdownEditor.js +126 -72
- package/dist/ThoughtChainList/RagRetrievalInfo.js +113 -145
- package/dist/ThoughtChainList/TableSql.js +413 -459
- package/dist/ThoughtChainList/ThoughtChainListItem.js +388 -222
- package/dist/ThoughtChainList/TitleInfo.js +189 -185
- package/dist/ThoughtChainList/ToolCall.js +429 -463
- package/dist/ThoughtChainList/WebSearch.js +192 -162
- package/dist/ThoughtChainList/index.js +449 -410
- package/dist/ThoughtChainList/style.js +253 -232
- package/dist/ThoughtChainList/types.js +1 -0
- package/dist/ToolUseBar/ToolUseBarItem.js +183 -139
- package/dist/ToolUseBar/ToolUseBarItemComponents.js +345 -276
- package/dist/ToolUseBar/ToolUseBarThink.js +335 -396
- package/dist/ToolUseBar/index.js +226 -113
- package/dist/ToolUseBar/style.js +334 -308
- package/dist/ToolUseBar/thinkStyle.js +350 -328
- package/dist/Types/common.js +1 -0
- package/dist/Types/index.js +4 -2
- package/dist/Types/message.js +1 -0
- package/dist/Utils/easings.js +9 -12
- package/dist/Utils/formatTime.js +41 -17
- package/dist/Utils/getScroll.js +41 -41
- package/dist/Utils/language.js +355 -150
- package/dist/Utils/proxySandbox/ProxySandbox.js +1637 -1076
- package/dist/Utils/proxySandbox/SecurityContextManager.js +607 -343
- package/dist/Utils/proxySandbox/index.js +554 -267
- package/dist/Utils/proxySandbox/types.js +187 -52
- package/dist/Utils/scrollTo.js +48 -56
- package/dist/Utils/throttleByAnimationFrame.js +46 -20
- package/dist/WelcomeMessage/index.js +106 -58
- package/dist/WelcomeMessage/style.js +80 -55
- package/dist/Workspace/Browser/index.js +102 -40
- package/dist/Workspace/Browser/style.js +62 -33
- package/dist/Workspace/File/DataSourceStrategy.js +419 -217
- package/dist/Workspace/File/FileComponent.js +1004 -791
- package/dist/Workspace/File/FileTypeProcessor.js +337 -184
- package/dist/Workspace/File/PreviewComponent.js +472 -532
- package/dist/Workspace/File/index.js +3 -10
- package/dist/Workspace/File/style.js +397 -424
- package/dist/Workspace/File/utils.js +160 -106
- package/dist/Workspace/HtmlPreview/index.js +238 -137
- package/dist/Workspace/HtmlPreview/style.js +99 -77
- package/dist/Workspace/RealtimeFollow/index.js +411 -413
- package/dist/Workspace/RealtimeFollow/style.js +299 -303
- package/dist/Workspace/Task/index.js +53 -35
- package/dist/Workspace/Task/style.js +99 -73
- package/dist/Workspace/index.js +332 -254
- package/dist/Workspace/style.js +165 -146
- package/dist/Workspace/types.js +471 -252
- package/dist/Workspace/utils/codeLanguageUtils.js +148 -129
- package/dist/Workspace/utils.js +28 -20
- package/dist/index.js +27 -17
- package/package.json +3 -2
|
@@ -1,1120 +1,1681 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
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
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
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
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
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
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
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
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
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
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
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
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
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
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
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
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
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
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
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
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
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
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
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
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
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
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
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
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
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
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
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
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
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
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
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
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
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
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
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
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1597
|
+
*/ key: "isRunning",
|
|
1598
|
+
value: function isRunning() {
|
|
1599
|
+
return this.isActive;
|
|
1600
|
+
}
|
|
1601
|
+
},
|
|
1602
|
+
{
|
|
1603
|
+
/**
|
|
1080
1604
|
* 添加自定义全局变量
|
|
1081
|
-
*/
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
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
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
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
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
|
|
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
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
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
|
-
};
|