MAGICNUMBER - is just an approximator
FITTEXT - is just an approximator, and requires additional software called jquery to work
TEXTFIT - is just an approximator
FITTY - might work, can't be sure, no video demos to see, I may need to download it
TEXTFILL - might work, can't be sure, no video demos to see, but requires additional software
FLOWTYPE - does not scale the text to fit the box, it just scales the text as a function of box size
SVG - no URL was provided, so I can't tell how it works, but it claims to require magic numbers
There must be a system API that they use to obtain the width of the outputted text. How else could they possibly work if not through an API? Hopefully they aren't reading the pixels directly off the screen to see how the text was written. Do you know which API they would use or what the name of the API routine is?
There's no point in showing you my cheating code because it's not what I want anyway. I want something that isn't an approximator.
If Keynote can do it, it's doable. And I'm fairly sure it's done with the assistance of a macOS API. All I need to do is find out what that API is and then use a language that can access that API.