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

@curiousmedia/breakpoint

v2.1.0

Published

CSS and Javascript media query management tool

Downloads

14

Readme

Breakpoint

Unified Javascript and SCSS breakpoint manager.

Installation

npm install @curiousmedia/breakpoint

Dart Sass

The Dart Sass implementation is highly recommend and used for all examples unless specified otherwise.

@use '@curiousmedia/breakpoint/src/breakpoint' with (
  $breakpoints: (
    md: "@media (hover: hover)"
  )
);

@include breakpoint.any('md') {
  .button {
    &:hover {
      color: red;
    }
  }
}

LibSass & Ruby Sass

@import '@curiousmedia/breakpoint/src/breakpoint';

$breakpoints: (
  md: "@media (hover: hover)"
);

@include breakpointAny('md') {
  .button {
    &:hover {
      color: red;
    }
  }
}

Usage

CSS

Breakpoint presets need to be configured by setting the "breakpoints" SCSS variable.

$breakpoints: (
    landscape: "@media (orientation: landscape)",
    touch: "@media screen and (pointer: coarse)",
    cursor: "@media screen and (pointer: fine)",
    hover: "@media screen and (hover: hover)",
    still: "@media screen and (prefers-reduced-motion)",
    sm: "@media (max-width: 640px)",
    md: "@media (min-width: 641px) and (max-width: 1024px)",
    lg: "@media (min-width: 1025px)",
    grid: "@supports (display: grid)",
    page: "@page"
);

Presents can be referenced for quick, unified breakpoints across an entire project. Unfortunately, CSS and Javascript breakpoints must be defined separately.

Single breakpoint

Create "md" breakpoint.

@include breakpoint.any(md) {
    div {
        font-size: 2em;
    }
}

Multiple breakpoints using any

Create breakpoint where sm or lg conditions are met.

@include breakpoint.any(sm, lg) {
    div {
        font-size: 2em;
    }
}

Multiple breakpoints using all

Create breakpoint where landscape and sm conditions are met. If all queries use the same rule (e.g. @media), then they will be merged into a single breakpoint. However, if multiple queries do not use the same rule, they will be nested.

@include breakpoint.all(landscape, sm) {
    div {
        font-size: 2em;
    }
}

Custom Breakpoints

Custom breakpoints can be used along side presets.

@include breakpoint.all(sm, '@media (min-width: 400px)') {
    div {
        font-size: 2em;
    }
}

Nested

Create nested breakpoints.

div {
  @include breakpoint.any(hover) {
    @include breakpoint.any(landscape, sm) {
      font-size: 2em;
    }
  
    @include breakpoint.all(md, grid) {
      font-size: 3em;
    }
  }
}

Short hand

Create single-property breakpoint.

div {
  @include breakpoint.prop('font-size', (lg: 1em, md: 2em));
}

Javascript

Breakpoint presets are configured when class is instantiated.

Configuration

let bp = new Breakpoint({
    'landscape': '@media (orientation: landscape)',
    'touch': '@media screen and (pointer: coarse)',
    'cursor': '@media screen and (pointer: fine)',
    'hover': '@media screen and (hover: hover)',
    'still': '@media screen and (prefers-reduced-motion)',
    'sm': '@media (max-width: 640px)',
    'md': '@media (min-width: 641px) and (max-width: 1024px)',
    'lg': '@media (min-width: 1025px)',
    'grid': '@supports (display: grid)',
    'page': "@page"
});

Single breakpoint

Query "md" breakpoint.

bp.any('md'); //returns true or false

Multiple breakpoints using any

Query to evaluate if "sm" or "lg" conditions are met.

bp.any('sm', 'lg'); //returns true or false

Multiple breakpoints using all

Query to evaluate if "landscape" and "sm" conditions are met.

bp.all('landscape', 'md'); //returns true or false

Custom Breakpoints

Custom breakpoints can be used along side presets.

bp.all('sm', '@media (min-width: 400px)'); //returns true or false

Notes

Complex queries

This library is designed to handle common media queries. Complex queries with many conditions and not operators have not been tested.

Supported rules

The @page, @media, and @supports rules are supported. Due to the nature of SCSS syntax, additional rules will have to be manually added.

@page

The @page rule will always return true in the Javascript implementation; Javascript isn't computed on printed pages.