restructure API, exposing publish API and moving most public APIs to Document or Window