Simple text balancing utility. It's a wrapper around the text-wrap: balance CSS property.
If the browser supports the text-wrap: balance property, and the element has the text-wrap: balance property set, it will not be balanced.
npm install @activetheory/balance-textimport balanceText from '@activetheory/balance-text';
const el = document.querySelector('.el');
const result = balanceText({
el,
ratio: 1,
useParent: true,
debug: true,
});el: The element to balance.ratio: The ratio of the width of the element to the width of the parent.useParent: Whether to use the parent element as reference to balance the text.debug: Whether to log debug information.
See the demo folder for examples.
To run the demo, run npm run dev.