when dragging a link over a shape, there is a pink highlight around the shape. Also it is possible to drop the link in the middle of the shape and it will attach automatically.
I cannot figure out which part of the code does that. I was able to reproduce most of it, including the transparent ports, but not the pink highlight.