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

mq-func

v0.1.1

Published

Sass mixin for creating continuous functions from media queries

Downloads

3

Readme

mq-func

mq-func is a sass utility for creating continuous functions from media queries. It was inspired by this blog post.

Usage

Example

The package contains a single mixin mq-func which accepts a map of breakpoints with screen widths as keys and maps describing properties for each breakpoint as values.

@import "node_modules/mq-func/index.scss";

main {
  // The screen widths (map keys) here must be increasing.
  @include mq-func((
    500px: (width: 464px, font-size: 15px),
    600px: (width: 528px, font-size: 16px),
    1000px: (width: 660px, font-size: 20px)
  ), $const-upper: true);
}

The width of the main element will vary as follows:

  • Under 500px, it will be interpolated using the same slope as between 500px and 600px.
  • From 500px to 600px, it will vary linearly from 464px to 528px.
  • From 600px to 1000px, it will vary linearly from 528px to 660px.
  • Above 1000px, it will remain constant at 660px due to the const-upper argument.

The mixin will generate @media (min-width: <...>) queries accordingly:

main {
  width: calc(64vw + 144px);
}

@media (min-width: 600px) {
  main {
    width: calc(33vw + 330px);
  }
}

@media (min-width: 1000px) {
  main {
    width: 660px;
  }
}

Using CSS variables

CSS variables can be used instead of regular properties, for example to do additional computations afterwards.

:root {
  @include mq-func((
    500px: (--half-width: 3em),
    600px: (--half-width: 4em),
    700px: (--half-width: 4em)
  ));
}

main {
  width: calc(var(--half-width) * 2);
}

Using other media queries

Any media query that allows for the min-<value> such as min-width can be specified as a second argument to be used by the mixin instead of the width. Possible values include width (default), height , resolution, aspect-ratio, color-index, etc. Units will automatically be handled by the Sass engine.

@include mq-func((
  72dpi: (font-size: 3rem),
  150dpi: (font-size: 4rem),
  300dpi: (font-size: 5rem)
), $query: "resolution");