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

postcss-spritus

v1.3.0

Published

Find the sprites and then creates, saves and compresses

Downloads

6

Readme

postcss-spritus

Find the sprites and then creates, saves and compresses

Easy to use with your CSS

The sprite is stored only those images that you use

For vanilla CSS or SCSS use gulp-css-spritus

Install

npm install postcss-spritus --save

Example

postcss([
    require('postcss-spritus')()
])

Input example

.icon {
    background-image: spritus-url("assets/images/icons/*.png");
    background-size: spritus-size("assets/images/icons/*.png");
}

.icon-google {
    background-position: spritus-position("assets/images/icons/*.png", "google.png");
    height: spritus-height("assets/images/icons/*.png", "google.png");
    width: spritus-width("assets/images/icons/*.png", "google.png");
}
/* .icon-... */

Output example

.icon {
    background-image: url("../images/icons.png");
    background-size: 26px 130px;
}

.icon-google {
    background-position: 0 26px;
    height: 26px;
    width: 26px;
}
/* .icon-... */

Methods and options

The path relative to the root of the script

$sprite: "assets/images/icons/*.png";

Methods

Method | Description ------ | ----------- spritus-url($sprite); | is replaced by a relative link to the sprite url("../images/icons.png") spritus-size($sprite); | is replaced with the size of the sprite spritus-position($sprite, "%file_name%"); | is replaced by the position of the image in the sprite spritus-height($sprite, "%file_name%"); | is replaced by height in pixels spritus-width($sprite, "%file_name%"); | is replaced by width in pixels spritus:phw($sprite, "%file_name%"); | is replaced by the position, height and width of the image in sprite background-position: 0px 60px;height:30px;width:30px; spritus:each($sprite); | is replaced by all sprite image. See example below


%file_name% — may be full filename.png or only basename filename without extension


How does spritus:each($sprite);

In
/** example 1 **/
.myprefix {
    spritus:each("assets/images/icons/*.png")
}

/** example 2 **/
i.prefix {
    display:none;
    spritus:each("assets/images/icons/*.png")
}
Out
/** example 1 **/
.myprefix-google {
    background-position: 0px 26px;height: 26px;width: 26px;
}
.myprefix-twitter {
    background-position: 0px 42px;height: 26px;width: 26px;
}
...

/**  example 2 **/
i.prefix-google {
    display:none;
    background-position: 0px 26px;height: 26px;width: 26px;
}
i.prefix-twitter {
    display:none;
    background-position: 0px 42px;height: 26px;width: 26px;
}
...

Inline options

$sprite: "assets/images/icons/*.png?padding=30&algorithm=diagonal&name=newicons";
  • padding — see description in Plugin options
  • algorithm — see description in Plugin options
  • name — another name of the sprite to save

Plugin options

// ...
postcss([
  spritus({
    padding: 2,
    searchPrefix: "spritus",
    algorithm: "top-down",
    withImagemin: true,
    withImageminPlugins: [
      imageminPngquant({
        quality: "60-70",
        speed: 1
      })
    ],
    imageDirCSS: "../images/",
    imageDirSave: "public/images/"
  })
])
// ...

padding

The amount of transparent space, in pixels, around each sprite. Defaults to 2


withImagemin

Compression of the sprite using imagemin. Defaults to true


withImageminPlugins

Specify what to use plugins for. Defaults to [require('imagemin-pngquant')({quality: "60-70",speed: 1})]


imageDirCSS

Relative URL (background-image) which is replaced in position in your CSS. Defaults to ../images/


imageDirSave

The path where to save the sprites relative to the root of the script. Defaults to public/images/


searchPrefix

If you want to use a different prefix, then this option is for you. Defaults to spritus

gulpfile.js

// ...
postcss([
  spritus({
    searchPrefix: "myprefix"
  })
])
// ...

Now you can now use

.icon {
    background-image: myprefix-url(...);
    background-size: myprefix-size(...);
    myprefix:phw(...);
}

algorithm

Images can be laid out in different fashions depending on the algorithm. We use layout to provide you as many options as possible. . Defaults to top-down.At the time of writing, here are your options for algorithm:

| top-down | left-right | diagonal | alt-diagonal | binary-tree | |---------------------------|-------------------------------|---------------------------|-----------------------------------|---------------------------------| | top-down | left-right | diagonal | alt-diagonal | binary-tree |

More information can be found in the layout documentation: