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

@darkroom.engineering/elastica

v0.0.13

Published

### ⚠️ Still in development mode - API might change ⚠️

Downloads

38

Readme

Elastica

⚠️ Still in development mode - API might change ⚠️

Demo

Introduction

Elastica is a JavaScript library providing a physics engine for simulating elastic collision using Aligned axis bounding boxes (AABBs) and grid hash for efficient collision detection. It has a React wrapper which provides hooks and components for managing the state and interactions of your elements. Apply your own Cinematic equation for position and velocity of particles.

Installation

npm i @darkroom.engineering/elastica

Setup

import Elastica, {
  AxisAlignedBoundaryBox,
  initalConditionsPresets,
  updatePresets,
} from '@darkroom.engineering/elastica/react'

Elastica will wrap your component getting the dimensions for borders calculations and the grid size for collisions.

<Elastica
  config={{
    collisions: true,
    borders: 'rigid',
  }}
  initialCondition={initalConditionsPresets.random}
  update={updatePresets.dvdScreenSaver}
>
  {[{ name: 'DVD' }].map(({ name }, index) => (
    <AxisAlignedBoundaryBox key={index}>{name}</AxisAlignedBoundaryBox>
  ))}
</Elastica>

AxisAlignedBoundaryBox will wray your elements getting their size for collisions and positioning.

API

ReactElastica

| Prop | Type | Default | Description | | --------------------- | ----------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | children | ReactNode | N/A | Represents the child elements or components rendered within the ReactElastica component. These elements are part of the elastic collision simulation. | | className | string | N/A | Specifies a CSS class for styling the ReactElastica container, allowing custom styling and theming. | | showHashGrid | boolean | false | Shows the hash grid for measuing correct grid size. | | config | object | See below | Configuration object controlling various aspects of the physics simulation. | | └─ gridSize | number | 8 | Defines the size of the hash grid, bigger grid reduces number of computation by collisions but should not be smaller than biggest element. | | └─ collisions | boolean | true | Enables or disables collision detection between elements. | | └─ borders | string | 'rigid' | Defines the border behavior. 'rigid' indicates immovable borders, preventing objects from passing through the container's edges. 'Periodic' translates elements to opposite border when reaching limit. | | └─ containerOffsets | object | See below | Specifies the offsets from the container's edges for the simulation area, allowing for padding or margins. | | └── top | number | 0 | Top offset. | | └── bottom | number | 0 | Bottom offset. | | └── left | number | 0 | Left offset. | | └── right | number | 0 | Right offset. | | initialCondition | function | () => {} | Function to set the initial conditions of the simulation, such as starting positions and velocities of elements. It is called once when the component mounts. Engine instance Class passed as props | | update | function | () => {} | Callback function called on each simulation update, where cinematic equations have to be applied to each element. Engine instance Class passed as props. |

Aligned Axis Boundary Box

| Prop | Type | Default | Description | | ----------- | ----------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | className | string | N/A | Specifies a CSS class for styling the boundary box. This allows for custom styling of the container holding the children elements. | | children | ReactNode | N/A | Represents the child elements or components that will be enclosed within the boundary box. These children are subject to the constraints of the boundary box. | | ...props | object | N/A | Additional props that can be passed to the component. These props can include any other attributes or handlers needed for the custom behavior of the boundary box. |

useElastica

Hook that exposes the Elastica instance and provides a set of functions for managing the simulation.

initalConditionsPresets

Object containing preset functions for setting initial conditions of the simulation.

updatePresets

Object containing preset functions for updating the simulation.

Examples

For more examples check demo github