I ignore whether you can access that information using built-in tools, so here is a possible answer that centres on the maths of the problem.
What you're doing is basically an affine transformation, specifically the composition of a translation and a rotation:

Where the rotation matrix is:

; and the translation vector is:

So, in fine, the coordinates in the new system should be:
let x2 = x1*Math.cos(a) + Math.sin(a) * (-y1 + w2*Math.sin(a));
let y2 = y1*Math.cos(a) + Math.sin(a) * (+x1 - w2*Math.cos(a));
EDIT - The previous solution deals with the original posted problem; to tackle the "new" modified version - as described by the OP in the comments -, there are two possibilities:
- either to simply apply to the above result the transformation
(x, y) --> (x, h2-y) (this is the easy way);
- or to re-formalise the problem from scratch. We'll now do this for didactic reasons.
In this second scenario, apart from the aforementioned rotation and translation, the affine transformation includes a reflection about the x axis, and an additional translation:

; where the rotation matrix is still:

; the reflection can be written:

; the first translation, as before, is:

; and, finally, the second translation vector:

Inverting the system, the final result is:
let x2 = +x1*Math.cos(a) + Math.sin(a) * (-y1 + w2*Math.sin(a));
let y2 = -y1*Math.cos(a) + Math.sin(a) * (-x1 + w2*Math.cos(a)) + h2;