I want to create a simple demo of moving an eye (black circle) inside a bigger circle with a black stroke when moving a mouse. I have cursor positions mouseX and mouseY on a canvas and I need to map the value of mouse position into a circle so the eye is moving inside the circle.
This should be trivial but I have no idea how to solve this problem.
This is a coding problem but I think that I will get the best results from this Q&A. If not I will ask on stack overflow.
This is the code that shows the problem.
https://editor.p5js.org/jcubic/sketches/E2hVGceN9
If you use map function in P5JS library (that is linear map from one range to a different range) I get the black circle to move in a square with a side equal to the diameter of the circle. So the black circle is outside.
I'm not sure what should I use to calculate the position of the black circle so it's always inside the bigger circle.

I think, from my understanding of your question, that you are trying to clip coordinates in the plane, to be inside or on the boundary of the big circle.
For that, suppose the given mouse position is $x_1 = mouseX , y_1 = mouseY $ and the equation of the circle in the plane is given by
$ (x - h)^2 + (y - k)^2 = R^2 $
Then what you want to check first is whether the point $(x_1, y_1)$ is inside this circle by checking if
$ (x_1 - h)^2 + (y_1 - k)^2 \le R^2 $
If it is, then leave the coordiantes $(x_1, y_1)$ as they are.
If not, then calculate the vector from the center to the point $(x_1, y_1)$ and scale it such that it lies on the boundary, this is achieved explicitly as follows
Let $v = \dfrac{( x_1 - h , y_1 - k )}{\sqrt{ (x_1 - h)^2 + (y_1 - k)^2 } } $
Then the new coordinates are
$ (x_2, y_2) = (h, k) + R v $
This new point is the point where you want to place your black dot, and it will be on the boundary of the big circle.
So you have effectively clipped all positions in the plane to be inside the circle or on its perimeter.