How can I fix the size of a TextBox and dynamically decrease the fontSize if the text gets to large for the TextBox? Yes a similar question exists here but it only works for one line of text.
I want to achieve exactly that: (example from the imgflip meme editor)

I have tried following approach:
let text = new fabric.Textbox(box.text, {
top: box.top,
left: box.left,
width: box.width,
});
if (text.width > box.width) {
text.fontSize *= box.width / (text.width + 1);
text.width = box.width;
}
if (text.height > box.height) {
text.fontSize *= box.height / (text.height + 1);
text.height = box.height;
}
canvas.add(text);
This way the fontSize decreases by the ratio of which the width or height of the textbox changed. But this causes the text to get extremely small sometimes because the text won't get wrapped as nicely as it could. The fontSize and the wrapping need to find an optimum somehow. Any ideas? Thanks!