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

simple-include-media

v1.1.12

Published

A simple, all-rounded and easy-to-use media queries library for Sass(Scss)

Downloads

46

Readme

Simple Include Media

A simple, all-rounded and easy-to-use media queries library in Sass(Scss).

How to use

.example-class {
	@include media(">=phone & <tablet") {
		// your css
	}
}

will become

@media (min-width: 480px) and (max-width: 767px) {
	.example-class {
		// your css
	}
}

Do not use any space right after the operators ">", "<", ">=", "<=" and "=".

What's new in 1.1.x?

It now supports recursive parsing! You can now use the new function mediaAddExpressions to add expressions like "medium": ">phone & <=tablet" to further manager you media queries. You can find an example under folder "example". ***Please be careful when adding expression to avoid any endless loop. eg. "not": "not all and is not allowed.

Getting Started

Install

NPM

In cmd, run npm i simple-include-media --save-dev and include _simple-include-media.scss inside dist in your build. The default directory should be "node_modules/simple-include-media/dist".

Manual

Download the file dist/_simple-include-media.scss and import it.

Import

Import directly via Scss

Type @import "path/to/simple-include-media"; in you Scss file.

Import via Sass loader of Webpack

In your config file, add includePaths: ["./path/to/simple-include-media/dist"] in option of sass-loader and type @import "simple-include-media"; in you Scss file.

Use

@include media($yourExpression) {...}

Documentation

https://willisshek.github.io/Simple-Include-Media/index.html

How does it work?

Every time you @include media($string), it separates the input string according to space. Than it will parse the separated expressions by the following.

  1. Check whether it exists in $mediaExpressions. If it does, converts it. It can use different key to represent the same value. So you can use both "&" and "&&" to represent "and".npm npm
  2. It will check whether it contains the operators ">", "<", ">=", "<=" or "=". The format should be $dimension>=$value
    • If true, $value will be converted into number. If it can find a key in $mediaBreakpoints, the corresponding value will be used.
    • If $dimension is empty, "width" will be used. If not, it will return the same string. You can use "w" for "width", "h" for "height" and "a" for "aspect-ratio".
    • The prefix "max-" and "min-" are added automatically according to the operator.
    • No space is allow after $dimension and operators.
  3. If it doesn't exist in $mediaExpressions and doesn't have any operators, it will return the same expression.
    • eg. "not" will return "not".
    • So it uses the same logic as css media does.

A more complicated example

.example-class {
	@include media("! <desktop and landscape") {
		// first css
	}
	@include media("h>360px | a>=1") {
		// second css
	}
}

will be compiled into

@media not all and (max-width: 1023px) and (orientation: landscape) {
	.example-class {
		// first css
	}
}
@media (min-height: 361px), (min-aspect-ratio: 1) {
	.example-class {
		// second css
	}
}

Important variables

***No space is allow in the key of variables.

$mediaBreakpoints

  • Control the value when using ">", "<", ">=", "<=" or "=".
  • Do not use ">", "<", ">=", "<=" or "=" as key.

$mediaExpressions

  • Short form used to fast conversion of expressions.
  • It is not recommend but you can still use operators ">", "<", ">=", "<=" or "=" in the key.
  • You can use operators as value.
  • eg. ">=t": ">=tablet". In such case, ">=t" will become ">=tablet" and become "(min-width: 768px)" finally.

$mediaUnitSteps

  • Control the value added/subtracted when using ">" or "<".
  • Change it if you want to be more precise or rough, or use unit other than px, em and rem.

Important functions

mediaAddBreakpoints

  • Add new breakpoint(s) without erasing the old one.
  • eg. $mediaBreakpoints: mediaAddBreakpoints(("retina": 1920px)) // be carefull there are double brackets;
  • Due to the limitation of scss, you must add $mediaBreakpoints: at the beginning;
  • It's the same as $mediaBreakpoints: map-merge($mediaBreakpoints, ("retina": 1920px));, but more convenience.

mediaAddExpressions

  • Add new expression(s) without erasing the old one.
  • eg. $mediaExpressions: mediaAddExpressions(("small": "<=phone")) // be carefull there are double brackets;
  • Due to the limitation of scss, you must add $mediaExpressions: at the beginning;
  • It's the same as $mediaExpressions: map-merge($mediaExpressions, ("small": "<=phone"));, but more convenience.

Remarks

Remember to add ; to the end of every @import to avoid potential error.