This is the code for the fleeing button page at https://ivasilev.net/playground/fleeing-button.
The README in the root directory contains references to important bits of documentation that may aid in understanding the code.
I believe that there is nothing subtle in this code bundle.
The fleeing algorithm itself is explained and justified on the web page.
The entry point is ./index.ts and the logic is concentrated in the fleeingButtonStage component (the component system is explained in the README file in ../../common/rendering).
The current stat is stored in a StateStore instance, the working of which is explained here.