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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ink-playing-cards

v0.7.0

Published

A ink component to render playing cards and card games

Downloads

1,657

Readme

Ink Playing Cards

This library provides a flexible and extensible framework for building card games using React and Ink. It offers a set of components, hooks, and utilities that make it easy to create various types of card games, from simple to complex.

Features

  • Flexible card and deck management
  • Support for standard playing cards and custom cards
  • Zone system for managing different areas of the game (deck, hand, discard pile, play area)
  • Event system for handling game events
  • Advanced effect system for implementing complex card effects
  • Easy-to-use hooks for accessing game state and actions
  • Pre-built UI components for common card game elements
  • Customizable styling

Installation

npm install ink-playing-cards

Basic Usage

Here's a simple example of how to use the library to create a basic card game:

import React from 'react'
import { Box, Text } from 'ink'
import { DeckProvider, useDeck, Card, CardStack } from 'ink-playing-cards'

const Game = () => {
  const { deck, hand, draw, shuffle } = useDeck()

  React.useEffect(() => {
    shuffle()
    draw(5, 'player1')
  }, [])

  return (
    <Box flexDirection="column">
      <CardStack cards={deck.cards} name="Deck" />
      <Text>Your hand:</Text>
      <CardStack cards={hand.cards} name="Hand" faceUp maxDisplay={5} />
    </Box>
  )
}

const App = () => (
  <DeckProvider>
    <Game />
  </DeckProvider>
)

export default App

Core Concepts

Zones

The library uses a zone system to manage different areas of the game:

  • Deck
  • Hand
  • Discard Pile
  • Play Area

Each zone has methods for adding, removing, and manipulating cards.

Events

The event system allows you to respond to various game events, such as drawing cards or playing cards. You can listen for events and trigger custom logic when they occur.

Advanced Effects

The advanced effect system enables you to define and apply complex effects to cards. It supports:

  • Conditional effects
  • Triggered effects
  • Continuous effects
  • Delayed effects
  • Targeted effects

This system is useful for implementing card abilities, special rules, and complex game mechanics.

UI Components

The library provides pre-built UI components for common card game elements:

Card

Standard playing card with multiple display variants:

<Card
  suit="hearts"
  value="A"
  variant="simple" // 'simple' | 'ascii' | 'minimal'
  faceUp={true}
  selected={false}
  rounded={true}
/>

MiniCard

Compact card representation for space-efficient layouts:

<MiniCard
  suit="spades"
  value="K"
  variant="mini" // 'mini' | 'micro'
  faceUp={true}
  selected={false}
  rounded={true}
/>

CustomCard

Highly customizable card for special game mechanics:

<CustomCard
  size="medium" // 'small' | 'medium' | 'large'
  title="Special Card"
  description="Custom effect description"
  asciiArt={customArt}
  symbols={[{ char: '★', position: 'top-left', color: 'yellow' }]}
  borderColor="blue"
  textColor="white"
  faceUp={true}
/>

CardStack

Displays a stack of cards with customizable spacing and alignment:

<CardStack
  cards={handCards}
  name="Player Hand"
  variant="simple"
  stackDirection="horizontal" // 'horizontal' | 'vertical'
  spacing={{ overlap: -2, margin: 1 }}
  alignment="center" // 'start' | 'center' | 'end'
  maxDisplay={5}
  isFaceUp={true}
/>

Grid

Arranges cards in a customizable grid layout:

<Grid
  rows={3}
  cols={3}
  cards={gameBoard}
  variant="simple"
  spacing={{ row: 1, col: 1 }}
  alignment={{
    horizontal: 'center', // 'left' | 'center' | 'right'
    vertical: 'middle', // 'top' | 'middle' | 'bottom'
  }}
  fillEmpty={true}
  isFaceUp={true}
/>

Deck

Manages and displays a complete deck of cards:

<Deck
  variant="simple"
  showTopCard={true}
  placeholderCard={{ suit: 'hearts', value: 'A' }}
/>

Each component supports:

  • Multiple display variants
  • Customizable styling
  • Flexible layout options
  • Interactive states
  • Type-safe props

These components can be easily customized and styled to fit your game's needs. For more advanced usage and complex configurations, refer to the examples in the examples/ directory.

Advanced Usage

For more advanced usage, including custom cards, multiple players, and complex game logic, please refer to the examples in the examples/ directory.

Interactive Component Showcase

The library includes an interactive storybook-style component showcase that helps you explore and understand all available components and their configurations.

Running the Showcase

# Install dependencies
yarn install

# Start the showcase
yarn dev

Features

The showcase provides an interactive CLI interface to explore:

  • Card Components

    • Standard Card (simple, ASCII, and minimal variants)
    • MiniCard (compact card representations)
    • CardStack (various card arrangements)
    • Deck (full deck management)
    • CustomCard (highly customizable cards)
  • Component Configuration

    • Interactive property controls
    • Real-time preview
    • Multiple variant support
    • Style customization

Navigation

The showcase uses a step-by-step navigation system:

  1. Select a component to view
  2. Configure basic properties (variant, suit, value)
  3. Adjust display options (face up/down)
  4. Customize styling (borders, selection state)

Each step provides:

  • Hotkey support for quick navigation
  • Visual indicators for current state
  • Forward/back navigation
  • Live component preview

Development

The showcase is particularly useful during development:

  • Test component changes in real-time
  • Verify visual appearance across variants
  • Ensure proper prop handling
  • Debug styling issues

To modify or extend the showcase:

  1. Components are in src/components/
  2. Showcase views are in src/storybook/views/
  3. Each component has its own view file
  4. Views follow a consistent pattern for state management and navigation

Contributing

Contributions are welcome! Please read our contributing guidelines for details on how to submit pull requests, report issues, or request features.

License

This project is licensed under the MIT License - see the LICENSE file for details.