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

@unvt/sprite-one

v0.1.1

Published

Generate sprite images and json without mapnik

Downloads

219

Readme

Generate sprite image and json without Mapnik

  • SVG and PNG icon inputs
  • Multiple pixel ratio support
  • Uses sharp for rendering (compatibility with newer Node.js versions and architectures)
  • Supports SDF icons

Install

npm install @unvt/sprite-one

Usage

  • CLI
$ sprite-one -h
Usage: sprite-one [options] <sprite_filename>

generate sprite from icons

Options:
  -v, --version            output the version number
  -i, --icon <icons...>    A folder path which stores SVG icons. Multiple folders can be set.
  -r, --ratio <ratios...>  pixel ratio to generate sprite. default is 1.
  --sdf                    generate sprite with SDF (Signed Distance Field). (default: false)
  -h, --help               display help for command
  • npm
import { generateSprite } from '@unvt/sprite-one'

generateSprite('../out', '../input', [2]).then(() => {})

If multiple ratios are specified in either CLI or Node.js, the default file names when the ratio is more than one will be changed to the standard file name used by Mapbox and MapLibre (e.g., sprite.json for 1 ratio, [email protected] for 2 ratio...).

Multiple pixel ratio support

You can supply mulitple pixel ratio versions of the same icon in the directory by using the following naming convention:

  • [name].png or [name].svg -- the default icon
  • [name]@2x.png or [name]@2x.svg -- the icon to use in the 2x spritesheet

If the @2x version doesn't exist, the default icon will be used and scaled up appropriately. If you are using PNG icons, it is strongly recommended that you prepare alternate versions for each pixel ratio you require.

Note that while this feature is supported for SVG icons, this is usually unneccesary because SVG, as a vector format, can be scaled without problems.

SDF icons support

SDF icons can be generated by using the --sdf option. This allows users to apply icon-color and icon-halo-color properties in Maplibre style to able to change the colour dynamically.

import { generateSprite } from '@unvt/sprite-one'

generateSprite('../out', '../input', [1], true).then(() => {})

Develop

via bin/index.ts

git clone https://github.com/unvt/sprite-one.git
cd sprite-one
npm install
npx ts-node src/bin/index.ts ../../tmp/out --icon ../../tmp/maki/icons
npx ts-node src/bin/index.ts ../../tmp/out --icon ../../tmp/maki/icons --ratio=2
npx ts-node src/bin/index.ts ../../tmp/out --icon ../../tmp/maki/icons --icon ../../tmp/maki/icons2 --ratio=1 --ratio=2