本文へ移動

Toranpuトランプ

デッキを使い、11種類のゲームでコンピューターと対戦し、ソリティアを解いたり、独自の絵柄でカードを表示したりできます。

「トランプ」は、日本語で playing cards を指す言葉です。 名前について(英語)

目次

リファレンス

カード・手札・山札

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

最小化と gzip 圧縮をしたサイズは 242.8 kB(読み込むものをすべて含み、esbuild で計測)

リファレンスの説明と例は英語です。見出しと目次は日本語です。

Toranpu's custom elements, for any page and any framework that renders HTML, and the arithmetic behind them:

  • <toranpu-card>: one card, in any design and with any back, turned over by a tap.
  • <toranpu-hand>: a hand, fanned; turned face down where it lies, all at once or one by one; squared up into a bundle that shows nothing; or held closed, to open on a tap.
  • <toranpu-pile>: a stock or a discard pile, neat or messy, from a seed.
import { defineToranpuElements } from "@johnmorrisdotca/toranpu/element";

defineToranpuElements();
document.body.insertAdjacentHTML("beforeend", '<toranpu-card card="KS" design="english" flip></toranpu-card>');

Or with no call at all: importing @johnmorrisdotca/toranpu/element/define registers them by being imported.

Your own faces and backs: registerCardDesign and registerCardBack (also from /card-faces and /card-backs) keep them by name, so design="frontier" and back="frontier" work on every element of the page; a card also takes an element in slot="face" or slot="back", or a face function.

エクスポート

名前種類概要
arrangeCards関数A 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_BACKS定数How many backs a squared-up bundle shows, whatever the hand: a bundle never tells how many cards are in it.
CardFaceContext型What a card's face function is told: the language the card speaks, and the design it names.
CardFaceRenderer型A 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.
CardLands型Where a card a hand is given goes: to the front, or the end.
CardOrder型How 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.
CardPlace型One card's place: across and down in card widths from where the first lies, and its turn in degrees.
defineHand関数Register a hand under its standard tag or a host-supplied tag.
defineToranpuElements関数Register the elements under their tags, once; a tag already taken is left as it is.
ELEMENT_SIZES定数The sizes every element takes, as a card's width in pixels.
handLayout関数Where 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.
HandLayoutOptions型How a hand is laid out.
HandTurnOptions型How a hand's cards are turned face down or face up.
mixCards関数A 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.
partedHandLayout関数A 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).
PartOptions型How a parted hand is laid out.
pileLayout関数Where 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.
PileLayoutOptions型How a pile is laid out.
readHand関数A 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").
registerCardBack関数Keep a back by its name.
registerCardDesign関数Keep a design by its name, in place of any earlier one of that name.
replaceCard関数A hand with one card tossed out and another given in its stead, at the front or the end: as a new list.
SpinOptions型How a card is spun.
TORANPU_TAGS定数The elements' tags.
ToranpuCardクラスONE 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.
ToranpuHandクラスA HAND OF CARDS ON ANY PAGE: <toranpu-hand cards="AS KH QD">, fanned, in any design and with any back.
ToranpuPileクラスA 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.
tossCard関数A hand without one card, as a new list: the first of that card taken out, or the hand unchanged where it holds none.

ソースを見るGitHub で編集@johnmorrisdotca/toranpu 2.15.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。