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

gulp-svg-symbol-view

v1.0.3

Published

Generate sprites symbols from svgs by cleaning them up with svgo and concatenating them.

Downloads

7

Readme

gulp-svg-symbol-view npm version

Generate sprites symbols from svgs by cleaning them up with svgo and concatenating them. Outputs svg and JSON (for react inlines).

This piece was inspired by a rather old article by David Bushels. There he describes one cool way to use a symbol sprite to set backgrounds in css. The point is that it is impossible to link from css to symbol groups inside a sprite without additional constructions.

I took as a basis the Stefan Müller sprite generator gulp-svg-symbol-sprite and added logic to it using the "use" tag to create areas corresponding to the images contained in the symbol groups, which can then be referenced using the "view" tags using the postfix "- view "after the source file name. Well, okay, I myself would not understand such an explanation :) Just look inside the created sprite, having previously formatted it in the editor, and everything will become clear to you.

The process of creating view areas has two modes. The first is just a link to the original image, no changes. The second is when colors are removed from the original images and the generated view areas are styled using the colors passed to the parameters.

Usage:

gulpfile.js (simple):

var svgSprite = require('gulp-svg-symbol-view');

function sprite() {
	return gulp.src('./src/images/**/*.svg')
	.pipe(svgSprite('spritename'))
	.pipe(gulp.dest('./public'));
};

exports.sprite = sprite;

gulpfile.js (with json create):

function sprite() {
	return gulp.src('./src/images/**/*.svg')
	.pipe(svgSprite({
		name: 'spritename',
		json: true,
		svgo: { plugins: [ // you can control svgo if you want
			{ removeRasterImages: true },
			{ removeStyleElement: true }
		]}
	}))
	.pipe(gulp.dest('./public'));
};

gulpfile.js (use monochromatic mode):

function sprite() {
	return gulp.src('./src/images/**/*.svg')
	.pipe(svgSprite({
		name: 'spritename',
		monochrome: {
			darkcyan: '#008b8b',
			white: '#ffffff'
		}
	}))
	.pipe(gulp.dest('./public'));
};

html:

<svg class="icon">
	<use xlink:href="images/sprite.svg#iconname"></use>
</svg>

css:

.icon {
	background: url('images/sprite.svg#iconname-view') center / 30px 30px no-repeat transparent;
}

css (monochrome mode):

.icon {
	background: url('images/sprite.svg#iconname-view-darkcyan') center / 30px 30px no-repeat transparent;
}

.icon:hover {
	background-image: url('images/sprite.svg#iconname-view-white');
}