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

react-canvas-next

v0.1.3

Published

A lightweight React-based Canvas drawing library. This library provides some basic shape components, such as `Path` and `BezierCurve`. And, some components have Svg-like properties. For example, the `d` property of the `Path` component is the same as the

Downloads

11

Readme

react-canvas-next

A lightweight React-based Canvas drawing library. This library provides some basic shape components, such as Path and BezierCurve. And, some components have Svg-like properties. For example, the d property of the Path component is the same as the d property of the Svg path, and the viewBox property of the Canvas component is similar to the viewBox property of Svg.

Basic usage

<Canvas height={400} width={600} >
  <Rect
    fill="red"
    height={80}
    width={120}
    x={20}
    y={20}
  />
  <Rect
    fill="steelblue"
    height={80}
    width={120}
    x={160}
    y={20}
  />
  <Group
    fill="darkgoldenrod"
    lineWidth={4}
    stroke="deeppink"
  >
    <Rect
      height={25}
      width={25}
    />
    <Rect
      height={25}
      width={25}
      x={30}
    />
    <Rect
      fill="yellow"
      height={25}
      width={25}
      x={10}
      y={10}
    />
  </Group>
  <Circle
    cX={360}
    cY={60}
    fill="green"
    lineWidth={0}
    r={40}
  />
  <Text
    fill="yellow"
    font="80px seril"
    text="Nice Work"
    textBaseline="top"
    x={200}
    y={200}
  />
</Canvas>

basic

Components

Canvas

Canvas with viewBox

<Canvas width={400} height={400} viewBox={[0, 0, 800, 800]} style={{ border: '1px solid red' }}>
  <Rect x={200} y={200} width={400} height={400} fill='steelblue' />
  <Circle cX={400} cY={400} r={150} fill='white' />
</Canvas>

Canvas

Line

<Line
  stroke='steelblue'
  lineWidth={5}
  start={[30, 50]}
  end={[150, 100]}
  // `start` and `end` also can use follow props
  // x={30}
  // y={50}
  // endX={150}
  // endY={100}
/>

Polygon

<Polygon
  fill='steelblue'
  points={[
    100, 100, // x1, y1
    150, 25,  // x2, y2
    150, 75,  // x3, y3
    200, 0,   // x4, y4
    // ...
  ]}
/>

Polygon

Rect

<Rect
  start={[10, 20]}  // x={10} y={20}
  size={[150, 100]} // width={150} height={100}
  fill='steelblue'
/>

Rect

Arc

<Arc
  center={[200, 100]} // cX={200} cY={100}
  r={50}
  startAngle={0} // in radians, measured from the positive x-axis
  endAngle={5}   // in radians, measured from the positive x-axis
  fill='steelblue'
/>

Arc

Circle

<Circle
  center={[200, 150]} // cX={200} cY={150}
  fill="steelblue"
  r={50} // radius
/>

Circle

Ellipse

<Ellipse
  center={[200, 150]} // cX={200} cY={150}
  radius={[150, 80]}  // rX={150} rY={80} // The ellipse's radius
  rotation={Math.PI / 4}
  startAngle={0}
  endAngle={1.6 * Math.PI}
  fill='palegoldenrod'
/>

Ellipse

ArcCurve

<ArcCurve
  start={[200, 20]}      // x={200} y={20}
  control1={[200, 130]}  // cp1X={200} cp1Y={130}
  control2={[50, 20]}    // cp2X={50} cp2Y={20}
  r={40}  // radius
  stroke='darkcyan'
/>

ArcCurve

BezierCurve

<BezierCurve
  start={[50, 20]}      // starting point, same as x={50} y={20}
  control1={[230, 30]}  // first control point, same as cp1X={230} cp1Y={30}
  control2={[150, 80]}  // second control point, same as cp2X={150} cp2Y={80} 
  end={[250, 100]}      // endX={250} endY={100}
  fill='transparent'
  stroke='steelblue'
  lineWidth={2}
/>

BezierCurve

QuadraticCurve

<QuadraticCurve
  start={[50, 20]}     // x={50} y={20}
  control={[230, 30]}  // cpX={230} cpY={30}
  end={[50, 100]}      // endX={50} endY={100}
  stroke='steelblue'
/>

QuadraticCurve

Path

Use attribute d to control, the same as svg

<Path
  fill='red'
  stroke='steelblue' // stroke color
  lineWidth={2}      // stroke width
  d={`
    M 10,30
    A 20,20 0,0,1 50,30
    A 20,20 0,0,1 90,30
    Q 90,60 50,90
    Q 10,60 10,30 z
  `}
/>

Path d heart

Image

<Image
  src='/mk-logo.png'
  // area on image
  source={{
    x: 256,
    y: 256,
    height: 512,
    width: 512
  }}
  // drawn area
  dest={{
    x: 20,
    y: 20,
    width: 200
  }}
/>

Image

Text

<Text
  text='Hello World'
  font='48px serif'
  fill='#4884b6'
  stroke='#c8ca42'
  textBaseLine='top'
  x={20}
  y={10}
/>

text

Group

<Group
  fill="darkgoldenrod" // Default `fill` for children
  lineWidth={4}        // Default `lineWidth` for children
  stroke="deeppink"    // Default `stroke` for children
  transform={[translate(160, 40), rotate(Math.PI / 180 * 30)]} // transforms
>
  <Rect
    height={25}
    width={25}
  />
  <Rect
    height={25}
    width={25}
    x={30}
  />
  <Rect
    fill="yellow"
    height={25}
    width={25}
    x={10}
    y={10}
  />
</Group>

To-Do

  • Event system
  • Animation