[selectors] Add API hooks for matching selectors against trees and elements, and dedup some IDs.