UNPKG

svelte-textfit

Version:

Svelte action to fit headlines and paragraphs into any element. Ported from react-textfit

29 lines (28 loc) 979 B
/** * Ported from react-textfit@1.1.1 * The MIT License (MIT) * * Copyright (c) 2015 react-textfit * */ // Calculate height without padding. export function innerHeight(el) { const style = window.getComputedStyle(el, null); // Hidden iframe in Firefox returns null, https://github.com/malte-wessel/react-textfit/pull/34 if (!style) return el.clientHeight; return ( el.clientHeight - parseInt(style.getPropertyValue("padding-top"), 10) - parseInt(style.getPropertyValue("padding-bottom"), 10) ); } // Calculate width without padding. export function innerWidth(el) { const style = window.getComputedStyle(el, null); // Hidden iframe in Firefox returns null, https://github.com/malte-wessel/react-textfit/pull/34 if (!style) return el.clientWidth; return ( el.clientWidth - parseInt(style.getPropertyValue("padding-left"), 10) - parseInt(style.getPropertyValue("padding-right"), 10) ); }