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

svgtracer

v0.1.2

Published

svgtracer is a package to trace SVG paths into a list of points. It is intended to be used with typescript and is compatible with node.js and the browser.

Downloads

4

Readme

Description

svgtracer is a package to trace SVG paths into a list of points. It is intended to be used with typescript and is compatible with node.js and the browser.

Installation

npm install svgtracer

or

yarn add svgtracer

Usage

import traceSVG from 'svgtracer';

const svg = traceSVG('<file content or data uri>');
svg.forEach((path) => {
	path.forEach((point) => {
		console.log(point.position.x, point.position.y);
	});
});

Functions and classes

traceSVG

traceSVG(svg: string, options?: TraceOptions): SVG;

Returns an SVG object containing the traced paths and groups in the original hierarchy. | Parameter | Description | |---------------|---------------------------------------------------| | svg | contents of the svg in text form or data uri form | | options? | options for the svg tracer, see below |

TraceOptions

class TraceOptions {
	resolution: number;
	colors: boolean;
	subpaths: boolean;
	transform: TransformMatrix;
}

| Field | Default value | Description | | ---------- | ----------------- | -------------------------------------------------------------------------------- | | resolution | 1 | resolution of curves, higher is more accurate. | | colors | true | whether to include colors. | | subpaths | true | whether to split paths into subpaths (a new subpath starts with a move command). | | transform | identity | transformation matrix to apply to the svg. |

SVG

class SVG {
	public children: (SVGPath | SVGGroup)[];
	public getAllPaths(): SVGPath[];
}

| Field / Function | Description | | -------------------- | --------------------------------------------------------- | | children | Array containing all direct children of the root element. | | getAllPaths() | Returns an array of all paths in the svg. |

SVGGroup

class SVGGroup {
	public children: (SVGPath | SVGGroup)[];
}

| Field | Description | | --------- | ----------------------------------------------------- | | children | Array containing all direct children of this element. |

SVGPath

class SVGPath {
	public points: Point[];
	public boundingBox?: BoundingBox;
	public style: PathStyle;
	public subpaths: SVGSubpath[];
}

| Field | Description | | ----------- | --------------------------------------------------------------------------- | | points | Array containing all points of the path. Empty, if subpaths are enabled. | | boundingBox | Bounding box of the path. undefined if subpaths are enabled. | | style | Style element of the path. | | subpaths | Array containing all subpaths of the path. Empty, if subpaths are disabled. |

SVGSubpath

class SVGSubpath {
	public points: Point[];
	public boundingBox: BoundingBox;
}

| Field | Description | | ----------- | --------------------------------------- | | points | Array containing all points of the path | | boundingBox | Bounding box of the path. |

Point

class Point {
	public position: Vector2D;
	public normal: Vector2D;
}

| Field | Description | | --------- | --------------------------- | | position | Position of the point. | | normal | Normal vector of the point. |

PathStyle

class PathStyle {
	public fill?: Color;
	public stroke?: Color;
	public strokeWidth?: number;
}

| Field | Description | | ------------ | ---------------------------------------------------------- | | fill? | Fill color of the path. White if the path is not filled. | | stroke? | Stroke color of the path. White if the path is not filled. | | strokeWidth? | Stroke width of the path. Defaults to 1 if not specified. |

Color

class Color {
	public r: number;
	public g: number;
	public b: number;
	public a: number;
}

| Field | Description | | --------- | --------------------- | | r | Red channel (0-255) | | g | Green channel (0-255) | | b | Blue channel (0-255) | | a | Alpha channel (0-255) |