On the layout side rather than the "what spaces are available" side, I really recommend https://gwern.net/doc/design/typography/tex/1981-knuth.pdf , the paper in which the Knuth-Plass algorithm for paragraph layout is defined. (The Knuth-Plass algorithm decides how wide spaces should be on each line and which choices of hyphenation out of some predefined set should be used to lay out a paragraph.) It's super readable and generally quite joyful. Knuth describes TeX as a "labor of love", and it shines through that paper.
For those interested in typst, Laurenz wrote[0] about the differences between the typst and TeX layout algorithms a while ago. The paragraph layout algorithm is the same but the way it interacts with page placement is quite different.
[0]: https://laurmaedje.github.io/posts/layout-models/