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

p45

v1.1.0

Published

Svelte library for programmatically crafting grid based SVGs.

Downloads

33

Readme

Made to be Plundered Latest version Release date

P45

Svelte library for programmatically crafting grid based SVG icons.

Requires Svelte version 4.

Made to be Plundered

Fork, pillage, and plunder! Do whatever as long as you adhere to the project's permissive MIT license.

Classes

P45

The core class supplied to P45 components. It provides the context for P45 components such as grid size and certain named nodes.

It also provides functions for parsing command and transformation lists used by components such as <Shape> and <Transform>.

class P45 {
  // Accepts size of the grid used as the unscaled width and height in pixels.
  // Size must be between 8 and 64.
  // Size must be divisible by 2.
  constructor(size=24) {
    this.size = size
    this.center // '12' for default size
    this.centerNode // 'M12' for default size
    this.topLeftNode
    this.topCenterNode
    this.topRightNode
    this.centerLeftNode
    this.centerCenterNode
    this.centerRightNode
    this.bottomLeftNode
    this.bottomCenterNode
    this.bottomRightNode
  }

  // Parses nodes such as `M12` into coordinates such as `{ x: 12, y: 12 }`.
  parseNode(node);

  // Converts coordinates such as `x=12` and `y=12` into nodes such as `M12`.
  nodeOf(x, y);

  // Converts the number `n` into it's base 26 alphabetic representation.
  numberToAlpha(n);

  // Parses a string or array of strings representing
  // draw commands for a single shape and returns a
  // string used in SVG paths like this `<path d={result} />`.
  parseDrawCommands(commands);

  // Parses a string or array of strings representing
  // transform commands for a single element and returns a
  // string used for the SVG transform attribute like this
  // `<path transform={result} />` or `<g transform={result} />`.
  parseTransformCommands(commands);
}
<script>
	import { P45, Icon, Shape } from 'p45'

	const p45 = new P45()
</script>

<Icon {p45} width="300" height="300">
	<!-- Simple triangle -->
	<Shape
		draw="
      move to E20
      line to U20
      line to M4
      close
  " />
</Icon>

Illustration of the above drawing but with some minor modifications so it's visible on GitHub and other platforms.

Approximate illustration of the last code snippet

Draw Commands

move to <node>

  • move to D3 => M 3 3
  • move to M8 => M 12 8

line to <node>

  • line to D3 => L 3 3
  • line to M8 => L 12 8

[cubic] curve to <node> control with <node> [and <node>]

  • curve to M8 control with D3 => S 3 3 12 8
  • curve to M8 control with D3 and F6 => C 3 3 6 6 12 8

(quad|quadratic) curve to <node> [control with <node>]

  • (quad | quadratic) curve to M8 => T 12 8
  • (quad | quadratic) curve to M8 control with D3 => Q 3 3 12 8

arc to <node> with radius <number> and <number> [and rotation <number>] [and is large] [and is sweeping]

  • arc to M8 with radius 6 and 10 => A 6 10 0 0 0 12 8
  • arc to M8 with radius 6 and 10 and rotation 45 => A 6 10 45 0 0 12 8
  • arc to M8 with radius 6 and 10 and is large => A 6 10 0 1 0 12 8
  • arc to M8 with radius 6 and 10 and is sweeping => A 6 10 0 0 1 12 8
  • arc to M8 with radius 6 and 10 and rotation 45 and is large and is sweeping => A 6 10 45 1 1 12 8

close (connects the ends of the shape together)

  • close => z

Transform Commands

move by <number>

  • move by D3 => translate(3 3)
  • move by M8 => translate(12 8)

move <direction> by <number>

  • move up by 3 => translate(0 -3)
  • move down by 3 => translate(0 3)
  • move left by 3 => translate(-3 0)
  • move right by 3 => translate(3 0)

rotate by <number> [around <node>]

  • rotate by 45_ => rotate(45)
  • rotate by 45 around M8_ => rotate(45, 12, 8)

scale [x|y] by <number>

  • scale by 2 => scale(2 2)
  • scale x by 2 => scale(2 0)
  • scale y by 2 => scale(0 2)

scale [x|y|width|height|horizontally|vertically] by <number>

  • scale by 2 => scale(2 2)
  • scale x by 2 => scale(2 1)
  • scale y by 2 => scale(1 2)

flip [x|y|width|height|horizontally|vertically]

  • flip => scale(-1 -1)
  • flip x => scale(-1 1)
  • flip y => scale(1 -1)

skew [x|y|width|height|horizontally|vertically] by <number>

  • skew by 20 => skewX(20) skewY(20)
  • skew x by 20 => skewX(20)
  • skew y by 20 => skewY(20)

Components

{{PLACEHOLDER}}