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

@grafikjs/core

v0.0.7

Published

A lightweight JavaScript library for creating interactive SVG on the web.

Downloads

13

Readme

GrafikJS Core

The Core package is the foundational library of GrafikJS, providing the essential object model and engine that powers all GrafikJS functionalities. It handles the computation of transformation matrices, manages animations, and ensures efficient event handling, making it the backbone of GrafikJS's interactive and scalable vector graphics capabilities.

Purpose and Usage

It's important to note that while the Core package provides core functionalities for managing graphics data and behavior, it does not handle rendering or direct interaction with the DOM. For rendering SVG graphics in web applications, GrafikJS offers integrations with Vue.js, React, Angular, and Svelte packages, which integrate with Core library.

Developers can enhance their applications by utilizing the Core library to manage and manipulate graphical elements efficiently, whether within a framework ecosystem or as a standalone utility for mathematical computations and graphical data management.

Standalone Utility

While the Core library is primarily designed for use with graphical rendering frameworks, it can also be utilized independently as a powerful utility library. Developers can leverage it for:

2D Transformation Matrices: Performing mathematical calculations with 2D transformation matrices for various graphic manipulations.

const m1 = new grafik.Matrix().fromArray([0.5, 0, 0, 0.5, 500, 400]);
const m2 = new grafik.Matrix().fromArray([1.5, 0, 0, 1.5, 200, 300]);

m2.rotate(45);

m1.multiply(m2);

m1.scale(2);

console.log(m1.toCSS()); // Expected output: 'matrix(1.0606, 1.0606, -1.0606, 1.0606, 600, 550)'

Point Class: Representing and manipulating coordinates (x, y) within a graphical context.

const p1 = new grafik.Point(20, 25);
const p2 = new grafik.Point(12, 18);

p1.rotate(p2, 45); // Center point, and angle

p2.lerp(p1, 0.4);

console.log(p1.toString()); // Expected output: '12.7071 28.6066'

Bounding Box Calculations: Computing Axis-Aligned Bounding Boxes (AABBs) to determine the boundaries of graphical elements.

const b1 = new grafik.BBox(new grafik.Point(-10, -10), new grafik.Point(10, 10)); // Min, and max
const b2 = new grafik.BBox().fromPoints([
	new grafik.Point(10, 10),
	new grafik.Point(30, 10),
	new grafik.Point(30, 30),
	new grafik.Point(10, 30)
]);
const p = new grafik.Point(20, 20);

console.log(b1.intersects(b2)); // Expected output: true
console.log(b1.contains(p)); // Expected output: false
console.log(b2.contains(p)); // Expected output: true

b1.union(b2);

console.log(b1.getSize()); // Expected output: > Point {x: 40, y: 40}
console.log(b1.getOrigin()); // Expected output: > Point {x: 0.25, y: 0.25}

Curve Paths and Segments: Dynamically creating and managing SVG paths using various curve types such as:

  • Cubic Bezier Curve (CubicBezierCurve)
  • Quadratic Bezier Curve (QuadraticBezierCurve)
  • Line Curve (LineCurve)
  • Arc Curve (ArcCurve)
const cp = new grafik.CurvePath();
cp.moveTo(50, 50)
	.lineTo(100, 100)
	.quadraticCurveTo(150, 50, 200, 100)
	.cubicCurveTo(250, 150, 300, 100, 350, 150);

console.log(cp.updateBBox().getBBox().getSize()); // Expected output: > Point {x: 300, y: 100}
console.log(cp.toString()); // Expected output: M 50 50 L 100 100 Q 150 50 200 100 C 250 150 300 100 350 150