Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

adaptable-text

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adaptable-text

Adapt font size to a specified width using either binary search or linear steps.

  • 3.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

adaptable-text

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Adapt font size to a specified width using either binary search or linear steps.

Linear steps works best for small adjustments (eg. on resize) while binary search is most efficient when the expected font-size change is big.

paypal coinbase twitter

Installation

npm install adaptable-text

Usage

import AdaptableText from "adaptable-text";

const textToAdapt = new AdaptableText(document.querySelector(".TextToAdapt"), {
  step: 0.1,
  minFontSize: 10,
  width: null,
});
textToAdapt.init();

// Adapt
const adapt = () => {
  textToAdapt.setWidth();
  textToAdapt.adapt();
};

// Listen for a resize event
window.addEventListener("resize", adapt);

// Kick off
adapt(true);

API

Classes

AdaptableText

Typedefs

Options : object

AdaptableText

Kind: global class

new AdaptableText(element, [options])

Creates an instance of AdaptableText.

ParamType
elementHTMLElement
[options]Options

adaptableText.init()

Initialise the adaptor.

Kind: instance method of AdaptableText

adaptableText.setWidth()

Set the desired width for adaptation from options.width or getBoundingClientRect().width

Kind: instance method of AdaptableText

adaptableText.adapt([useBinarySearch])

Adapt font size to a specified width.

Kind: instance method of AdaptableText

ParamType
[useBinarySearch]boolean

Options : object

Kind: global typedef Properties

NameTypeDefaultDescription
[step]number0.5The step used by the generator to calculate the width of the element.
[minFontSize]number0A minimum font size for the element (max would be the size defined in a stylesheet retrieved by window.getComputedStyle(this.element)).
[width]number"null"A maximum width for the container.

License

MIT. See license file.

Keywords

FAQs

Package last updated on 06 Jul 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc