After this code, tangentSpaceX,Y,Z should contain a matrix of “negative” tangentspace. Anyways, I tried it and it works, however I dont understand the following line:

tangentSpaceY.set( Vector1 - Vector2 )

how does that generate the tangent space vector for Y(or V)

I would say this generates a unit vector from the endpoint of the unit vector along edge v2v3 to the endpoint of unit vector from v2v1.
That means e.g. for a counterclockwise triangle looking from vertex2 into the triangle this is a unit vector to the left.
Cross of that with the normal gives a vector in between the two edge vectors, and crossing those two gives a vector in normal direction.
(The last cross looks like nonsense, take the normal directly instead.)

You want to involve u and v rate of growth as well; otherwise your tangent space will twist and wind over the surface and you’ll get weird normal map interactions, unless your mesh is entirely regularly mapped.