CanvasId for WebAssembly

Sure it is the stuff for the VTKCanvas.

var VTKCanvas = {
  initializeCanvasElement: (elementId, applyStyle) => {
    const canvasElem = findCanvasEventTarget(elementId, applyStyle);
    if (!canvasElem) {
      return;
    }
    const containerElem = canvasElem.parentElement;
    const body = document.querySelector("body");
    if (applyStyle) {
      if (body === containerElem) {
        body.style.margin = 0;
        body.style.width = "100vw";
        body.style.height = "100vh";
      } else {
        containerElem.style.position = "relative";
        containerElem.style.width = "100%";
        containerElem.style.height = "100%";
      }
      canvasElem.style.position = "absolute";
      canvasElem.style.top = 0;
      canvasElem.style.left = 0;
      canvasElem.style.width = "100%";
      canvasElem.style.height = "100%";
    }
  },
  getParentElementBoundingRectSize: elementId => {
    const canvasElem = findCanvasEventTarget(elementId);
    if (!canvasElem) {
      return 0;
    }
    const containerElem = canvasElem.parentElement;
    const dpr = window.devicePixelRatio;
    const width = containerElem.getBoundingClientRect().width;
    const height = containerElem.getBoundingClientRect().height;
    const w = Math.floor(width * dpr + .5);
    const h = Math.floor(height * dpr + .5);
    const sizePtr = _malloc(8);
    const idx = ((sizePtr) >>> 2);
    HEAP32.set([ w, h ], idx >>> 0);
    return sizePtr;
  }
};

It look super arbitrary that we write the height and width to the heap and shift is 0 bits. You are right, it is the new helper code from the vtkWebAssemblyRenderWindowInteractor.js.

Also, would it be a good idea to expose to JavaScript, vtkInitializeCanvasElement and use this for creating additional canvases and perhaps vtkGetParentElementBoundingRectSize for resizing canvases when resizing a canvas.

At the moment, we are starting and stopping the event loop in JavaScript and reusing a single interactor for two windows, changing the canvasId of course.

I borrowed some of your JavaScript wrapping code to make it easier for experimenting.