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

tailwind-basekick

v0.2.0

Published

TailwindCSS plugin for aligning text to its baseline

Downloads

5

Readme

Tailwind Baseline

NPM version

This package provides a Tailwind CSS plugin that allows you to align text to its baseline.

Installation

npm install tailwind-basekick

Configuration

This plugin uses the basekick key in your Tailwind config’s theme object to generate aspect basekick utilities. Here is an example:

// tailwind.config.js
const defaultTheme = require("tailwindcss/defaultTheme");

module.exports = {
  theme: {
    extend: {
      fontFamily: {
        sans: ["Inter var", ...defaultTheme.fontFamily.sans],
        serif: ["Merriweather", ...defaultTheme.fontFamily.serif],
        mono: ["Roboto Mono", ...defaultTheme.fontFamily.mono],
      },
      baseline: {
        sans: {
          descenderHeightScale: 0.136,
          capHeight: 0.723,
        },
        serif: {
          descenderHeightScale: 0.144,
          capHeight: 0.7462,
        },
        mono: {
          descenderHeightScale: 0.111,
          capHeight: 0.7077,
        },
      },
    },
  },
  variants: {},
  plugins: [require("tailwind-basekick")],
};

The fonts theme object is a dictionary where the key is the fontFamily, and the value is a dictionary. The value dictionary has two keys, descenderHeightScale and capHeight, that take decimal numbers as values.

Defining descenderHeightScale

Descender height is the space between the baseline of your font and the bounding box when the line height is 1. You can measure descenderHeightScale by setting line-height to 1 and measuring how much space there is between the bottom of the letter "x" and the bottom of the bounding box.

For example, the descenderHeightScale for the Inter font is 0.136, which means that when font-size is 1000px and line-height is 1 there is 136px between the bottom of the letter x and the bounding box.

Defining capHeight

Cap height is the height of capital letters in comparison to the bounding box when the line-height is 1. The easiest way to measure a cap height of a Google Font is by using this Codepen.

For example, the capHeight for the Inter font is 0.723, which means that when font-size is 1000px and line-height is 1 the height of the letter "H" is 723px.

Usage

You can align the text of an element to baseline by adding the class baseline to the same element, where you define the line-height (e.g. leading-2). You can define the font-family (e.g. font-sans) and font-size (e.g. text-sm) anywhere.

 <div class="font-sans text-sm">
    <p class="leading-2 baseline">
      Hello! This text is aligned on the baseline.
    </p>
</div>

License

MIT © Lachlan Teale