File size: 738 Bytes
c392a82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
() => {
  const host = document.getElementById("script-input");
  const field = host?.querySelector("textarea");
  if (!field) return;
  // Gradio measures text before the final responsive width can settle.
  // Ask the native input handler to measure again when that width changes.
  let width = 0;
  const observer = new ResizeObserver(entries => {
    const next = entries[0].contentRect.width;
    if (Math.abs(next - width) < .5) return;
    width = next;
    requestAnimationFrame(() => {
      if (field.isConnected) field.dispatchEvent(new Event("input", {bubbles:true}));
      else observer.disconnect();
    });
  });
  observer.observe(host);
  window.addEventListener("pagehide", () => observer.disconnect(), {once:true});
}