Exciton g factors of van der Waals heterostructures from first-principles calculations