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

@salvadorsru/card-deck

v1.0.4

Published

Simple Web Component that animates card swipes similar to Tinder's effect.

Downloads

20

Readme

Card Deck Web Component

Live Demo

CSS and Component Import

To use the component, ensure you include the CSS from the dist folder, as the package only includes the Web Component JavaScript when imported into your project.

<link rel="stylesheet" href="@salvadorsru/card-deck/dist/style.min.css" />
<script type="module" src="@salvadorsru/card-deck/index.min.js"></script>

Alternatively, you can import the package directly in your JavaScript/TypeScript files:

import "@salvadorsru/card-deck";

Note: Importing the package via JavaScript does not include the CSS. You will need to manually include the CSS from the dist folder in your project.

Events

The card-deck component emits a custom event named discard whenever a card is removed from the deck.

An event called cardRemoved is also emitted when a card has been discarded and is permanently removed. This means that the discarded card has completely disappeared from the screen after its animation finishes, and its HTML element has been removed.

Triggered By: The component when a card is removed.

Event Detail Properties:

  • goRight (boolean): true if the card was discarded to the right, false if to the left.
  • goDown (boolean): true if the card was discarded downward, false if upward.
  • card (HTMLElement): A reference to the removed card's HTML element.

Behavior

  • Cards move left or right with the .go-left and .go-right classes.
  • The .reset class resets the card's position.
  • Card moves it will have a class with the adjective .dragged. Depending on its direction, it also gets one of the following classes .to-left, .to-right, .to-top, .to-bottom.

These variables allow flexibility in adjusting the appearance and behavior of the card deck without modifying the core CSS.

Use example

Basic usage

You can statically define all the elements as follows:

<card-deck>
  // Card container
  <div></div>
  // Card container
  <div></div>
  // Card container
</card-deck>

External card deck management

You can programmatically control the behavior of a <card-deck> using the following subpackage.

Include via HTML

<script type="module" src="@salvadorsru/card-deck/emulate.min.js"></script>

Or import via JavaScript

import emulate from "@salvadorsru/card-deck/emulate";
// or
import { discardToRight, discardToLeft } from "@salvadorsru/card-deck/emulate";

This module provides the discardToRight and discardToLeft functions, which allow you to move the card deck to the right or left through code, easily and programmatically.

Example Usage

import { discardToRight, discardToLeft } from "@salvadorsru/card-deck/emulate";

const $deck = document.querySelector("card-deck");

discardToRight($deck);
// or
discardToLeft($deck);

CSS Variables for card-deck

The card-deck component supports various CSS variables to allow customization of its appearance and behavior.

Size Variables

  • --card-width (default: 150px): Defines the width of each card *Required.
  • --card-height (default: 200px): Defines the height of each card *Required.
  • --card-ratio (default: 1.5): Sets the aspect ratio of the cards.

Animation Variables

  • --transition-time (default: 0.3s): Controls the duration of the transform animation when a card moves.
  • --transition-opacity (default: 0.3s): Defines the transition time for opacity changes.
  • --transition-rotation (default: 0.3s): Sets the transition duration for the rotation effect.