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

@jingx/plinko-threejs

v1.0.1

Published

Three.js plinko table animation packaged as a React component for Next.js.

Readme

@jingx/plinko-threejs

An interactive 3D Plinko board game built with Three.js rendering and cannon-es physics. Packaged as a React component for Next.js / React applications as well as a standalone Vanilla JavaScript API.


Features

  • 3D Physics & Rendering: Accurate rigid-body collisions powered by cannon-es and rendered with Three.js.
  • Dynamic Spot Bounce Feedback: Glowing emissive bounce animations on collision spots.
  • Flat Numeric Slot Badges: Rendered with numeric pocket numbers 5, 4, 3, 2, 1, 1, 2, 3, 4, 5 from left to right.
  • Deterministic Result Routing: Control exactly which pocket the ball lands in using canonical result keys (e.g. '5_LEFT', '1_RIGHT') or numeric slot indices.
  • Release Event Handling: onAfterRelease callback triggers as soon as the ball settles into the target slot pocket.
  • Synthesized Audio: Built-in Web Audio API synthesizer for peg bounces, drops, and win celebrations without external asset dependencies.
  • TypeScript Support: Full TypeScript declarations included out-of-the-box (dist/index.d.ts).

Installation

npm install @jingx/plinko-threejs three cannon-es

Note: three and cannon-es are required dependencies. If you are using React, react (>=18.0.0) is a peer dependency.


Slot Pocket Layout

For the default 9-row board (10 pockets), the layout from left to right is:

| Index | Canonical Name | Badge Label | Description | | :---: | :---: | :---: | :--- | | 0 | 5_LEFT | 5 | Outermost left pocket | | 1 | 4_LEFT | 4 | Left inner pocket 4 | | 2 | 3_LEFT | 3 | Left inner pocket 3 | | 3 | 2_LEFT | 2 | Left inner pocket 2 | | 4 | 1_LEFT | 1 | Center-left pocket 1 | | 5 | 1_RIGHT | 1 | Center-right pocket 1 | | 6 | 2_RIGHT | 2 | Right inner pocket 2 | | 7 | 3_RIGHT | 3 | Right inner pocket 3 | | 8 | 4_RIGHT | 4 | Right inner pocket 4 | | 9 | 5_RIGHT | 5 | Outermost right pocket |


Quick Start

1. React / Next.js Component

import React, { useState } from "react";
import PlinkoGame from "@jingx/plinko-threejs";

export function GameView() {
    const [result, setResult] = useState<string | null>("5_LEFT");

    const handleRelease = () => {
        console.log("Ball successfully landed in target pocket!");
    };

    return (
        <div style={{ width: "100%", height: "600px", position: "relative" }}>
            <PlinkoGame
                rows={9}
                result={result}
                isMuted={false}
                onAfterRelease={handleRelease}
            />
        </div>
    );
}

export default GameView;

2. Vanilla JavaScript / DOM

import { createPlinkoGame } from "@jingx/plinko-threejs";

const container = document.getElementById("plinko-container");

const game = createPlinkoGame({
    container,
    rows: 9,
    result: "5_RIGHT",
    isMuted: false,
    onAfterRelease: () => {
        console.log("Ball reached slot pocket!");
    },
    onWin: ({ slot, slotName, slotLabel, multiplier, payout }) => {
        console.log(`Landed in ${slotName} (${slotLabel}) - Multiplier: ${multiplier}x, Payout: $${payout}`);
    }
});

// Drop a ball with a new target dynamically:
game.setResult("1_LEFT");

// Clean up when destroying the view
// game.destroy();

API Reference

<PlinkoGame /> (React Component)

| Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | rows | number | 9 | Number of peg rows (8 to 16 supported). | | result | string \| number \| null | null | Target slot pocket key (e.g. '5_LEFT', '2_RIGHT') or slot index (0..9). | | onAfterRelease | () => void | undefined | Callback fired when the ball reaches and settles into the target slot pocket. | | isMuted | boolean | false | Whether synthesizer audio is muted. | | currentCountdown | number \| null | null | Optional round countdown timer. | | spinningSeconds | number | undefined | Duration hint for animation / countdown timing. | | className | string | undefined | CSS class for container <div>. | | style | CSSProperties | undefined | Inline styles for container <div>. |


createPlinkoGame(options) (Vanilla JS)

Options:

  • container?: HTMLElement - DOM element to mount the Three.js canvas into.
  • rows?: number - Row count (default 9).
  • result?: string | number | null - Target slot pocket result.
  • onAfterRelease?: () => void - Callback fired when the ball settles in target pocket.
  • onWin?: (result: PlinkoWinResult) => void - Win event callback.
  • isMuted?: boolean - Mute audio effects (default false).
  • initialBalance?: number - Initial virtual balance (default 1000.00).
  • initialBet?: number - Initial bet amount (default 10.00).
  • initialRisk?: 'Low' | 'Medium' | 'High' - Risk multiplier tier.

Instance Methods:

  • dropBall(laneX?: number) - Drops a ball from the top indicator or specified lane.
  • setResult(result: string | number | null) - Sets target pocket and triggers a drop.
  • getResult(): string | null - Retrieves current target pocket string.
  • setOnAfterRelease(callback: () => void) - Registers / updates release callback.
  • setRows(rows: number) - Reconfigures row count and rebuilds the board geometry.
  • setIsMuted(isMuted: boolean) - Toggles audio mute state.
  • getIsMuted(): boolean - Gets current audio mute state.
  • getSlotName(index: number): string | null - Returns canonical name (e.g. '5_LEFT').
  • getSlotLabel(index: number): string - Returns badge digit (e.g. '5', '4').
  • parseResultToSlotIndex(res: string | number): number | null - Resolves result string to slot index.
  • getState(): PlinkoGameState - Gets current state snapshot.
  • setState(state: Partial<...>) - Updates state properties.
  • destroy() - Disposes Three.js scene, physics bodies, event listeners, and DOM elements.

Exported Utilities

import { 
    getSlotName, 
    getSlotLabel, 
    parseResultToSlotIndex 
} from "@jingx/plinko-threejs";

getSlotName(0);  // "5_LEFT"
getSlotName(9);  // "5_RIGHT"

getSlotLabel(0); // "5"
getSlotLabel(4); // "1"
getSlotLabel(5); // "1"
getSlotLabel(9); // "5"

parseResultToSlotIndex("5_LEFT");  // 0
parseResultToSlotIndex("5_RIGHT"); // 9

Development

# Install dependencies
npm install

# Start development server
npm run dev

# Build library bundle (ESM + CJS + Types)
npm run build

# Build demo application
npm run build:demo

License

MIT © SPACX