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

@magicyan/canvas

v0.0.10

Published

A @napi-rs/canvas wrapper

Downloads

4

Readme

Magicyan Canvas

Install with

npm install @magicyan/canvas
pnpm install @magicyan/canvas
yarn add @magicyan/canvas
bun install @magicyan/canvas
  • This lib is a wrapper of @napi-rs/canvas
  • It works the same as the original library, but including the features below

Usage

import { Canvas } from "@magicyan/canvas";

async function main(){
    const canvas = new Canvas(1000, 1000);
    const context = canvas.getContext();

    context.style.set("fill", "#156490");
    context.fillRect(0, 0, canvas.width, canvas.height);

    context.style.set("fill", "white");

    context.fillRect(175, 496, 650, 430, [0, 0, 32, 32]);
    
    context.beginPath();
    context.moveTo(175, 496);
    context.lineTo(499, 164);
    context.lineTo(824, 496);
    context.closePath();
    context.fill();

    context.style.set("stroke", "white");
    context.line.set({ width: 46, cap: "round" });

    context.beginPath();
    context.moveTo(70.5, 496);
    context.lineTo(499.5, 67);
    context.lineTo(928.5, 496);
    context.stroke();

    context.style.set("fill", "#156490");

    // door
    context.fillRect(303, 646, 160, 280, [32, 32, 0, 0]);

    // window
    context.fillRect(558, 646, 180, 140, 32);

    await canvas.writeFile("./house.png", "png");
    console.log("Done");
}
main();

Output:

Context Style

import { Canvas } from "@magicyan/canvas";

const canvas = new Canvas(600, 300);
const context = canvas.getContext();

context.style.set("fill", "greenyellow");
context.style.set("stroke", "#41b5cc");
context.style.setFill("#dc3d3d");
context.style.setStroke("blueviolet");

console.log(context.style.fill); // #dc3d3d
console.log(context.style.stroke); // blueviolet

Context Filter

import { Canvas, blurFilter, filter, opacityFilter } from "@magicyan/canvas";

const canvas = new Canvas(600, 300);
const context = canvas.getContext();

context.filter.set(blurFilter(20), filter.sepia(40));
console.log(context.filter.current); // [ 'blur(20px)', 'sepia(40%)' ]

context.filter.add(opacityFilter(68));
console.log(context.filter.current); // [ 'blur(20px)', 'sepia(40%)', 'opacity(68%)' ]

context.filter.remove("Blur");
console.log(context.filter.current); // [ 'sepia(40%)', 'opacity(68%)' ]

context.filter.clear();
console.log(context.filter.current); // [ 'none' ]

Context Line

import { Canvas } from "@magicyan/canvas";

const canvas = new Canvas(600, 300);
const context = canvas.getContext();

context.line.set({
    cap: "round",
    dash: [5, 15],
    join: "bevel",
    dashOffset: 4,
    width: 12
});

context.line.setCap("square");
context.line.setDash(5, 12, 8);
context.line.setDashOffset(2);
context.line.setJoin("round");
context.line.setWidth(8);

console.log(context.line.cap); // square
console.log(context.line.dash); // [ 5, 12, 8 ]
console.log(context.line.dashOffset); // 2
console.log(context.line.join); //  round
console.log(context.line.width); // 8

Context Font

import { Canvas } from "@magicyan/canvas";

const canvas = new Canvas(600, 300);
const context = canvas.getContext();

context.font.set({
    size: 40,
    family: "Montserrat",
    style: "italic",
    weight: "semibold",
    baseline: "top",
    align: "start",
    kerning: "auto"
});

context.font.setSize(60);
context.font.setFamily("Poppins");
context.font.setStyle("italic underline");
context.font.setWeight("light");
context.font.setBaseline("bottom");
context.font.setAlign("right");
context.font.setKerning("none");

console.log(context.font.size); // 60
console.log(context.font.family); // Poppins
console.log(context.font.style); // italic underline
console.log(context.font.weight); // light
console.log(context.font.baseline); // bottom
console.log(context.font.align); // right
console.log(context.font.kerning); // none

Context Gradient

import { Canvas } from "@magicyan/canvas";

const canvas = new Canvas(600, 300);
const context = canvas.getContext();

context.style.set("fill", context.createGradient({
    type: "linear",
    x0: 0, y0: 0,
    x1: canvas.width, y1: canvas.height,
    colorStop: {
        0.1: "#40ade7",
        0.4: "#2858a1",
        0.9: "#351b6d"
    }
}));