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

sprite-magic-importer

v1.6.2

Published

Custom node-sass importer for create CSS Sprites like Magic Imports of the Compass.

Downloads

2,243

Readme

sprite-magic-importer

Custom node-sass importer for create CSS Sprites like Magic Imports of the Compass.

Input

@import "icons/*.png";
@include all-icons-sprites(true);

.foo {
    .bar {
        @include icons-sprite(chrome);
    }
}

Output

.icons-sprite, .icons-chrome, .icons-firefox, .icons-ie, .foo .bar {
  background-image: url("/images/icons.png?_=bfa627d");
  background-repeat: no-repeat;
}

.icons-chrome {
  background-position: -32px 0;
  width: 32px;
  height: 32px;
}

...snip...

.foo .bar {
  background-position: -32px 0;
}

.foo .bar:hover, .foo .bar.chrome-hover {
  background-position: 0 0;
}

See: Example

Supported Compass features

Mixins and Functions

  • @mixin all-<map>-sprites()
  • @mixin <map>-sprite()
  • @mixin <map>-sprite-dimensions()
  • @function <map>-sprite-width()
  • @function <map>-sprite-height()

Magic Selectors

Supported are hover, target, active, and focus.

Customization Options

  • $disable-magic-sprite-selectors
    • default: false
  • $sprite-selectors
    • default: hover, target, active, focus
  • $default-sprite-separator
    • default: -
  • $<map>-sprite-base-class
    • default: .<map>-sprite
  • $<map>-sprite-dimensions
    • default: false
  • $<map>-class-separator
    • default: $default-sprite-separator

Usage

Create configure script.

importer.js

var SpriteMagicImporter = require('sprite-magic-importer');

module.exports = SpriteMagicImporter({
    // http://compass-style.org/help/documentation/configuration-reference/
    sass_dir:                   'src/sass',
    images_dir:                 'src/images',
    generated_images_dir:       'dist/images',
    http_stylesheets_path:      '/css',
    http_generated_images_path: '/images',

    // spritesmith options
    spritesmith: {
        algorithm: `diagonal`,
        padding: 2
    },

    // imagemin-pngquant options
    pngquant: {
        quality: 75,
        speed: 10
    }
});

build.js

Plese note: You cannot use sass.renderSync with this importer.

var sass = require('node-sass');
var importer = require('./importer');

sass.render({
    ...
    importer: importer
    ...
});

configure options

  • project_path string - The path to the root of the project.
    • default: process.cwd()
  • http_path string - The path to the project when running within the web server.
    • default: /
  • sass_dir string - The directory where the sass stylesheets are kept. It is relative to the project_path.
    • default: sass
  • css_dir string - The directory where the css stylesheets are kept. It is relative to the project_path.
    • default: stylesheets
  • images_dir string - The directory where the images are kept. It is relative to the project_path.
    • default: images
  • generated_images_dir string - The directory where generated images are kept. It is relative to the project_path.
    • default: images_dir
  • http_generated_images_path string - The full http path to generated images on the web server.
    • default: http_path + / + generated_images_dir
  • http_stylesheets_path string - The full http path to stylesheets on the web server.
    • default: http_path + / + css_dir
  • use_cache boolean - Set this to true to speed up using the cache.
    • default: true
  • cache_dir string - The full path to where cache of temporary stylesheets are kept.
    • default: os.tmpdir() + /sprite-magic-importer
  • retina_mark regexp - Regular expression for detecting high resolution image from file name.
    • default: /@(\d)x$/
  • spritesmith object - This option is passed to the Spritesmith.run().
    • See: https://www.npmjs.com/package/spritesmith#spritesmithrunparams-callback
  • pngquant object - This option is passed to the imagemin-pngquant.
    • See: https://www.npmjs.com/package/imagemin-pngquant#options

CLI

node-sass --importer ./importer.js -o dist/css src/app.scss

Retina support

@import "icons/*.png";              // '*@2x.png' will not be imported
@include all-icons-sprites(true);

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
    @import "icons/*@2x.png";
    @include all-icons-sprites();
}

License

The MIT License (MIT)

Copyright (c) 2016 Takayuki Irokawa