Flare-JS icon indicating copy to clipboard operation
Flare-JS copied to clipboard

Running in a WebWorker

Open sanbornhilland opened this issue 6 years ago • 3 comments

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

Currently I can almost get a3a8bc0f5 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.

sanbornhilland avatar Dec 12 '18 20:12 sanbornhilland

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 avatar Dec 13 '18 15:12 luigi-rosso

@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?

sanbornhilland avatar Dec 13 '18 16:12 sanbornhilland

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.

sanbornhilland avatar Dec 13 '18 18:12 sanbornhilland