2d-inc / Flare-JS

Flare Javascript ES6 runtime with Canvas rendering.

Home Page:https://flare.rive.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Running in a WebWorker

sanbornhilland opened this issue · comments

Is it possible or are there plans to make this runnable in a WebWorker?

Currently I can almost get a3a8bc0 running in a web worker but it has a dependency on document.createElementNS which is not available in a WebWorker.

I'm unsure about the CanvasKit version because I don't know where the canvas-kit.js dependency is coming from.

No plans currently, but this is interesting. I'd like to see if we can support it.

We had to resort to using document.createElementNS for getting the an SVGMatrix transform class that worked across all browsers. Unfortunately DOMMatrix didn't work at all in Safari. https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix. We need this for transforming sub paths via Path2D addPath: https://developer.mozilla.org/en-US/docs/Web/API/Path2D/addPath.

CanvasKit is essentially WebAssembled SKIA, you can read more about it here: https://skia.org/user/modules/canvaskit

CanvasKit will support some of the more advanced path functionality and some other rendering features (like triangle geometry and more complex fills) we're currently working on in Flare. If you're willing to delve deeper, I'd encourage you to explore that path.

Thanks for looking into Flare!

@luigi-rosso Thanks for the background information. On the SKIA site it mentions that they are working on an NPM distribution. In the mean time is there a way I can get my hands on a build so that I can try running your canvaskit branch?

See #6 for an example that replaces createElementNS with svg.js to run in a WebWorker. That's the main change and it mostly seems to just work. Pretty cool. I'm not familiar with svg.js or the SVGMatrix class but if it's feasible to decouple Flare-JS from the DOM I think it would open up some interesting possibilities for people.