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

svelte-playing-cards

v2.2.0

Published

A customizable deck of playing cards

Downloads

9

Readme

Svelte Playing Cards

A highly customizable package for making card games in svelte. Provides two components Card and Deck. By default renders svg cards by nicubunu.

To import types for typescript project:

<script>
    import type {Suit,Value,ValueWithoutJoker,CardType} from 'svelte-playing-cards/Card.svelte';
</script>

Usage

  1. Deck
    Component to generate deck of cards

    Import component by

    import Deck from "svelte-playing-cards/Deck.svelte"

    and use it in your code

    <Deck />

    by default it renders all 52 cards (without jokers) To specify cards pass it in as a list to deck prop

    <Deck deck={["10-of-CLUBS","QUEEN-of-HEARTS","BLACK-JOKER"]} />

    Other props are:

    |Props|Default values|Description| |:---:|:------------:|:---------:| |deck| all 52 cards(without jokers)|list of cards to render| |shouldShuffle| true|should shuffle the supplied deck| |cardWidth| "200px"|width of single card| |cardHeight|"250px"|height of single card| |cardCustomFronts|[ ]|list of cards which should have custom front along with custom component and its props| |cardCustomBackComp|null|custom component for back of cards| |cardCustomBackCompProps|{}|props for custom back component| |topPosition|"0px"|distance from top| |leftPosition|"0px"|distance from left| |topPositionOffset|0.1|offset from topPosition (helps in giving 3d look to deck)| |leftPositionOffset|0.5|offset from leftPosition (helps in giving 3d look to deck)| |frontShowingCards|[ ]|list of cards showing front| |onClick|remove the top card from deck| on:click handler| |onDblClick|shuffle the deck| on:dblclick handler|

    To use methods:

    <script>
        import Deck from "svelte-playing-cards/Deck.svelte"
        let deckComp: Deck;
    
        $: if(deckComp){
            // now you can use the methods available on Deck like deckComp.drawTopCard()
        }
    </script>
    
    <Deck bind:this={deckComp} />

    Available methods are: |Methods|Description| |:-----:|:---------:| |gettingReady|makes Deck ready to call other method upon. Only needed if you need to call other methods immediatly after initialization| |getDeck|get the deck| |drawTopCard|remove the top card| |drawCards|remove n cards| |shuffleWithTransition|shuffle the deck with optional transition| |showCardFront|show frontside of a card| |hideCardFront|show backside of a card| |flipCard| flip a card| |showTopCardFront|show frontside of top card| |hideTopCardFront|show backside of top card| |flipTopCard| flip top card| |drop| drag and drop a card|

    Available Functions are: |Functions|Description| |:-------:|:---------:| |generateFullDeckFun|generates a full deck (with/without jokers) |shuffleFun|shuffle the provided deck|

  2. Card

    Component to render a card Import component by

    import Card from "svelte-playing-cards/Card.svelte"

    and use it in your code

    <Card card="10-of-CLUBS" />

    Other props are:

    |Props|Default values|Description| |:---:|:------------:|:---------:| |width|"200px"|width| |height|"250px"|height| |topPosition|"0px"|css top (in case of position = absolute)| |leftPosition|"0px"|css left (in case of position = absolute)| |position|"absolute"|position| |showBackSide|true|should show back side| |card*|-|card face value (value-of-suit)| |customBack|null|custom component to display on backside of card| |customBackProps|{}|props for custom back component| |customFront|null|custom component to display on frontside of card| |customFrontProps|{}|props for custom front component| |enableDrag|true|allow card to be drag and drop| |shouldRotate|false|rotate 90deg to swap width and height| |onClick|flip the card| on:click handler| |onDblClick|remove the card (from DOM)| on:dblclick handler|

    To use methods:

    <script>
        import Card from "svelte-playing-cards/Card.svelte"
        let cardComp: Deck;
    
        $: if(cardComp){
            // now you can use the methods available on Card like cardComp.flip()
        }
    </script>
    
    <Card bind:this={cardComp} />

    Available methods are: |Methods|Description| |:-----:|:---------:| |getCard|get the card value hold by this card| |flip|flip the card| |remove|remove the card (from DOM)| |transitionToTarget|transitions the card towards target| |showFront|show frontside of card| |showBack|show backside of card| |drop|function to call when drop the card on HTMLElement|
    |getPosition|get css top and left of the card| |setPosition|set css top and left of the card| |getSuppliedProps|get supplied props to the card| |shufflingTransition|make shuffling transition. (does not make sense to use it alone. Better to use in a deck)|