Refactor to pluggable architecture and build with requirejs

- Update demo and tests to work with new architecture
- Document new public API