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

shalam

v1.0.8

Published

A tool for friendly CSS spriting

Downloads

12

Readme

Shalam

Project Status

A friendly tool for CSS spriting. Shalam allows you to add Retina-friendly, high-quality image sprites to your website without modifying any markup.

Installation

Mac OS X

First, you'll need to make sure that your system is ready. If you're running OS X, you'll need Cairo installed. Cairo depends on XQuartz. You'll want to download and install XQuartz from here:

https://xquartz.macosforge.org/landing/

Then install Cairo and pkgconfig with Homebrew:

brew install cairo pkgconfig
npm install -g shalam

If you get an error about xcb-shm, try running the following before running npm install:

export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig

Linux

If you'd like to use Shalam on Linux, you can run a similar set of commands:

yum install cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel giflib-devel

npm install -g shalam

Windows

Windows support is currently not available. You may find success, however, after installing node-canvas manually. Patches to add or improve Windows support are welcome.

Adding Sprites

Simply use the -shalam-sprite declaration in your CSS files:

.my-great-class {
    font-size: 1.5em;
    font-weight: bold;

    -shalam-sprite: "files-page/chevron.png" dest-size(32px 32px);
}

The syntax for -shalam-sprite is simple: a string containing a path to an image asset (discussed below) is required. Following the string is an optional dest-size() modifier. dest-size() allows you to specify the height and width of the image as you would like it to appear on the page. This is usually the width and height of the element you are applying -shalam-sprite to. Only two positive non-zero numbers that use px as the unit are accepted.

When shalam is run, you'll get this code:

.my-great-class {
    font-size: 1.5em;
    font-weight: bold;

    -shalam-sprite: "files-page/chevron.png" dest-size(32px 32px);
    /* shalam! */;
    background: url(../img/sprites/files-page.png) -20px -74px;
    background: url(../img/sprites/files-page.compat.png) -50px -24px/125px 32px;
    /* end shalam */
}

The background declarations with all the fixins are generated for you! This means that generating sprites with retina assets (even if your assets are not all retina) is a breeze.

Running

shalam /path/to/source/css /path/to/source/images /path/to/final/output/image
  • The first argument is the path to a directory containing the CSS files to process.
  • The second argument is the path to a directory containing the source images that will be used in the sprited image. This doesn't need to be a part of your application's main repository (since the source images will not be included in your assets). For example, you might keep your source images in /Users/matt/projects/site-assets/.
  • The third argument is the path to the location you expect the final sprited image to go. That is, if you expect to create static/img/sprite.png, you will specify static/img/sprite. The file extension is omitted intentionally to support a compatibility sprite (static/img/sprite.compat.png, for IE8 support).

For example, you might run:

shalam static/css static/img static/img/sprite

The URL paths to the sprited images that will be inserted into the CSS will be relative to their paths on the disk. In the above example, the following code:

/* ~/myapp/static/css/main.css */
.foo {
    -shalam-sprite: "image.png";
}

run with the following command:

shalam static/css static/img static/img/sprite

will yield

/* ~/myapp/static/css/main.css */
.foo {
    -shalam-sprite: "image.png";
    /* shalam! */;
    background: url(../img/sprite.png) 0 0;
    background: url(../img/sprite.compat.png) 0 0/40px 40px;
    /* end shalam */
}

Notice that the URLs used in the template are relative from the final path of the sprited image to the location of the CSS file. In static/css/main.css, ../img/sprite.png would yield static/img/sprite.png, which is what we passed for the third argument.

Advanced Features

More advanced features are documented on the wiki:

Support

Need to contact us directly? Email [email protected] and be sure to include the name of this project in the subject.

Hacking on Shalam

If you're interested in contributing, please read our wiki page about hacking on Shalam to get started.

Copyright and License

Copyright 2015 Box, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.