If it's after they're elected then it'll run down the line of succession: VP, Speaker of the House, president pro tempore of the Senate, then the cabinet.
If it's before they're elected, I'm no expert but I believe the Democratic and Republican parties are private organizations that can do whatever the fuck they want, even fail to abide by the results of their own primaries.
I've got a project coming hopefully this fall. You probably just saved me hours next summer.