Skip to content

Commit

Permalink
fix: fix exceptional canvas options when init in node env
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed May 30, 2024
1 parent 04239f8 commit e095a2a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/g6/__tests__/utils/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ export function createGraphCanvas(
container.style.height = `${height}px`;

resetEntityCounter();

let extraOptions = {};

console.log(!!globalThis.window);

if (globalThis.process) {
const offscreenNodeCanvas = {
getContext: () => context,
} as unknown as HTMLCanvasElement;
const context = new OffscreenCanvasContext(offscreenNodeCanvas);
// 下列参数仅在 node 环境下需要传入 / These parameters only need to be passed in the node environment
extraOptions = {
document: container.ownerDocument,
offscreenCanvas: offscreenNodeCanvas,
};
}

const offscreenNodeCanvas = {
getContext: () => context,
} as unknown as HTMLCanvasElement;
Expand All @@ -51,9 +68,7 @@ export function createGraphCanvas(
width,
height,
renderer: () => instance,
// @ts-expect-error document offscreenCanvas is not in the type definition
document: container.ownerDocument,
offscreenCanvas: offscreenNodeCanvas,
...extraOptions,
});
}

Expand Down

0 comments on commit e095a2a

Please sign in to comment.