npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flex-text

v1.3.0

Published

Mastering font-size like flexbox!

Downloads

35

Readme

flex-text

Mastering font-size like flexbox for IE 8+:

font-size A:B:C:D = 1:2:1:1

screenshot

Demo

http://idiotwu.github.io/flex-text/

Install

npm install flex-text

Usage

import FlexText from 'flex-text';

const flexText = new FlexText({
    container: document.querySelector('.container'),
    spacing: 0,
    items: [{
        elem: document.querySelector('.first'),
        flex: 1,
    }, {
        elem: document.querySelector('.second'),
        flex: 2,
    }, ...]
});

Important Notes

Unwanted white space:

You may get white spaces around flex items when they are layouted as inline-block, here's a little trick to it:

.container {
    letter-spacing: -0.31em;
}

.item {
    letter-spacing: normal;
}

Canvas vs Legacy Element

This plugin does text measuring with <span> element. As a result, the created <span> element must be inserted into document so that we can measure boundings. Text measuring with canvas is easier and will calculate at a higher performace. However, using legacy elements keeps us away from incompatibility :)

That's also the reason why I wrote it in es5 flavor.

APIs

new FlexText([options: object])

Construct new instance with supported options:

container: element

The element that holds all flex items.

You can set container later by calling instance#attachTo()

spacing: number

White space between each item.

You can also modify spacing by calling instance#setSpacing().

items: array

A list of flex items:

[{
    elem: element,  // the flex item
    flex: number,   // flex factor, like css flex-grow property
}, ...]

You can also add single flex item by calling instance#addItem().

instance#update()

Update DOM layout at next frame.

instance#setSpacing(value: number)

Change white space between items.

instance#attachTo(container: element)

Set the container element.

instance#addItem(elem: element[, flex: number])

Add single flex item, default flex is 1.

instance#removeItem(elem: element)

Remove item from list by giving item.elem.

instance#clear()

Remove all flex items.

instance#alloc()

Measuring font-size and returning the result like:

[{
    elem: DOMElement,
    fontSize: 123,
}, ...]

License

MIT.