Implement :nth-*() and :*-of-type level 3 pseudo-classes

Re-submitting #1318