a bunch of refactoring

refactoring of mug and element code to be dryer and more extensible and partial extraction of itext code into a new plugin system

note that changes to model.js aren't shown because there were too many.