OrbitControls constrain panning responsive

Hi, I have a scene that I want the user to be able only to pan up the limits of the scene (top, bottom left , right)

I made it b blocking the rotation and the zoom orbit controls
and I contained the movement in the x and the y axis by reading the position of the camera and with an if statement when the cam reaches the end (try end error values) it stops.

my problem is that this is not responsive so in other resolutions the boundaries have different values

any idea on hot o make it responsive ?

thank you

You can use a raycaster from the controls target to the camera position
Example : https://sbcode.net/threejs/raycaster2/
and limit camera position accordingly or within another arbitrary tolerance.