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

jpad-components

v1.0.2

Published

A set of web-components to build declarative virtual gamepad layouts

Downloads

89

Readme

<jpad-components>

NPM Version GitHub License

A set of web-components to build declarative virtual gamepad layouts.

The aim of this project is to enable rapid prototyping and to provide a simple way of implementing touch / keyboard inputs without having to write custom UI code.

The jpad-components are designed to work with any framework and game engine, you can use the jpad-controller API directly in your game loop or listen to the controller, trackpad or button events as needed.

Installation

jpad-components is available on npm:

npm i jpad-components

Usage

Import the components separately or as a bundle:

// import as a bundle
import 'jpad-components'; // Load all elements in one go

// or just the components you need
import 'jpad-components/jpad-controller.js'; // Layout controller and simple API
import 'jpad-components/jpad-tile.js'; // Create familiar button layouts
import 'jpad-components/jpad-button.js'; // Handle input as a button or trigger
import 'jpad-components/jpad-trackpad.js'; // Handle movement in any direction
<!-- available on CDN too -->
<head>
  ...
  <script src="https://esm.run/jpad-components" type="module"></script>
</head>

The components API is documented here.

Here's a minimal example:

<!-- Define the layout -->
<jpad-controller>
    <jpad-trackpad
      name="movement"
      upkeys="ArrowUp, KeyW"
      downkeys="ArrowDown, KeyS"
      leftkeys="ArrowLeft, KeyA"
      rightkeys="ArrowRight, KeyD"
      slot="left"
    ></jpad-trackpad>

    <jpad-tile slot="right">
      <jpad-button passby name="jump" keys="Z">Z</jpad-button>
      <jpad-button passby name="attack" keys="X">X</jpad-button>
    </jpad-tile>
</jpad-controller>

<script>
  // Get the element
  const jpad = document.querySelector('jpad-controller');

  // Use it with the input api
  jpad.getAxis('movement');
  jpad.isPressed('attack');
  jpad.isJustPressed('attack');

  // You can also listen for the events
  jpad.addEventListener('buttontrigger', (e) => {
    console.log(e.detail.name, e.detail.pressed);
  });
  jpad.addEventListener('trackpadmove', (e) => {
    console.log(e.detail.name, e.detail.axis);
  });
</script>

Some examples in the wild

Here's some demos that use jpad-components to handle their inputs:

License

This project is released under the MIT license.

Contributions

Any contribution or feedback is warmly welcomed, this project has been tested on a limited set of devices and browsers and might display some bugs.

If you need support or found a bug

If you need and help or have found a bug, feel free to leave an issue or DM me on Nostr.