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

utopia-core-scss

v1.0.1

Published

Utopia.fyi fluid calculations in SCSS

Downloads

711

Readme

Utopia Core SCSS

The calculations behind Utopia.fyi. Written in SCSS. Also available in JS/TS here.

Installation

npm install utopia-core-scss
@use 'node_modules/utopia-core-scss/src/utopia' as utopia;

Documentation

Utopia Core SCSS outputs in two formats: mixins & functions. Mixins generate actual (slightly) opinionated CSS custom properties. Functions sit beneath mixins doing the real work, returning calculated values for you to write your own custom CSS. The both use identical APIs and only differ by name (generateX for mixins, calculateX for functions).

All mixins/functions default relativeTo to viewport (vi), but can be overriden to container (cqi), or viewport-width (vw).

Mixins

generateTypeScale()

Generate a fluid type scale between two widths, sizes and scales. Set the number of positive and negative steps. Custom property prefix can be overriden from step-.

Example

:root {
  // Calling this:
  @include utopia.generateTypeScale((
    "minWidth": 320,
    "maxWidth": 1240,
    "minFontSize": 18,
    "maxFontSize": 20,
    "minTypeScale": 1.2,
    "maxTypeScale": 1.25,
    "positiveSteps": 2,
    "negativeSteps": 2,
    /* Optional params */
    "relativeTo": "viewport",
    "prefix": "step-",
  ));

  // Generates this:
  --step--2: clamp(...);
  --step--1: clamp(...);
  --step-0: clamp(...);
  --step-1: clamp(...);
  --step-2: clamp(...);
}

generateSpaceScale()

Generate a set of fluid spaces from min/max width/base sizes, and a number of positive/negative multipliers. Fluid spaces & one-up pairs are automatically created, and custom pairs can be created by supplying the keys you wish to interpolate between. Pass usePx: true to separate space from browser text zoom preferences. Custom property prefix can be overriden from space-.

Example

:root {
  // Calling this:
  @include utopia.generateSpaceScale((
    "minWidth": 320,
    "maxWidth": 1240,
    "minSize": 18,
    "maxSize": 20,
    "positiveSteps": (1.5, 2),
    "negativeSteps": (0.75),
    /* Optional params */
    "customSizes": ("s-l",),
    "usePx": true,
    "relativeTo": "container",
    "prefix": "space-",
  ));

  // Generates this:
  --space-xs: clamp(...);
  --space-s: clamp(...);
  --space-m: clamp(...);
  --space-l: clamp(...);
  // One-up pairs
  --space-xs-s: clamp(...);
  --space-s-m: clamp(...);
  --space-m-l: clamp(...);
  // Custom pairs
  --space-s-l: clamp(...);
}

generateClamps()

Generate multiple clamps from a single set of min/max widths. Supply an array of number pairs to interpolate between. Pass usePx: true to separate space from browser text zoom preferences. Custom property prefix can be overriden from space-.

Example

:root {
  // Calling this:
  @include utopia.generateClamps((
    "minWidth": 320,
    "maxWidth": 1240,
    "pairs": (
      (16, 48),
      (40, 18)
    ),
    /* Optional params */
    "usePx": true,
    "relativeTo": "container",
    "prefix": "space-",
  ))

  // Generates this:
  --space-16-48: clamp(...);
  --space-40-18: clamp(...);
}

generateClamp()

Generate a single clamp custom property from a min/max width & size. Default to using rem and vi but this can be overriden to use px and cqi. Pass usePx: true to separate space from browser text zoom preferences. Custom property prefix can be overriden from space-.

Example

:root {
  // Calling this:
  @include utopia.generateClamp((
    "minWidth": 320,
    "maxWidth": 1240,
    "minSize": 16,
    "maxSize": 20,
    /* Optional params */
    "usePx": true,
    "relativeTo": "container",
    "prefix": "space-",
  ))

  // Generates this:
  --space-16-20: clamp(...);
}

Functions

calculateTypeScale()

Calculate a fluid type scale between two widths, sizes and scales. Set the number of positive and negative steps, and whether you want the scale to be relative to the viewport or the container.

Example

$typeScale: utopia.generateTypeScale((
  "minWidth": 320,
  "maxWidth": 1240,
  "minFontSize": 18,
  "maxFontSize": 20,
  "minTypeScale": 1.2,
  "maxTypeScale": 1.25,
  "positiveSteps": 5,
  "negativeSteps": 2,
  /* Optional params */
  "relativeTo": "container",
))

// $typeScale == (
//    (
//      "step": 0,
//      "minFontSize": 18,
//      "maxFontSize": 20,
//      "clamp": clamp(...),
//    )
//  )

calculateSpaceScale()

Calculate a set of fluid spaces from min/max width/base sizes, and a number of positive/negative multipliers. Fluid spaces & one-up pairs are automatically created, and custom pairs can be created by supplying the keys you wish to interpolate between. Clamp provided in rem and px.

Example

$spaceScales: utopia.calculateSpaceScale((
  "minWidth": 320,
  "maxWidth": 1240,
  "minSize": 18,
  "maxSize": 20,
  "positiveSteps": (1.5, 2, 3, 4, 6),
  "negativeSteps": (0.75, 0.5, 0.25),
  "customSizes": ("s-l", "l-s",),
  /* Optional params */
  "relativeTo": "container",
))

// $spaceScales == (
//  "sizes": (
//    (
//      "label": "s",
//      "minSize": 18,
//      "maxSize": 20,
//      "clamp": clamp(),
//      "clampPx": clamp(),
//    ),
//  ),
//  "oneUpPairs": (),
//  "customPairs": (),
// )

calculateClamps()

Calculate multiple clamps from a single set of min/max widths. Supply an array of number pairs to interpolate between.

Example

$clamps: utopia.calculateClamps((
  "minWidth": 320,
  "maxWidth": 1240,
  "pairs": (
    (16, 48),
    (40, 18)
  ),
  /* Optional params */
  "usePx": true,
  "relativeTo": "container"
))

// $clamps == (
//    (
//      "label": "16-48",
//      "clamp": clamp(...),
//    ),
//    (
//      "label": "40-16",
//      "clamp": clamp(...),
//    )
//  )

calculateClamp()

Calculate a single clamp calculation from a min/max width & size. Default to using rem and vi but this can be overriden to use px and cqi.

Example

$clamp: utopia.calculateClamp({
  "minWidth": 320,
  "maxWidth": 1240,
  "minSize": 16,
  "maxSize": 48,
  /* Optional params */
  "usePx": true,
  "relativeTo": "container"
})

// clamp(1rem, 0.3043rem + 3.4783vi, 3rem);