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

@carloitaben/tailwindcss-scale

v0.0.1

Published

I should explain what this does

Downloads

1

Readme

tailwindcss-scale

I should explain what this does

Installation

npm i @carloitaben/tailwindcss-scale

Requirements

  • tailwindcss >= 3.3
  • ESM Tailwind config

Usage

The minimum configuration for this plugin is the following:

import type { Config } from "tailwindcss"
import { scalePlugin } from "@carloitaben/tailwindcss-scale"

export default {
  // ...
  plugins: [
    // ...
    scalePlugin({
      unit: "vw",
      // Scale with viewport width
      values: [16, 360],
      // The root font size is 16px at 360vw
    }),
  ],
} satisfies Config

By default, the plugin generates an scale variant that proportionally resizes any spacing class:

<div className="w-12">When my root font size is 16px, my width is 48px.</div>

<div className="scale:w-12">
  When my root font size is 16px, my width is 48px on a screen 360px wide. I'll proportionally scale up on wider
  screens, and down on narrow ones.
</div>

With the previous configuration, the scaled element measures:

| Screen width | Element width | | ------------ | ------------- | | 120px | 16px | | 240px | 32px | | 360px (base) | 48px (base) | | 480px | 64px | | 720px | 96px |

Configuration

prefix

The generated variant name. Defaults to "scale".

type Config = {
  prefix?: string
}
scalePlugin({
  prefix: "fluid",
  // ...
})
<div className="fluid:w-12"></div>

unit

A viewport unit to use in calculations.

type Config = {
  unit: "vw" | "vh" | "vmin" | "vmax"
}
scalePlugin({
  unit: "vmax",
  // ...
})

values

The magic numbers for scaling.

/**
 * A valid screen from your Tailwind configuration.
 */
type Screen: string

type Value = [
  rootFontSize: number,
  viewportSize: number
]

type Config = {
  values: Value | { [K: Screen]: Value }
}

The simplest values definition is a tuple:

scalePlugin({
  values: [16, 360], // 16px @ 360vw
  // ...
})

You can also map scaling factors to your Tailwind screens using an object:

scalePlugin({
  // ...
  screens: {
    sm: "640px",
    // @media (min-width: 640px) { ... }
    xl: "1280px",
    // @media (min-width: 1280px) { ... }
  },
  // ...
  values: {
    DEFAULT: [16, 360],
    // 16px @ 360 units
    sm: [16, 1920],
    // @media (min-width: 640px): 16px @ 1920 units
    xl: [32, 2560],
    // @media (min-width: 1280px): 32px @ 2560 units
  },
})

So this element

<div className="scale:w-12"></div>

will have the following measurements:

| Screen width | Element width | | ------------ | ------------- | | 120px (base) | 16px (base) | | 240px (base) | 32px (base) | | 360px (base) | 48px (base) | | 480px (sm) | 64px (sm) | | 720px (sm) | 18px (sm) | | 1920px (xl) | 72px (xl) | | 2240px (xl) | 84px (xl) | | 2560px (xl) | 96px (xl) |

You can use Tailwind screen variants to opt-out of scaling on specific breakpoints or modify the property size:

<div className="w-12 sm:scale:w-12 lg:w-24 xl:scale-w-24"></div>

Caveats

  • Currently breaks when the document root font size is changed (i.e. with zoom)
  • There's probably a better way of doing this
  • Not tested

License

MIT