-
-
Notifications
You must be signed in to change notification settings - Fork 229
Add support for Canvas #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting @steel! 🙂 I will look into adding support for Canvas as soon as possible. However, being able to render graphics might be a bit challenging, but at least we can get support for the API. |
@capricorn86 Just use https://www.npmjs.com/package/canvas :D |
Are you saying that you can use that package to add in |
@Sparticuz I need to evaluate the package first. I am a bit worried that it is depended on OS system libraries to work, but on the other hand it seems quite popular 😅 |
FYI, adding canvas might mean impacting running tests in parallel for solutions using happy-dom for that: For example: I just wanted to point it out, no real opinion otherwise (maybe some config can control these "if there is a peer I will depend on it" cases to give control over them, or maybe that is too much config... idk) |
As @webChannelN said, node-canvas does not support workers environment |
And also consider that node-canvas doesn't have prebuilt binaries for ARM64 Automattic/node-canvas#1662 |
What about use jimp to implement a basic |
https://github.com/google/skia/tree/main/modules/canvaskit runs completely on WASM |
Also we could at least add a canvas element as a stub for a future implementation |
would like this implemented too. seems like |
Please don't use |
I'm thinking about picking this up soon. I think that going with something like Skia seems like the best bet as performance is an important aspect here. I can imagine this being used in some applications for server side rendering and then we don't want any performance bottlenecks. However, it probably has to be an optional dependency or a plugin. |
Hi @capricorn86 Any update on this and/or ETA on a resolution to this issue? |
@weastaughscottlogic the update is that this is still high priority, but it is not a small task. It will probably be the next thing after going through the queue of pull requests and major bugs. |
Is there an workaround for this, while happy-dom still doesn't support the Canvas AP ? |
if you're using vitest/jest you can use https://www.npmjs.com/package/vitest-canvas-mock or https://www.npmjs.com/package/jest-canvas-mock |
Any solution for the bun's test runner ? |
Hi! 👋 I'm currently working on #1332, which will add basic support for This ticket still has high priority and is one of the milestones for Happy DOM: |
Would it be possible to inject a custom canvas backend into the To illustrate what I mean, here's a simple pseudocode example in TypeScript: async function resolveCanvas() {
// Dynamically import the '@napi-rs/canvas' module
const impl = await import('@napi-rs/canvas');
return {
// Function to create a new canvas with specified width and height
createCanvas: (width, height) => impl.createCanvas(width, height),
// Function to get the context of the canvas, e.g., '2d' or 'webgl'
getContext: (canvas, ctx) => canvas.getContext(ctx),
// Function to load and register a custom font
loadFont: (fontData) => impl.GlobalFonts.register(fontData),
// Additional methods for other canvas-related operations can be added here
...
};
} In this pseudocode:
I believe this approach could make |
watch |
@twlite I also had something like that in mind. Creating an API that allow to inject the Canvas logic. Then create a standard package for Canvas that is part of Happy DOM. The API would then allow to use any compatible module basically. |
e.g.
document.createElement('canvas').getContext('2d')
The text was updated successfully, but these errors were encountered: