Files
Tom Moor e14dfcfcb4 perf: Stop restyling the document on every frame of the sidebar animation (#14132)
The document container and editor exposed their measured widths as inherited
CSS variables, so each frame of a width animation restyled every element in
the document. Full width blocks now use a container unit, and media resizing
measures the editor content width when it is needed.
2026-10-18 17:52:20 -04:00

21 lines
613 B
TypeScript

/**
* Returns the width that blocks can fill in the editor that contains the
* element, which is the editor's width without its own padding.
*
* @param element an element in the editor, or the editor element itself.
* @returns the width in pixels, or Infinity when the element is not in an editor.
*/
export function contentWidth(element: Element): number {
const editor = element.closest(".ProseMirror");
if (!editor) {
return Infinity;
}
const style = getComputedStyle(editor);
return (
editor.clientWidth -
parseFloat(style.paddingLeft) -
parseFloat(style.paddingRight)
);
}