Calculate primary/principal axis of selection?

Is there a simple way to calculate the principal axis from a selection, e.g. to use as a custom axis or align another object to?

What I want to do is basically do PCA on the selected geometry and convert that to a custom axis or the 3D cursor.

You can use any selection of vertices, edges or faces as Transform Orientation by hitting the plus sign in the selection in the top middle (usually showing Global)…
IDK if this is what you need…