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 🙏

© 2026 – Pkg Stats / Ryan Hefner

foster-ts-shapes

v0.1.0

Published

Deterministic SVG shape generation library

Readme

foster-ts-shapes

Deterministic SVG shape generation — zero dependencies, fully typed, endlessly composable.

Drop in a seed and a shape list, get back a pixel-perfect SVG every time. No canvas, no DOM, no runtime deps — just TypeScript and math.


Install

npm install foster-ts-shapes

Quick Start

import { generate } from "foster-ts-shapes";

const result = generate({
  seed: 42,
  canvas: { width: 400, height: 400 },
  shapes: [{ type: "circle", x: 200, y: 200, size: 100, fill: "steelblue" }],
});

console.log(result.svg); // <svg ...>...</svg>

Same seed → same SVG. Every time. On any machine.


Examples

AnimatedShapes AnimatedShapes2

Note: These animations are external visualizations created to showcase the PRNG-driven variation system — cycling through different seeds to demonstrate deterministic shape generation. foster-ts-shapes outputs static SVG strings only. It does not animate shapes or produce GIFs.


Shapes

Nine primitives, all sharing a common base interface:

| Type | Required fields | | ----------- | ------------------------------------- | | square | x, y, size | | rectangle | x, y, width, height | | circle | x, y, size | | triangle | x, y, size | | trapezoid | x, y, topWidth, bottomWidth, height | | octagon | x, y, size | | polygon | x, y, sides, size | | oval | x, y, width, height | | blob | x, y, size, points? |

Every shape also accepts rotation? (degrees).


Features

Styling

Every shape accepts fill, stroke, and opacity fields:

{
  type: "square",
  x: 100, y: 100, size: 80,
  fill: "tomato",
  stroke: "darkred",
  strokeWidth: 3,
  opacity: 0.85,
}

Gradients

Linear and radial gradients on fill and/or stroke:

{
  type: "circle",
  x: 150, y: 150, size: 100,
  fillGradient: {
    type: "linear",
    x1: 0, y1: 0, x2: 1, y2: 1,
    stops: [
      { offset: 0, color: "royalblue" },
      { offset: 1, color: "mediumpurple" },
    ],
  },
}

Bezier Rounding

Smooth out any shape's corners with a single field:

{
  type: "polygon",
  x: 200, y: 200, sides: 6, size: 100,
  bezier: 0.4,             // 0–1: rounding amount
  bezierDirection: "in",   // "out" (convex, default) | "in" (concave)
}

Variation / Distortion

Seeded randomness that distorts vertices — great for organic, hand-drawn aesthetics:

{
  type: "blob",
  x: 150, y: 150, size: 100, points: 8,
  fill: "goldenrod",
  distort: 0.3,          // 0–1: per-vertex displacement
  sizeVariance: 0.2,     // 0–1: overall scale jitter
  clamp: { width: 200, height: 200 }, // keep shape within bounds
}

Layers

Control z-order with layer — lower values render behind higher ones:

shapes: [
  {
    type: "circle",
    x: 200,
    y: 200,
    size: 150,
    fill: "cornflowerblue",
    layer: 0,
  },
  {
    type: "oval",
    x: 200,
    y: 200,
    width: 80,
    height: 40,
    fill: "white",
    layer: 1,
  },
];

Masks

Clip any shape using one or more mask shapes. Masks accept the full variation and bezier API:

// Circle clipped to a triangle window
{
  type: "circle",
  x: 150, y: 150, size: 100,
  fill: "steelblue",
  mask: { type: "triangle", x: 150, y: 150, size: 90 },
}

// Polygon revealed through two circular windows
{
  type: "polygon",
  x: 200, y: 150, sides: 8, size: 130,
  fill: "mediumseagreen",
  mask: [
    { type: "circle", x: 140, y: 130, size: 60 },
    { type: "circle", x: 260, y: 170, size: 60 },
  ],
}

// Donut: punch a hole in a shape by compositing black into the mask
{
  type: "square",
  x: 150, y: 150, size: 160,
  fill: "steelblue",
  mask: [
    { type: "square", x: 150, y: 150, size: 160, fill: "white" }, // reveal
    { type: "square", x: 150, y: 150, size: 80,  fill: "black" }, // punch hole
  ],
}

API

generate(input: GeneratorInput): GeneratorOutput

interface GeneratorInput {
  seed: number; // any integer — determines all randomness
  canvas: { width: number; height: number };
  shapes: Shape[];
  outputMode?: "semantic" | "path"; // default: "semantic"
}

interface GeneratorOutput {
  svg: string;
  metadata: { shapeCount: number };
}

outputMode: "semantic" emits native SVG primitives (<rect>, <circle>, etc.) where possible. outputMode: "path" forces all shapes to <path> elements — useful when distortion or masking is applied.


Determinism

The seed drives a mulberry32 PRNG. Given the same seed and input, generate() returns byte-for-byte identical SVG output across environments and versions. This makes the library suitable as a stable foundation for generative art pipelines, procedural asset systems, or any context where reproducibility matters.


TypeScript

Full strict-mode types are included. No @types/ package needed.

import type { GeneratorInput, Shape, GeneratorOutput } from "foster-ts-shapes";

███████╗ ██████╗ ███████╗████████╗███████╗██████╗
██╔════╝██╔═══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗
█████╗  ██║   ██║███████╗   ██║   █████╗  ██████╔╝
██╔══╝  ██║   ██║╚════██║   ██║   ██╔══╝  ██╔══██╗
██║     ╚██████╔╝███████║   ██║   ███████╗██║  ██║
╚═╝      ╚═════╝ ╚══════╝   ╚═╝   ╚══════╝╚═╝  ╚═╝

License

MIT © 2026 VisualFinesse