fitWidthJs constant
String
const fitWidthJs
JavaScript code to determine the tightest possible width
that encompass all rendered HTML elements. This computes the maximum
right
coordinates from the getBoundingClientRect()
of all elements.
Returns a JavaScript array: [width, height]
Implementation
static const fitWidthJs = """
(function() {
let maxRight = 0;
document.body.querySelectorAll('*').forEach(el => {
const rect = el.getBoundingClientRect();
maxRight = Math.max(maxRight, rect.right);
});
return [maxRight, 0];
})();
""";