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
}
let low = 0
let high = text.len()
let clipped = ""
while low <= high {
let middle = low + calc.floor((high - low) / 2)
let candidate = content(text.slice(0, middle) + marker)
let candidate_width = measure(candidate).width
if candidate_width == length {
return candidate
}
if candidate_width > length {
high = middle - 1
} else {
low = middle + 1
clipped = candidate
}
}
clipped
}
}

#par(
clip(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit",
content => text(upper(content), size: 14pt),
10cm
),
leading: 1.166em,
spacing: 1.166em
)