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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@juleslois/virtual-gamepad

v0.1.1

Published

Reusable virtual touch controls and browser gamepad input source with a framework-agnostic core.

Readme

@juleslois/virtual-gamepad

Reusable virtual touch controls and a browser Gamepad API source for Canvas/WebGL games and React apps. The core is framework-agnostic; the React overlay is an optional wrapper.

Extracted from cmys-fight, a deterministic browser action roguelite.

Install

npm install @juleslois/virtual-gamepad

Peer dependency: react >= 18 is only required for the ./react entry.

Core (framework-agnostic)

import {
  calculateTouchViewportOffsets,
  applyTouchViewportOffsets,
  joystickVector,
  pulseHaptics,
  GamepadSource,
  updateAxisNavigation,
  createAxisNavigationState,
} from "@juleslois/virtual-gamepad";
  • calculateTouchViewportOffsets(width, height, options?) — reserves safe gutters for a letterboxed 4:3 game viewport (aspect, scales and cluster sizes are configurable).
  • applyTouchViewportOffsets(container, offsets) — writes the --touch-* CSS variables that the stylesheet consumes.
  • joystickVector(clientX, clientY, bounds, radiusFactor?) — pure function that converts a pointer position into a normalized { x, y } axis.
  • pulseHaptics(duration?) — safe navigator.vibrate wrapper.
  • GamepadSource.poll() — returns a GamepadFrame (axes, buttons, dPad) from the first connected gamepad, with deadzone and d-pad synthesis applied. Feed the raw state into your own action mapping.
  • updateAxisNavigation(state, x, y, now, suppressed) — menu-style navigation state machine: one immediate step, 420ms delay, 160ms repeat, neutral gate for direction changes. createAxisNavigationState() builds the initial state.

React overlay

import { VirtualTouchControls, type VirtualGamepadButton } from "@juleslois/virtual-gamepad/react";
import "@juleslois/virtual-gamepad/style.css";

const buttons: VirtualGamepadButton[] = [
  { id: "pause", slot: "start", label: "START", hapticMs: 12 },
  { id: "fire", slot: "x", label: "X" },
  { id: "interact", slot: "a", label: "A" },
  { id: "skill", slot: "b", label: "B" },
  { id: "swap", slot: "y", label: "Y" },
];

<TouchHost>
  <VirtualTouchControls
    buttons={buttons}
    layout="right"
    labelMode="gamepad"
    scale={1}
    onAxisChange={(x, y) => input.setAxis(x, y)}
    onButtonChange={(id, down) => input.setAction(id, down)}
  />
</TouchHost>

The component owns pointer capture, knob rendering, haptics and label layout. Your app maps button ids and the axis to its own semantic actions.

Styling

Import the stylesheet once (@juleslois/virtual-gamepad/style.css). The pixel gamepad theme is driven by CSS variables:

  • --touch-scale — overall control scale (the component sets it from the scale prop).
  • --touch-bottom-offset / --touch-top-offset / --touch-side-offset — safe-area-aware edge gaps (set via applyTouchViewportOffsets or manually).
  • --face-top / --face-shadow — face button colors.

Override any .touch-* rule for a custom theme.

Development

The package lives at src/virtual-gamepad inside the cmys-fight repository. The game itself consumes it through the package name (@juleslois/virtual-gamepad as a file: dependency), so every build and test run continuously validates the published artifact layout. Build and test from the repository root:

npm run build:sdk   # esbuild ESM + d.ts into src/virtual-gamepad/dist
npm run test:sdk    # build + contract smoke test
npm run version:sdk [major|minor|patch]  # bump package version
npm run publish:sdk:dry-run  # inspect the tarball without publishing
npm run publish:sdk          # build and publish to npm