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

svg-typewriter

v2.0.0

Published

SVG Text Measurement Line Wrapper

Downloads

394

Readme

SVG Typewriter

Circle CI

Sauce Test Status

Overview

SVG Typewriter is a library for measuring, manipulating, and writing text on SVG. The svg text spec indicates that "SVG performs no automatic line breaking or word wrapping", meaning that developers normally need to write their own code to accomplish this; SVG Typewriter aims to make this entire process easier.

SVG Typewriter is based on D3.js.

Features

  • Measurers efficiently measure the size of a piece of text when written to a particular SVG element, taking into account the CSS styles affecting that text.
  • Wrappers calculate how best to fit text into a given space, based on results from the Measurer.
  • Writers write text to a given SVG element based on specified options such as alignment, rotation, and animation.

In general, users will primarily interact with Writers, although they will need to instantiate Measurers based on specific SVG elements so that the library can perform accurate measurement and wrapping. Users can set options on Wrappers to control the wrapping behavior.

Installation

npm install --save svg-typewriter

Example Usage

import { Measurer, Wrapper, Writer } from "svg-typewriter";

// Create a Measurer based on the element we want to write into.
// Passing in the intended element allows accurate measurement based on the CSS
// styles that will actually be applied to that element.
const measurer = new Measurer(svg);

// Create a Wrapper with default options.
// A wrapper calculates how to break text to fit in a given space and returns
// the wrapped text as strings. Wrappers do not directly write the wrapped text.
const wrapper = new Wrapper();

// Create a Writer.
// A Writer uses the supplied Measurer and Wrapper to best decide how to fit
// text in a given space, then writes the wrapped text to a given element.
const writer = new Writer(measurer, wrapper);

// Set write options.
const writeOptions = {
  selection: svg,
  xAlign: "left",
  yAlign: "top",
  textRotation: 0
};

// write the text to the element.
writer.write("Hello World!", width, height, writeOptions);

See the docs for more detailed examples.