gravitify
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

Gravitify

Brings HTML nodes and their JavaScript functionality to the canvas and applies physics to everything using matter.js.

Screenshot 2024-03-19 at 12 25 48 PM

Installation

The following command lets you install the public package directly from NPM:

npm install gravitify

Usage

The gravitify function is the main function of the library. It converts a DOM root element and its children into a 2D physics scene by creating or resizing a canvas to the same size as the root element and adding all 'top level elements' as entities. 'Top level element' means buttons, text, inputs and so on. These elements can be defined by their css selectors and a function.

import { gravitify } from "gravitify";

const canvas = document.querySelector("canvas") as HTMLCanvasElement;
const main = document.querySelector("main") as HTMLElement;

// default usage
gravitify(main, canvas);

// with entity elements specified by their css selectors and a function
gravitify(main, canvas, ["#super-specific", "button", "a"], (e) => {
    return e.children.length === 0;
}, { /* See: `gravitify.PhysicsOptions` jsDoc */ });

Tests

For testing purposes there is a Parcel and TypeScript project in the test directory.

# install all dependencies
npm i

# start the parcel development server for the test page
npm run dev

Readme

Keywords

none

Package Sidebar

Install

npm i gravitify

Weekly Downloads

12

Version

0.0.6

License

MIT

Unpacked Size

23.8 kB

Total Files

6

Last publish

Collaborators

  • maxwellmatthis