
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Automatically fit text into its container, preventing overflow and underflow.
The algorithm uses computed width and height and therefore works for all font types and variations. It adjusts the font size of a given element so that it precisely fills its container. Not only text, it works for any elements with dimensions defined relative to font size (eg. width: 1em
).
AutoFit
The AutoFit
component automatically re-runs when children
changes and when the viewport resizes.
import { AutoFit } from 'auto-fit'
export const Title = ({ text }) => {
return (
<div style={{ maxWidth: '60%', margin: '0 auto' }}>
<AutoFit>{text}</AutoFit>
</div>
)
}
AutoFit
PropsName | Type | Default | Description |
---|---|---|---|
children | ReactNode | The content to be auto fitted. | |
multiline | boolean | false | Allow text to wrap and fit into both container width and height. |
minFontSizePx | number | 8 | The smallest font size the algorithm will use. |
maxFontSizePx | number | 160 | The largest font size the algorithm will use. |
as | string | ReactComponent | 'div' | The underlying component that AutoFit will use. |
autoFit
functionFor advanced use cases, the autoFit
function may be useful. It is used by the AutoFit
component and has no dependencies.
import { autoFit } from 'auto-fit'
autoFit(options)
If you have many elements or re-run autoFit
frequently, throttle is good for performance:
import { autoFit, throttleAnimationFrame } from 'auto-fit'
const throttledAutoFit = throttleAnimationFrame(() => autoFit(options))
throttledAutoFit() // Subsequent calls are reasonably throttled
autoFit
optionsName | Type | Default | Description |
---|---|---|---|
innerEl | HTMLElement | The inner element to be auto fitted. | |
containerEl | HTMLElement | The container element is used as bounding box for the inner element. | |
minFontSizePx | number | 8 | The smallest font size the algorithm will use. |
maxFontSizePx | number | 160 | The largest font size the algorithm will use. |
AutoFit
uses requestAnimationFrame
to throttle repeated calls, ensuring that we render as often as possible without excessively blocking the UI.When developing one typically wants to see the output in the example application without having to publish and install. We achieve this by linking the local package into the example app.
Because of issues with yarn link
, we use Yalc. A linking approach is preferred over yarn workspaces since we want to run the package as it would appear in the real world.
npm i yalc -g
yarn
yarn watch
# Other terminal
cd example
yarn
yalc add --link auto-fit
yarn dev
Using --link
makes it so that Next.js can HMR the updates instantly. It creates a link:
rather than a file:
dependency.
# Bump version number
yarn clean && yarn build
npm publish
FAQs
Automatically fit text into its container, preventing overflow and underflow.
We found that auto-fit 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.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.