Bring shadow dom algorithms up to date

This is a complete update of the distribution, composition and event
path algorithms from the spec draft.

Fixes #420