From a quick glance, it looks like for getting the text, it listens to all the keyboard events globally. I can imagine many potential problems and shortcomings with this approach, but on the other side, this is probably the most simple and most generic solution, working for almost every application.
For sending the text, it does sth similar, i.e. it just injects global key events. Probably first some key backspace events to delete the old text, and then the keys for the replacement text.
https://github.com/espanso/espanso/blob/dev/espanso-inject/s...
But maybe I understand the code wrong. I did not delve too deep into it.