Skip to the content

Toranpuトランプ

Use a deck, play eleven games with computers, solve a solitaire, or display cards in your own design.

Toranpu is Japanese for playing cards. About the name

Contents

Reference

Register card tags

import { … } from "@johnmorrisdotca/toranpu/element/define";

242.8 kB minified and gzipped, with everything it imports (measured with esbuild)

The custom elements, registered by being imported:

<script type="module" src="…/dist/element-define.js"></script>

<toranpu-card card="QS" flip></toranpu-card>

This is the one module of the package that does something when it is imported, and package.json says so, so that a bundler keeps it. ./element exports the same classes and defineToranpuElements() with no effect of its own, for a page that wants to choose when.

Exports

NameKindWhat it is
arrangeCardsfunctionA hand laid out another way, as a new list (the one given is left alone): "rank" sorts it low to high, the ace high, a rank's cards in suit order; "suit" groups it by suit, spades, hearts, clubs, diamonds, each in rank order; "face" groups it into the number cards, ace to ten, and then the face cards, jack, queen, king, each group in rank order and a rank's cards in suit order; "dealt" keeps the order given.
BUNDLE_BACKSconstantHow many backs a squared-up bundle shows, whatever the hand: a bundle never tells how many cards are in it.
CardFaceContexttypeWhat a card's face function is told: the language the card speaks, and the design it names.
CardFaceRenderertypeA function that draws a card's face: given the card's id and its context, SVG markup (drawn on the card's paper in a box 100 by 140, or a whole <svg> document), or an element, or null to draw the card as its design does.
CardLandstypeWhere a card a hand is given goes: to the front, or the end.
CardOrdertypeHow a hand's cards are laid out: as they were dealt, by rank, grouped by suit, or the number cards apart from the face cards.
CardPlacetypeOne card's place: across and down in card widths from where the first lies, and its turn in degrees.
defineHandfunctionRegister a hand under its standard tag or a host-supplied tag.
defineToranpuElementsfunctionRegister the elements under their tags, once; a tag already taken is left as it is.
ELEMENT_SIZESconstantThe sizes every element takes, as a card's width in pixels.
handLayoutfunctionWhere each card of a hand of count lies: a fan when open, a squared-up stack with a sliver of each card showing when closed, and every shape in between.
HandLayoutOptionstypeHow a hand is laid out.
HandTurnOptionstypeHow a hand's cards are turned face down or face up.
mixCardsfunctionA hand mixed up, as a new list: the same cards in another order, never the order given (where a hand has two cards or more that differ), so a mix is always seen to change something.
partedHandLayoutfunctionA HAND PARTED AT ONE CARD: that card lifted a little, upright and wholly in view, and the cards to its left and right drawn apart from it into a group on each side (one group where it is the first or the last).
PartOptionstypeHow a parted hand is laid out.
pileLayoutfunctionWhere each card of a pile of count lies, bottom first, the top card last: at 0 messiness a neat stack whose edge shows a card's thickness for each card under the top, and towards 1 a heap, each card nudged and turned a little more.
PileLayoutOptionstypeHow a pile is laid out.
readHandfunctionA hand written as text, as its cards: the two-letter ids separated by spaces or commas ("AS KH 10D TC RJ", with 10 for ten as well as T), or the deck's one-letter codes run together ("pvOZ").
registerCardBackfunctionKeep a back by its name.
registerCardDesignfunctionKeep a design by its name, in place of any earlier one of that name.
replaceCardfunctionA hand with one card tossed out and another given in its stead, at the front or the end: as a new list.
SpinOptionstypeHow a card is spun.
TORANPU_TAGSconstantThe elements' tags.
ToranpuCardclassONE CARD ON ANY PAGE: <toranpu-card card="QS">, in any design and with any back, face up or face down, turned over by a tap when it has flip.
ToranpuHandclassA HAND OF CARDS ON ANY PAGE: <toranpu-hand cards="AS KH QD">, fanned, in any design and with any back.
ToranpuPileclassA PILE OF CARDS ON ANY PAGE: <toranpu-pile>, a stock to draw from or a discard pile, its top card on top and the cards under it showing as a stack, from neatly squared to very messy.
tossCardfunctionA hand without one card, as a new list: the first of that card taken out, or the hand unchanged where it holds none.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/toranpu 2.15.0.