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

Card designs

import { … } from "@johnmorrisdotca/toranpu/card-faces";

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

The faces of the cards, drawn as SVG in the same 100 by 140 box as the backs: plain (unless said), four colour, and the English pattern with its drawn kings, queens and jacks, which is its own entry point because of its size. Jokers too (RJ, BJ), for a table of your own.

import { cardFaceSvg, cardFaceUrl, loadCardDesign } from "@johnmorrisdotca/toranpu/card-faces";

element.innerHTML = cardFaceSvg("QS");
image.src = cardFaceUrl("TD", { design: "four-colour" });
const english = await loadCardDesign("english");
element.innerHTML = cardFaceSvg("KS", { design: english });

Your own faces: register a design, with art for the standard cards, for cards no deck has (a territory card, a card a game invents), or both, and ask for it by its name on any card, hand, pile or table.

import { registerCardDesign, cardFaceSvg } from "@johnmorrisdotca/toranpu/card-faces";

registerCardDesign({
  name: "frontier",
  box: [100, 140],
  art: {},
  draw: (card) => (card.startsWith("land-") ? `<text x="50" y="76" text-anchor="middle" font-size="12">${card.slice(5)}</text>` : null),
  label: (card) => `Territory ${card.slice(5)}`,
});
element.innerHTML = cardFaceSvg("land-ridge", { design: "frontier" });

Exports

NameKindWhat it is
CARD_DESIGNSconstantThe designs drawn here, by name.
CARD_FACE_COLOURSconstantThe faces' own colours.
CARD_FACE_PROPERTIESconstantThe CSS custom properties a plain or four-colour face drawn into a page takes its colours from.
CardDesigntypeA set of drawn cards: its name, the box each card is drawn in, and each card's drawing (what goes inside an <svg> of that box) by its id, KS for the king of spades and RJ and BJ for the red and black jokers.
CardDesignNametypeA design's name.
cardFaceFromArtfunctionA card's face from artwork of your own: art is SVG markup (or a whole <svg> document) drawn on the card's paper in a box 100 by 140, or in box, fitted to the card's height and centred; a whole <svg> is used as it is.
CardFaceOptionstypeHow a face is drawn.
cardFaceSvgfunctionA card's face as a whole SVG document, 100 by 140: QS, TD, a joker (RJ, BJ), a rules card (R1, R2) or the blank (BL).
cardFaceUrlfunctionA card's face as a data URL, for an <img src>, a CSS background or a canvas.
cleanMarkupfunctionSVG markup with what could run or fetch taken out: scripts, foreignObject, frames, animation elements and styles, every on… handler, and any href that is not a picture or a #fragment of the drawing itself.
CUSTOM_CARD_IDconstantWhat a card's id may be, when a design of the page draws it: letters and digits, with -, _, . and : inside, up to 40.
EXTRA_CARDSconstantTHE EXTRAS OF A REAL DECK, which no game here deals but a hand on a page may hold, as a wild card or for the look of it: the two jokers, the two rules cards a pack is sold with (R1, the rules of Hearts; R2, of Spades), and a blank (BL).
EXTRA_LIMITSconstantThe most of each kind of extra one hand holds: four jokers, as some packs have; two rules cards; two blanks.
faceNamefunctionA face's name in words: "queen of spades", "red joker"; in Japanese "スペードのクイーン", "赤のジョーカー".
isCardFacefunctionWhether a text is a card a face can be drawn for: QS, TD, a joker (RJ, BJ), a rules card (R1, R2) or the blank (BL).
JOKERSconstantThe two jokers' ids: the red joker and the black.
loadCardDesignfunctionA design by its name, loaded when it is first asked for: "english" fetches the English pattern (about 700 kB, 200 kB compressed) only then.
pipPlacesfunctionThe middles of a number card's pips, in the 100 by 140 box, and whether each is drawn upside down.
registerCardDesignfunctionKeep a design by its name, in place of any earlier one of that name.
registeredCardDesignsfunctionThe names of the designs registered now, in the order they were.
safeImageUrlfunctionA picture's address, or null when it is anything else.
unregisterCardDesignfunctionForget a registered design.

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