
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
A fast, jQuery-free text sizing component that quickly fits single and multi-line text to the width (and optionally height) of its container.
A fast, jQuery-free text sizing component that quickly fits single and multi-line text to the width (and optionally height) of its container.
textFit
supports IE9+, Firefox, Chrome, Opera, and most mobile browsers. If you find an incompatibility,
please file an issue.
If you require IE <= 8 support, please use the jQuery version. Functionality is identical between v1.0 and v2.0, the only change was the removal of the jQuery dependency.
options.suppressErrors
. Wrap in try/catch
instead if you really need this.alignVert
when reprocessing.reProcess
is now true
by default. Set to false
if you want to fire-and-forget on potentially
processed nodes. This was originally false by default because it was being used in an infinite scrolling list.<div class="box" style="width:300px;height:300px">
Fit me, I am some text
</div>
// textFit accepts arrays
textFit(document.getElementsByClassName('box'));
// or single DOM elements
textFit(document.getElementsByClassName('box')[0]);
// Use jQuery selectors if you like.
textFit($('#box')[0])
The text will scale until it reaches the horizontal or vertical bounds of the box. Explicit width and height styles are required in order to fit the text.
If your text has multiple lines, textFit() will automatically detect that and disable white-space: no-wrap! No changes are necessary.
<div class="box" style="width:300px;height:300px">
This text <br>
Has multiple lines <br>
Fit me!
</div>
textFit(document.getElementsByClassName('box'))
If, for some reason, the automatic detection is not working out for you, use the following to explicitly turn on multiLine fitting:
textFit(document.getElementsByClassName('box'), {multiLine: true})
<div class="box" style="width:300px;height:300px">
This text <br>
Has multiple lines <br>
And wants to be centered horizontally and vertically<br>
Fit me!
</div>
textFit(document.getElementsByClassName('box'), {alignHoriz: true, alignVert: true})
Sometimes you want to make sure that your text remains sanely sizes if it is very short or very long. textFit has you covered:
<div class="box" style="width:300px;height:300px">
Short Text
</div>
textFit(document.getElementsByClassName('box'), {minFontSize:10, maxFontSize: 50})
textFit determines reasonable minimum and maximum bounds for your text. The defaults are listed below.
To ensure accurate results with various font-faces, line-heights, and letter-spacings, textFit resizes the text until it fits the box as accurately as possible. Unlike many similar plugins, textFit uses binary search to find the correct fit, which speeds the process significantly. textFit is fast enough to use in production websites.
textFit()
is a synchronous function. Because of this, resizes should be invisible as the render thread does not
have a chance to do a layout until completion. Normal processing times should be < 1ms and should not significantly
block renders.
From the source, for reference:
settings = {
alignVert: false, // if true, textFit will align vertically using css tables
alignHoriz: false, // if true, textFit will set text-align: center
multiLine: false, // if true, textFit will not set white-space: no-wrap
detectMultiLine: true, // disable to turn off automatic multi-line sensing
minFontSize: 6,
maxFontSize: 80,
reProcess: true, // if true, textFit will re-process already-fit nodes. Set to 'false' for better performance
widthOnly: false // if true, textFit will fit text to element width, regardless of text height
};
MIT
FAQs
A fast, jQuery-free text sizing component that quickly fits single and multi-line text to the width (and optionally height) of its container.
The npm package textfit receives a total of 6,507 weekly downloads. As such, textfit popularity was classified as popular.
We found that textfit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.