Extract DAG.js

Extracts DAG.js into a standalone lib.