fitHeightJs constant

String const fitHeightJs

JavaScript code to determine the tightest possible height that encompass all rendered HTML elements. This computes the maximum bottom coordinates from the getBoundingClientRect() of all elements.

Returns a JavaScript array: [width, height]

Implementation

static const fitHeightJs = """
(function() {
 let maxBottom = 0;

  document.body.querySelectorAll('*').forEach(el => {
  const rect = el.getBoundingClientRect();
  maxBottom = Math.max(maxBottom, rect.bottom);
  });

  return [0, maxBottom];
  })();
""";