CatPtain commited on
Commit
ffe4e3d
·
verified ·
1 Parent(s): 4feec70

Upload canvasRenderer.ts

Browse files
frontend/src/utils/canvasRenderer.ts CHANGED
@@ -3,7 +3,11 @@
3
  * 用于将DOM元素渲染为Canvas并转换为Base64图像
4
  */
5
 
6
- import html2canvas from 'html2canvas';
 
 
 
 
7
 
8
  // 渲染选项接口
9
  interface RenderOptions {
@@ -32,12 +36,15 @@ export async function renderElementToCanvas(
32
  timeout = 5000
33
  } = options;
34
 
35
- return new Promise((resolve, reject) => {
36
  const timeoutId = setTimeout(() => {
37
  reject(new Error('Canvas rendering timeout'));
38
  }, timeout);
39
 
40
  try {
 
 
 
41
  // 使用html2canvas进行渲染
42
  html2canvas(element, {
43
  scale,
 
3
  * 用于将DOM元素渲染为Canvas并转换为Base64图像
4
  */
5
 
6
+ // Dynamic import for html2canvas to resolve bundling issues
7
+ const getHtml2Canvas = async () => {
8
+ const { default: html2canvas } = await import('html2canvas');
9
+ return html2canvas;
10
+ };
11
 
12
  // 渲染选项接口
13
  interface RenderOptions {
 
36
  timeout = 5000
37
  } = options;
38
 
39
+ return new Promise(async (resolve, reject) => {
40
  const timeoutId = setTimeout(() => {
41
  reject(new Error('Canvas rendering timeout'));
42
  }, timeout);
43
 
44
  try {
45
+ // 动态导入html2canvas
46
+ const html2canvas = await getHtml2Canvas();
47
+
48
  // 使用html2canvas进行渲染
49
  html2canvas(element, {
50
  scale,