Skip to content

Releases: tvanc/lineclamp

v0.2.0

20 Feb 20:34
Compare
Choose a tag to compare

.softClamp() will now find the largest possible font size within one hundredth of a pixel (0.01px).

Side note: 🎉 First minor release!

Start with max; fix infinite loop

22 Aug 02:46
Compare
Choose a tag to compare

Fix a bug that could cause findBoundary(), a hidden utility function for finding the largest workable font size, to spiral deeper ever deeper into the space between two whole numbers.

Fix another bug that caused .softClamp() to always reduce font size by one px from the starting font size.

v0.1.22

20 Dec 01:00
Compare
Choose a tag to compare

Improves performance by changing hardClamp() to use a binary-search approach.

The previous method tested one word, then two words, then three words, etc, until finally the text was too long.

Given an element with 40 words, the new method tests first with 20 words. Then if not too long, 30 words. If too long, 25.
In other words, the possibilities are halved until the ideal number is found.

hardClamp() (which trims text until it fits) and softClamp() (which reduces font size until the text fits) now use the same underlying algorithm.

Performance comparisons on CodePen

Thanks again @MartinMalinda for the idea

v0.1.21

03 Nov 02:21
Compare
Choose a tag to compare
  • Removed a debugging console.log() call.
  • Fixed bug where lineclamp.softclamp, lineclamp.hardclamp, and lineclamp.clamp events fired even when no clamping occurred.

☝️ Thanks @MartinMalinda for the bug reports!

  • Fixed bugs causing first or last words to disappear.
  • Updated dev dependencies

v0.1.15

09 Mar 20:04
Compare
Choose a tag to compare
  • Add hardClampAsFallback option for controlling whether softClamp() will resort to calling hardClamp() if the minimum font size is reached and text still doesn't fit.
  • Add /test/ to .npmignore 🤦‍♂
  • Start with the maximum font size in softClamp(). Previously we started with the element's current font size and only clamped if necessary.
  • maxHeight and maxLines can be used together. Previously if both were defined, maxHeight took precedence.

v0.1.10

30 Nov 23:47
Compare
Choose a tag to compare

Changes

  • Performance: 98% faster.
  • Compatibility: Available in ES, UMD, and CommonJS formats
  • hardClamp() preserves original whitespace characters

Performance

When soft clamping (see LineClamp.prototype.softClamp()), instead of trying every font size between min and max until the text fits, LineClamp now narrows in on the proper font size by oscillating between an ever-decreasing range of possibilities.

For example, given a maxFontSize of 100 and minFontSize of 1, previous versions of LineClamp would have tried every font size between 100 and 1 until the text fit. Now, LineClamp tries 50. If that doesn't fit, it tries 25. If that fits, it tries 37 (halfway between 25 and 50). The process repeats until only the lower bound fits.

calculateTextMetrics() has also been refactored to use textContent and appendChild() instead of the slower innerHTML property.

v0.1.0

19 Nov 05:32
Compare
Choose a tag to compare

Refactored to be much more robust and focused. Now works in many more situations because the module no longer relies on getting the computed line height. LineClamp also now works with block and inline elements - regardless of padding, border widths, min/max heights or CSS line-height rules.

Initial commit

19 Oct 23:31
Compare
Choose a tag to compare
Initial commit Pre-release
Pre-release
Fixed a bug caused by attempting to use window.getComputedStyle() on an

`undefined` property.

Worked around min-height ruining my groove.