@ant-design/agentic-ui 2.0.22 → 2.0.24
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/Components/GradientText/index.d.ts +2 -1
- package/dist/Components/GradientText/index.js +3 -2
- package/dist/Components/GradientText/style.js +3 -8
- package/dist/Components/TextAnimate/index.d.ts +1 -0
- package/dist/Components/TextAnimate/index.js +27 -16
- package/dist/Components/TypingAnimation/index.d.ts +1 -1
- package/dist/Components/TypingAnimation/index.js +9 -9
- package/dist/MarkdownEditor/editor/components/LazyElement/index.js +36 -4
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.d.ts +4 -0
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +245 -344
- package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +74 -56
- package/dist/MarkdownEditor/editor/store.d.ts +36 -0
- package/dist/MarkdownEditor/editor/store.js +208 -76
- package/dist/MarkdownInputField/MarkdownInputField.js +12 -1
- package/dist/MarkdownInputField/SendButton/index.js +3 -0
- package/dist/Schema/SchemaRenderer/index.js +80 -55
- package/dist/Utils/proxySandbox/ProxySandbox.d.ts +32 -0
- package/dist/Utils/proxySandbox/ProxySandbox.js +170 -128
- package/dist/WelcomeMessage/index.d.ts +2 -2
- package/dist/WelcomeMessage/index.js +8 -5
- package/dist/WelcomeMessage/style.js +0 -1
- package/package.json +1 -1
|
@@ -56,6 +56,85 @@ import {
|
|
|
56
56
|
import { mdDataSchemaValidator } from "../validator";
|
|
57
57
|
import { TemplateEngine } from "./templateEngine";
|
|
58
58
|
export * from "./templateEngine";
|
|
59
|
+
var createSandboxInstance = (sandboxConfig) => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
return createSandbox(__spreadProps(__spreadValues({}, DEFAULT_SANDBOX_CONFIG), {
|
|
62
|
+
allowDOM: (_a = sandboxConfig.allowDOM) != null ? _a : true,
|
|
63
|
+
allowedGlobals: sandboxConfig.allowedGlobals || DEFAULT_SANDBOX_CONFIG.allowedGlobals,
|
|
64
|
+
forbiddenGlobals: sandboxConfig.forbiddenGlobals || DEFAULT_SANDBOX_CONFIG.forbiddenGlobals,
|
|
65
|
+
strictMode: (_b = sandboxConfig.strictMode) != null ? _b : true,
|
|
66
|
+
timeout: sandboxConfig.timeout || 3e3
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
var createSandboxContext = (shadowRoot) => {
|
|
70
|
+
return {
|
|
71
|
+
shadowRoot,
|
|
72
|
+
safeWindow: {
|
|
73
|
+
devicePixelRatio: typeof window !== "undefined" ? window.devicePixelRatio : 1,
|
|
74
|
+
innerWidth: typeof window !== "undefined" ? window.innerWidth : 1024,
|
|
75
|
+
innerHeight: typeof window !== "undefined" ? window.innerHeight : 768
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
var executeUnsafeScript = (script, shadowRoot) => {
|
|
80
|
+
console.warn("沙箱已禁用,使用不安全的脚本执行方式");
|
|
81
|
+
const scriptFn = new Function(
|
|
82
|
+
"shadowRoot",
|
|
83
|
+
"window",
|
|
84
|
+
script.textContent || ""
|
|
85
|
+
);
|
|
86
|
+
try {
|
|
87
|
+
scriptFn(shadowRoot, {
|
|
88
|
+
devicePixelRatio: window.devicePixelRatio
|
|
89
|
+
});
|
|
90
|
+
} catch (evalError) {
|
|
91
|
+
console.error("执行脚本错误:", evalError);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var executeExternalScript = (script, shadowRoot) => {
|
|
95
|
+
console.warn("外部脚本暂时不通过沙箱执行:", script.src);
|
|
96
|
+
try {
|
|
97
|
+
shadowRoot == null ? void 0 : shadowRoot.appendChild(script);
|
|
98
|
+
} catch (appendError) {
|
|
99
|
+
console.error("Error appending external script:", appendError);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var executeSandboxedScript = (script, shadowRoot, sandboxConfig) => __async(void 0, null, function* () {
|
|
103
|
+
const sandbox = createSandboxInstance(sandboxConfig);
|
|
104
|
+
try {
|
|
105
|
+
const result = yield sandbox.execute(
|
|
106
|
+
script.textContent || "",
|
|
107
|
+
createSandboxContext(shadowRoot)
|
|
108
|
+
);
|
|
109
|
+
if (!result.success && result.error) {
|
|
110
|
+
console.error("沙箱脚本执行错误:", result.error);
|
|
111
|
+
}
|
|
112
|
+
} catch (evalError) {
|
|
113
|
+
console.error("沙箱执行失败:", evalError);
|
|
114
|
+
} finally {
|
|
115
|
+
sandbox.destroy();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
var executeInlineScript = (script, shadowRoot, sandboxConfig) => __async(void 0, null, function* () {
|
|
119
|
+
if (!sandboxConfig.enabled) {
|
|
120
|
+
executeUnsafeScript(script, shadowRoot);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
yield executeSandboxedScript(script, shadowRoot, sandboxConfig);
|
|
124
|
+
});
|
|
125
|
+
var executeScript = (script, shadowRoot, sandboxConfig) => __async(void 0, null, function* () {
|
|
126
|
+
try {
|
|
127
|
+
if (!script.src && script.textContent) {
|
|
128
|
+
yield executeInlineScript(script, shadowRoot, sandboxConfig);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (script.src) {
|
|
132
|
+
executeExternalScript(script, shadowRoot);
|
|
133
|
+
}
|
|
134
|
+
} catch (scriptError) {
|
|
135
|
+
console.error("Script execution error:", scriptError);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
59
138
|
var ErrorBoundary = class extends Component {
|
|
60
139
|
constructor(props) {
|
|
61
140
|
super(props);
|
|
@@ -354,61 +433,7 @@ a:active {
|
|
|
354
433
|
}
|
|
355
434
|
});
|
|
356
435
|
scripts.forEach((script) => __async(void 0, null, function* () {
|
|
357
|
-
|
|
358
|
-
try {
|
|
359
|
-
if (!script.src && script.textContent) {
|
|
360
|
-
if (sandboxConfig.enabled) {
|
|
361
|
-
const sandbox = createSandbox(__spreadProps(__spreadValues({}, DEFAULT_SANDBOX_CONFIG), {
|
|
362
|
-
allowDOM: (_a2 = sandboxConfig.allowDOM) != null ? _a2 : true,
|
|
363
|
-
allowedGlobals: sandboxConfig.allowedGlobals || DEFAULT_SANDBOX_CONFIG.allowedGlobals,
|
|
364
|
-
forbiddenGlobals: sandboxConfig.forbiddenGlobals || DEFAULT_SANDBOX_CONFIG.forbiddenGlobals,
|
|
365
|
-
strictMode: (_b2 = sandboxConfig.strictMode) != null ? _b2 : true,
|
|
366
|
-
timeout: sandboxConfig.timeout || 3e3
|
|
367
|
-
}));
|
|
368
|
-
try {
|
|
369
|
-
const result = yield sandbox.execute(script.textContent, {
|
|
370
|
-
shadowRoot,
|
|
371
|
-
// 提供一个安全的 window 上下文
|
|
372
|
-
safeWindow: {
|
|
373
|
-
devicePixelRatio: typeof window !== "undefined" ? window.devicePixelRatio : 1,
|
|
374
|
-
innerWidth: typeof window !== "undefined" ? window.innerWidth : 1024,
|
|
375
|
-
innerHeight: typeof window !== "undefined" ? window.innerHeight : 768
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
if (!result.success && result.error) {
|
|
379
|
-
console.error("沙箱脚本执行错误:", result.error);
|
|
380
|
-
}
|
|
381
|
-
} catch (evalError) {
|
|
382
|
-
console.error("沙箱执行失败:", evalError);
|
|
383
|
-
} finally {
|
|
384
|
-
sandbox.destroy();
|
|
385
|
-
}
|
|
386
|
-
} else {
|
|
387
|
-
console.warn("沙箱已禁用,使用不安全的脚本执行方式");
|
|
388
|
-
const scriptFn = new Function(
|
|
389
|
-
"shadowRoot",
|
|
390
|
-
"window",
|
|
391
|
-
script.textContent
|
|
392
|
-
);
|
|
393
|
-
try {
|
|
394
|
-
scriptFn(shadowRoot, {
|
|
395
|
-
devicePixelRatio: window.devicePixelRatio
|
|
396
|
-
});
|
|
397
|
-
} catch (evalError) {
|
|
398
|
-
console.error("执行脚本错误:", evalError);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
} else if (script.src) {
|
|
402
|
-
console.warn("外部脚本暂时不通过沙箱执行:", script.src);
|
|
403
|
-
try {
|
|
404
|
-
shadowRoot == null ? void 0 : shadowRoot.appendChild(script);
|
|
405
|
-
} catch (appendError) {
|
|
406
|
-
console.error("Error appending external script:", appendError);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
} catch (scriptError) {
|
|
410
|
-
console.error("Script execution error:", scriptError);
|
|
411
|
-
}
|
|
436
|
+
yield executeScript(script, shadowRoot, sandboxConfig);
|
|
412
437
|
}));
|
|
413
438
|
} catch (contentError) {
|
|
414
439
|
console.error("Error processing content:", contentError);
|
|
@@ -117,6 +117,38 @@ export declare class ProxySandbox {
|
|
|
117
117
|
* 使用 Worker 执行代码以实现真正的超时控制
|
|
118
118
|
*/
|
|
119
119
|
private executeWithWorker;
|
|
120
|
+
/**
|
|
121
|
+
* 尝试序列化参数,失败则回退到同步执行
|
|
122
|
+
*/
|
|
123
|
+
private trySerializeParams;
|
|
124
|
+
/**
|
|
125
|
+
* 回退到同步执行
|
|
126
|
+
*/
|
|
127
|
+
private fallbackToSyncExecution;
|
|
128
|
+
/**
|
|
129
|
+
* 创建 Worker 实例
|
|
130
|
+
*/
|
|
131
|
+
private createWorkerInstance;
|
|
132
|
+
/**
|
|
133
|
+
* 生成 Worker 代码
|
|
134
|
+
*/
|
|
135
|
+
private generateWorkerCode;
|
|
136
|
+
/**
|
|
137
|
+
* 设置 Worker 超时
|
|
138
|
+
*/
|
|
139
|
+
private setupWorkerTimeout;
|
|
140
|
+
/**
|
|
141
|
+
* 设置 Worker 消息处理器
|
|
142
|
+
*/
|
|
143
|
+
private setupWorkerHandlers;
|
|
144
|
+
/**
|
|
145
|
+
* 处理控制台消息
|
|
146
|
+
*/
|
|
147
|
+
private handleConsoleMessage;
|
|
148
|
+
/**
|
|
149
|
+
* 清理 Worker 资源
|
|
150
|
+
*/
|
|
151
|
+
private cleanupWorker;
|
|
120
152
|
/**
|
|
121
153
|
* 执行代码的核心方法(同步版本)
|
|
122
154
|
*/
|
|
@@ -732,140 +732,182 @@ ${instrumented}`;
|
|
|
732
732
|
*/
|
|
733
733
|
executeWithWorker(code, injectedParams) {
|
|
734
734
|
return new Promise((resolve, reject) => {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
735
|
+
const serializableParams = this.trySerializeParams(
|
|
736
|
+
injectedParams,
|
|
737
|
+
code,
|
|
738
|
+
resolve,
|
|
739
|
+
reject
|
|
740
|
+
);
|
|
741
|
+
if (!serializableParams)
|
|
742
|
+
return;
|
|
743
|
+
const { worker, workerUrl, timeoutId } = this.createWorkerInstance(
|
|
744
|
+
code,
|
|
745
|
+
serializableParams,
|
|
746
|
+
resolve,
|
|
747
|
+
reject
|
|
748
|
+
);
|
|
749
|
+
if (!worker)
|
|
750
|
+
return;
|
|
751
|
+
this.setupWorkerHandlers(worker, workerUrl, timeoutId, resolve, reject);
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* 尝试序列化参数,失败则回退到同步执行
|
|
756
|
+
*/
|
|
757
|
+
trySerializeParams(injectedParams, code, resolve, reject) {
|
|
758
|
+
if (!injectedParams)
|
|
759
|
+
return {};
|
|
760
|
+
const serializableParams = {};
|
|
761
|
+
for (const [key, value] of Object.entries(injectedParams)) {
|
|
762
|
+
try {
|
|
763
|
+
JSON.stringify(value);
|
|
764
|
+
serializableParams[key] = value;
|
|
765
|
+
} catch (e) {
|
|
766
|
+
console.warn(`无法序列化注入参数 "${key}",回退到同步执行`);
|
|
767
|
+
this.fallbackToSyncExecution(code, injectedParams, resolve, reject);
|
|
768
|
+
return null;
|
|
758
769
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
770
|
+
}
|
|
771
|
+
return serializableParams;
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* 回退到同步执行
|
|
775
|
+
*/
|
|
776
|
+
fallbackToSyncExecution(code, injectedParams, resolve, reject) {
|
|
777
|
+
try {
|
|
778
|
+
const result = this.executeCode(code, injectedParams);
|
|
779
|
+
resolve(result);
|
|
780
|
+
} catch (error) {
|
|
781
|
+
reject(error);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* 创建 Worker 实例
|
|
786
|
+
*/
|
|
787
|
+
createWorkerInstance(code, serializableParams, resolve, reject) {
|
|
788
|
+
const workerCode = this.generateWorkerCode();
|
|
789
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
790
|
+
const workerUrl = URL.createObjectURL(blob);
|
|
791
|
+
try {
|
|
792
|
+
const worker = new Worker(workerUrl);
|
|
793
|
+
const timeoutId = this.setupWorkerTimeout(worker, workerUrl, reject);
|
|
794
|
+
worker.postMessage({
|
|
795
|
+
code,
|
|
796
|
+
config: this.config,
|
|
797
|
+
injectedParams: serializableParams
|
|
798
|
+
});
|
|
799
|
+
return { worker, workerUrl, timeoutId };
|
|
800
|
+
} catch (error) {
|
|
801
|
+
URL.revokeObjectURL(workerUrl);
|
|
802
|
+
console.warn("Worker 创建失败,回退到同步执行");
|
|
803
|
+
this.fallbackToSyncExecution(code, serializableParams, resolve, reject);
|
|
804
|
+
return { worker: null, workerUrl, timeoutId: 0 };
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* 生成 Worker 代码
|
|
809
|
+
*/
|
|
810
|
+
generateWorkerCode() {
|
|
811
|
+
return `
|
|
812
|
+
self.onmessage = function(e) {
|
|
813
|
+
const { code, config, injectedParams } = e.data;
|
|
814
|
+
|
|
815
|
+
try {
|
|
816
|
+
// 创建安全的执行环境
|
|
817
|
+
const safeGlobals = {
|
|
818
|
+
Math, Date, JSON, parseInt, parseFloat, isNaN, isFinite,
|
|
819
|
+
encodeURIComponent, decodeURIComponent, encodeURI, decodeURI,
|
|
820
|
+
String, Number, Boolean, Array, Object, RegExp,
|
|
821
|
+
Error, TypeError, ReferenceError, SyntaxError
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
// 添加自定义全局变量
|
|
825
|
+
Object.assign(safeGlobals, config.customGlobals || {});
|
|
826
|
+
|
|
827
|
+
// 添加注入的参数
|
|
828
|
+
Object.assign(safeGlobals, injectedParams || {});
|
|
762
829
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
830
|
+
// 添加 console(如果允许)
|
|
831
|
+
if (config.allowConsole) {
|
|
832
|
+
safeGlobals.console = {
|
|
833
|
+
log: (...args) => self.postMessage({ type: 'log', data: args }),
|
|
834
|
+
warn: (...args) => self.postMessage({ type: 'warn', data: args }),
|
|
835
|
+
error: (...args) => self.postMessage({ type: 'error', data: args }),
|
|
836
|
+
info: (...args) => self.postMessage({ type: 'info', data: args }),
|
|
837
|
+
debug: (...args) => self.postMessage({ type: 'debug', data: args })
|
|
770
838
|
};
|
|
771
|
-
|
|
772
|
-
// 添加自定义全局变量
|
|
773
|
-
Object.assign(safeGlobals, config.customGlobals || {});
|
|
774
|
-
|
|
775
|
-
// 添加注入的参数
|
|
776
|
-
Object.assign(safeGlobals, injectedParams || {});
|
|
777
|
-
|
|
778
|
-
// 添加 console(如果允许)
|
|
779
|
-
if (config.allowConsole) {
|
|
780
|
-
safeGlobals.console = {
|
|
781
|
-
log: (...args) => self.postMessage({ type: 'log', data: args }),
|
|
782
|
-
warn: (...args) => self.postMessage({ type: 'warn', data: args }),
|
|
783
|
-
error: (...args) => self.postMessage({ type: 'error', data: args }),
|
|
784
|
-
info: (...args) => self.postMessage({ type: 'info', data: args }),
|
|
785
|
-
debug: (...args) => self.postMessage({ type: 'debug', data: args })
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
// 创建执行函数
|
|
790
|
-
const wrappedCode = config.strictMode ? "'use strict';\\n" + code : code;
|
|
791
|
-
const func = new Function(...Object.keys(safeGlobals), 'return (function() { ' + wrappedCode + ' })()');
|
|
792
|
-
|
|
793
|
-
// 执行代码
|
|
794
|
-
const result = func(...Object.values(safeGlobals));
|
|
795
|
-
|
|
796
|
-
self.postMessage({ type: 'result', data: result });
|
|
797
|
-
} catch (error) {
|
|
798
|
-
self.postMessage({ type: 'error', data: { message: error.message, stack: error.stack } });
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
`;
|
|
802
|
-
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
803
|
-
const workerUrl = URL.createObjectURL(blob);
|
|
804
|
-
let worker;
|
|
805
|
-
let timeoutId;
|
|
806
|
-
try {
|
|
807
|
-
worker = new Worker(workerUrl);
|
|
808
|
-
timeoutId = window.setTimeout(() => {
|
|
809
|
-
if (worker) {
|
|
810
|
-
worker.terminate();
|
|
811
839
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
);
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
worker.terminate();
|
|
824
|
-
URL.revokeObjectURL(workerUrl);
|
|
825
|
-
resolve(data);
|
|
826
|
-
} else if (type === "error") {
|
|
827
|
-
if (timeoutId)
|
|
828
|
-
clearTimeout(timeoutId);
|
|
829
|
-
if (worker)
|
|
830
|
-
worker.terminate();
|
|
831
|
-
URL.revokeObjectURL(workerUrl);
|
|
832
|
-
reject(new Error(data.message));
|
|
833
|
-
} else if (type === "log" || type === "warn" || type === "error" || type === "info" || type === "debug") {
|
|
834
|
-
if (this.config.allowConsole) {
|
|
835
|
-
const consoleMethod = console[type];
|
|
836
|
-
if (typeof consoleMethod === "function") {
|
|
837
|
-
consoleMethod("[Sandbox]", ...data);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
worker.onerror = (error) => {
|
|
843
|
-
if (timeoutId)
|
|
844
|
-
clearTimeout(timeoutId);
|
|
845
|
-
if (worker)
|
|
846
|
-
worker.terminate();
|
|
847
|
-
URL.revokeObjectURL(workerUrl);
|
|
848
|
-
reject(new Error(`Worker error: ${error.message}`));
|
|
849
|
-
};
|
|
850
|
-
worker.postMessage({
|
|
851
|
-
code,
|
|
852
|
-
config: this.config,
|
|
853
|
-
injectedParams: serializableParams
|
|
854
|
-
});
|
|
855
|
-
} catch (error) {
|
|
856
|
-
if (timeoutId)
|
|
857
|
-
clearTimeout(timeoutId);
|
|
858
|
-
if (worker)
|
|
859
|
-
worker.terminate();
|
|
860
|
-
URL.revokeObjectURL(workerUrl);
|
|
861
|
-
try {
|
|
862
|
-
const result = this.executeCode(code, injectedParams);
|
|
863
|
-
resolve(result);
|
|
864
|
-
} catch (syncError) {
|
|
865
|
-
reject(syncError);
|
|
840
|
+
|
|
841
|
+
// 创建执行函数
|
|
842
|
+
const wrappedCode = config.strictMode ? "'use strict';\\n" + code : code;
|
|
843
|
+
const func = new Function(...Object.keys(safeGlobals), 'return (function() { ' + wrappedCode + ' })()');
|
|
844
|
+
|
|
845
|
+
// 执行代码
|
|
846
|
+
const result = func(...Object.values(safeGlobals));
|
|
847
|
+
|
|
848
|
+
self.postMessage({ type: 'result', data: result });
|
|
849
|
+
} catch (error) {
|
|
850
|
+
self.postMessage({ type: 'error', data: { message: error.message, stack: error.stack } });
|
|
866
851
|
}
|
|
852
|
+
};
|
|
853
|
+
`;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* 设置 Worker 超时
|
|
857
|
+
*/
|
|
858
|
+
setupWorkerTimeout(worker, workerUrl, reject) {
|
|
859
|
+
return window.setTimeout(() => {
|
|
860
|
+
worker.terminate();
|
|
861
|
+
URL.revokeObjectURL(workerUrl);
|
|
862
|
+
reject(
|
|
863
|
+
new Error(`Code execution timeout after ${this.config.timeout}ms`)
|
|
864
|
+
);
|
|
865
|
+
}, this.config.timeout);
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* 设置 Worker 消息处理器
|
|
869
|
+
*/
|
|
870
|
+
setupWorkerHandlers(worker, workerUrl, timeoutId, resolve, reject) {
|
|
871
|
+
worker.onmessage = (e) => {
|
|
872
|
+
const { type, data } = e.data;
|
|
873
|
+
if (type === "result") {
|
|
874
|
+
this.cleanupWorker(worker, workerUrl, timeoutId);
|
|
875
|
+
resolve(data);
|
|
876
|
+
return;
|
|
867
877
|
}
|
|
868
|
-
|
|
878
|
+
if (type === "error") {
|
|
879
|
+
this.cleanupWorker(worker, workerUrl, timeoutId);
|
|
880
|
+
reject(new Error(data.message));
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
this.handleConsoleMessage(type, data);
|
|
884
|
+
};
|
|
885
|
+
worker.onerror = (error) => {
|
|
886
|
+
this.cleanupWorker(worker, workerUrl, timeoutId);
|
|
887
|
+
reject(new Error(`Worker error: ${error.message}`));
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* 处理控制台消息
|
|
892
|
+
*/
|
|
893
|
+
handleConsoleMessage(type, data) {
|
|
894
|
+
if (!this.config.allowConsole)
|
|
895
|
+
return;
|
|
896
|
+
const consoleTypes = ["log", "warn", "error", "info", "debug"];
|
|
897
|
+
if (!consoleTypes.includes(type))
|
|
898
|
+
return;
|
|
899
|
+
const consoleMethod = console[type];
|
|
900
|
+
if (typeof consoleMethod === "function") {
|
|
901
|
+
consoleMethod("[Sandbox]", ...data);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* 清理 Worker 资源
|
|
906
|
+
*/
|
|
907
|
+
cleanupWorker(worker, workerUrl, timeoutId) {
|
|
908
|
+
clearTimeout(timeoutId);
|
|
909
|
+
worker.terminate();
|
|
910
|
+
URL.revokeObjectURL(workerUrl);
|
|
869
911
|
}
|
|
870
912
|
/**
|
|
871
913
|
* 执行代码的核心方法(同步版本)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TextAnimateProps } from '../Components/TextAnimate';
|
|
3
3
|
import { TypingAnimationProps } from '../Components/TypingAnimation';
|
|
4
|
-
export type WelcomeMessageTitleAnimateProps = Pick<
|
|
5
|
-
export type WelcomeMessageDescriptionAnimateProps = Pick<
|
|
4
|
+
export type WelcomeMessageTitleAnimateProps = Pick<TypingAnimationProps, 'duration' | 'typeSpeed' | 'deleteSpeed' | 'delay' | 'pauseDelay' | 'loop' | 'startOnView' | 'showCursor' | 'blinkCursor' | 'cursorStyle'>;
|
|
5
|
+
export type WelcomeMessageDescriptionAnimateProps = Pick<TextAnimateProps, 'delay' | 'duration' | 'variants' | 'by' | 'startOnView' | 'once' | 'animation'>;
|
|
6
6
|
/**
|
|
7
7
|
* WelcomeMessage 组件的属性接口
|
|
8
8
|
* @interface WelcomeMessageProps
|
|
@@ -41,18 +41,21 @@ var WelcomeMessage = ({
|
|
|
41
41
|
const { wrapSSR, hashId } = useStyle(prefixCls);
|
|
42
42
|
return wrapSSR(
|
|
43
43
|
/* @__PURE__ */ React.createElement("div", { className: classnames(prefixCls, hashId, rootClassName), style }, title && /* @__PURE__ */ React.createElement(
|
|
44
|
-
|
|
44
|
+
TypingAnimation,
|
|
45
45
|
__spreadProps(__spreadValues({
|
|
46
|
-
|
|
46
|
+
as: "div"
|
|
47
47
|
}, titleAnimateProps), {
|
|
48
|
-
as: "div",
|
|
49
48
|
className: classnames(`${prefixCls}-title`, classNames == null ? void 0 : classNames.title)
|
|
50
49
|
}),
|
|
51
50
|
title
|
|
52
51
|
), description && /* @__PURE__ */ React.createElement(
|
|
53
|
-
|
|
54
|
-
__spreadProps(__spreadValues({
|
|
52
|
+
TextAnimate,
|
|
53
|
+
__spreadProps(__spreadValues({
|
|
55
54
|
as: "div",
|
|
55
|
+
animation: "blurInUp",
|
|
56
|
+
by: "character",
|
|
57
|
+
once: true
|
|
58
|
+
}, descriptionAnimateProps), {
|
|
56
59
|
className: classnames(
|
|
57
60
|
`${prefixCls}-description`,
|
|
58
61
|
classNames == null ? void 0 : classNames.description
|