const assert = require('assert')

function createGL (opts) {
  assert(!opts || (typeof opts === 'object'), 'pex-gl: createGL requires opts argument to be null or an object')
  if (!opts) opts = {}

  let canvas = opts.canvas

  if (!canvas) {
    canvas = document.createElement('canvas')
    canvas.width = opts.width || window.innerWidth
    canvas.height = opts.height || window.innerHeight
    if (!opts.width && !opts.height) {
      // fullscreen
      document.body.style.margin = '0px'
    }
    if (document.body) {
      document.body.appendChild(canvas)
    } else {
      // just in case our script is included above <body>
      document.addEventListener('DOMContentLoaded', () => {
        document.body.appendChild(canvas)
      })
    }
  }
  const gl = canvas.getContext('webgl', opts)
  return gl
}

module.exports = createGL

const assert = require('assert')

function createGL (opts) {
  assert(!opts || (typeof opts === 'object'), 'pex-gl: createGL requires opts argument to be null or an object')
  if (!opts) opts = {}

  let canvas = opts.canvas

  if (!canvas) {
    canvas = document.createElement('canvas')
    canvas.width = opts.width || window.innerWidth
    canvas.height = opts.height || window.innerHeight

    const appendCanvas = () => {
      if (!opts.width && !opts.height) {
        // fullscreen
        document.body.style.margin = '0px'
      }
      document.body.appendChild(canvas)
    }

    if (document.body) {
      appendCanvas()
    } else {
      // just in case our script is included above <body>
      document.addEventListener('DOMContentLoaded', appendCanvas)
    }
  }
  const gl = canvas.getContext('webgl', opts)
  return gl
}

module.exports = createGL

Change the way properties on document.body are set while loading canvas.
Change the way properties on document.body are set while loading canvas.

In the default setup, when no width and height options are passed and
`createGL` is called on page load, it throws an error if the script is
included before the body element, since `document.body.style` is null.
The function already accounts for this fact while appending the canvas
to the page, but not while setting `style.margin = '0px'`. This PR
changes that.
