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

sass-unit-graph

v2.0.0

Published

Responsive CSS unit without the use of media queries.

Downloads

3

Readme

Sass Unit Graph

Responsive CSS unit without the use of media queries.

:warning: Usage of Dart Sass is mandatory.

@use "sass-unit-graph" as *;

:root {
  --font-size-base: #{unit-graph(
    (320px,16px), 
    (1920px,24px)
  )};
}

body {
  // font size of 16px at viewport width of 320px
  // font size of 18.24px at viewport width of 768px
  // font size of 24px at viewport width of 1920px
  font-size: var(--font-size-base);
}

Examples

Examples available on the GitHub Page.

Quick install

NPM

npm i -D sass sass-unit-graph

Using within Sass

@use "sass-unit-graph" as *;

Browser support

All browsers with support for CSS calc(), min(), max() and vw are supported, which includes:

  • Edge (79+)
  • Chrome (79+)
  • Firefox (75+)
  • Safari (11.1+)
  • Android Browser (92+)

Usage

The unit-graph() Sass function returns an expression based on at least two points.

It is possible to use any CSS calc operations.

@use "sass-unit-graph/unit" as unit;

:root {
  --custom-prop: #{unit-graph(
    (320px,16px), 
    (1920px,24px)
  )};
}

// Multiplication
font-size: calc(var(--custom-prop) * 2);
// Division
font-size: calc(var(--custom-prop) / 2);
// Addition
font-size: calc(var(--custom-prop) + 10%);
// Subtraction
font-size: calc(var(--custom-prop) - 10%);

It is also possible to add or subtract multiple graph expressions:

@use "sass-unit-graph/unit" as unit;

:root {
  --custom-prop-1: #{unit-graph(
    (320px,16px),
    (1920px,24px)
  )};

  --custom-prop-2: #{unit-graph(
    (320px,8px),
    (1920px,12px)
  )};
}

body {
  font-size: calc(var(--custom-prop-1) + var(--custom-prop-2));
}

Extrapolation

Extrapolation will appen below the first points X value, and above the last point X value.

unit-graph(
  // Extrapolation
  (320px,16px), 
  // Value is linear between two points
  (1920px,24px)
  // Extrapolation
)

It is possible to draw an horizontal line to get a constant Y value.

unit-graph(
  // Extrapolation
  (0px,    16px),
  // Fixed value of 16px until 320px
  (320px,  16px), 
  // Value is linear between two points
  (1920px, 24px), 
  // Fixed value of 24px above 1920px
  (2000px, 24px)
  // Extrapolation
)

Steps

Creation of steps is possible by creating sharp line.

unit-graph(
  // Extrapolation
  (0px,      16px),
  // Fixed value of 16px until ~768px
  (767.99px, 16px), 
  // Very sharp ascending line, user won't notice
  (768px,    24px), 
  // Fixed value of 24px above 768px
  (1920px,   24px)
  // Extrapolation
)

Optimisation

In case of repeatition, usage of CSS custom properties is strongly
encouraged since complexe expressions might be quite long.

Known issues and limitations

Precision

Although very good, the precision of float numbers will be limited by Dart Sass compiler, which affects the precision of the generated expressions.

Units

unit-graph() accepts all absolute CSS units (cm, mm, in, px, pt, pc), although the output will always be in pixels.

This is made possible by Sass's support of real-world unit calculations, as detailed in the Sass documentation of numeric units.

@use "sass-unit-graph" can't find the file

Configure Dart Sass includePaths option to resolve to your node_modules folder.

Credit

Based on my previous work sass-linear-expression, which is own by Sigmund.

Special thanks to my front-end collegues who inspired me to create better tooling.