HumbleSoftware/js-imagediff — pull request #28 by cburgmer (2014-04-19 16:49:08+00:00)
Title: Support module system for browser environment

Currently a Node.js environment is recognised by checking for `require`-style imports. In that case the `canvas` dependency is required. The module fails if the dependency is not met.

This behaviour does not work when packaged using browserify. In this case the Node.js style `require`-style is present. However, we do not want to depend on there being a `canvas` module.

This commit changes the import handling of the optionally installed dependency by moving the code into the module itself. If a canvas dependency is provided it is used, if not the browser canvas element is. In case the latter is not available an error is thrown.

This change makes sure to provide the user with the possibility to alternatively override the default browser support. I do not know whether that is necessary, just feels like a good option to have for free.