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

bowlcut

v0.2.2

Published

A library for hairy SVG text manipulation

Downloads

1

Readme

Alt

A library for hairy SVG text manipulation

| 1st screenshot | 2nd screenshot | 3rd screenshot | | --- | --- | --- |

Bowlcut is a library designed to stretch vector text between sets of paths. Specifically, Bowlcut uses TTF fonts to produce styled SVG paths. Bowlcut wordmarks can have multiple region that text flows between, as many fonts as you would like, and a set of colors for various fills and strokes. Bowlcut was originally built for procedurally generating sports team logos, but it has many other applications as well in graphic design and inventive text layouts.

Bowlcut is designed to be used in a browser context, because some of its dependencies rely on using the DOM for measuring the size of paths. The built file provided for use is an ES6 module, but it is provided as a bundle because its dependencies are commonjs modules that have to be included with it. You can edit the Rollup config file and run your own builds for additional contexts.

Installation

	npm i bowlcut

Bowlcut is an ES6 module, so you will need to import it into your code:

	import {Bowlcut} from 'node_modules/bowlcut/dist/bundle.js';

Use

A Bowlcut object is a renderable collection of styled text grouped into regions. These regions reference properties on the Bowlcut object for their styling, and have some properties of their own. Here's an example of how to set up a Bowlcut object.

	var wordmark = new Bowlcut({
		text: ['example', 'wordmark'],
		colors: ['#ff0000', '#00ccff']
	});

	/* other properties:
		precision (decimal places, defaults to 3)
		debug (true / false). Shows paths defining the regions
		uniqueId (hex string set up by the constructor)
	*/

	//now load the fonts (returns a promise):
	wordmark.loadFonts([
		['Modak-Regular', 'fonts/Modak-Regular.ttf'],
		['PassionOne-Bold', 'fonts/PassionOne-Bold.ttf']
	]);

Region objects define the position, styling, and bounding paths of text in the Bowlcut object. First properties are passed to the constructor, then the bounding paths are set.

	//some example region data
	var dataA = {
		bounds: {
			x: 128,
			y: 128,
			width: 256,
			height: 64
		},
		font: 1, // use the index of the font in the Bowlcut object
		fill: 0,
		stroke: 1,
		slice: {
			0: []	// key is the index of the string
					// value is an array of arguments for String.slice()
		},
		topPath: null,	// you can pass path elements here if you like
						// there are convenience methods detailed below for common shapes
		bottomPath: null,
		stretchToWidth: false, //default is false. Set to true to fill bounds when text width < bounds width
							  // otherwise text will be centered in the bounds
		advanceWidthScale: 1.0 // default is 1. this adjusts letter spacing before scaling and stretching is applied.
	};

	var dataB = {
		bounds: {
			x: 128,
			y: 224,
			width: 256,
			height: 64
		},
		font: 0,
		fill: 1,
		stroke: null,
		slice: {
			1: [4] // will return 'mark'
		},
		topPath: null,
		bottomPath: null
	};

	var regionA = wordmark.addRegion(dataA);
	var regionB = wordmark.addRegion(dataB);

Here's what setting up the bounding paths looks like.

	regionA.makeRadialArch(0.5); //value of 0-1

	regionB.makeArch(0, 0.3);	// creates a bridge arch, with a flat top and a curved-up bottom
								// these values are on a scale of 0-1 with respect to the bounds height

	//also available: region.makeStraightPaths() for unwarped regions

Finally, to render:

	someSvg.appendChild(wordmark.render());

	//the render() function returns an SVG group of paths representing the regions.

And the final output:

Alt

This example is provided as working code under examples/readme.html in the repository.

Samples

Start a local server in the main folder and navigate to examples/methods.html, examples/logo.html, examples/radial-test.html, or examples/readme.html to see Bowlcut in action.

Upcoming features and fixes

  • Further incorporation of Bezier.js LUT functionality and point sampling
  • A set of unit tests for the path parsing functions

License info

Bowlcut.js is distributed under the MIT License.

The example fonts included are from Google Fonts and are distributed under the Open Font License.