Since, I couldn't find any proper text clipping function for the typst documents on the internet, i've decided to make it myself. This function utilizes binary search to find the most optimal clipped text length, according to its rendered counterpart.
By default clipped text content is being suffixed by ...
marker which you can change by setting marker
function argument to anything else:
#let clip(text, content, length, marker: "...") = {
context {
let element = content(text)
if (measure(element).width <= length) {
return element