# @fourhao/playing-cards

A standalone, framework-free ESM library for a 52-card deck, with `standard`
and `jumbo` faces. Version 1.1.0. All rank/suit marks are SVG paths; court
illustrations are local SVG files. No engine, game routes, remote font,
framework, server or network API is required by the library.

## Use

```js
import {
  createCardFace, readCardStyle, saveCardStyle,
  CARD_STYLE_STORAGE_KEY, DEFAULT_CARD_STYLE, normalizeCardStyle,
} from '@fourhao/playing-cards';
import '@fourhao/playing-cards/styles.css';

const face = createCardFace(document,
  { rank: 12, suit: 'hearts' },
  { style: readCardStyle() });
cardElement.append(face);
cardElement.setAttribute('aria-label', 'Queen of hearts');
```

For an unbundled browser, import the same exports from `./index.js` and link
`./styles.css`. Keep `rank-art.js`, `suits.js` and `styles/` beside the module.
`courtArtSource(card, {style})` is also exported from the package root and
`./court-art.js`; it returns null for non-court or invalid cards. Offline
exporters may bundle this single resolver into data URLs without modifying
rendering code. Court URLs resolve against `import.meta.url`, so the whole directory can move
to another host or path. A local HTTP server works without Internet access;
normal browser ES-module restrictions may prevent a `file://` gallery.

The caller supplies an explicit DOM `document`, integer `rank` 1–13 (A–K)
and a `suit`: `clubs`, `diamonds`, `hearts` or `spades`. Engine-specific card
numbers are not accepted. Invalid rank/suit/document throws `TypeError`.
Options default to `{style: 'jumbo'}`; unknown styles normalize to `jumbo`.

The returned `svg.card-face` has `data-card-style` and `data-card-suit`, a
`0 0 100 140` viewBox, and `aria-hidden="true"`. The caller provides paper,
border, 5:7 aspect ratio, an accessible card label and all interaction. Do not
stretch the containing card to another aspect ratio. Black/red ink defaults
are in the stylesheet and can be changed with `--playing-cards-black` and
`--playing-cards-red`, or overridden on the SVG itself. Internal rank and pip
paths use `currentColor`.

### Styles

- `jumbo`: large rank and suit in one horizontal header, one central suit on
  A–10, and enlarged upright court busts. Paths, rank outlines and portrait
  geometry retain the published Fourhao `54e007a05495a44e7ca07c1c9281cf59a988fa8e`
  design. Version 1.1 reduces each number/suit footprint uniformly by 10%
  around its original centre, adding space on large full-screen tables while
  keeping the exact same proportions at every zoom and display size. The
  twelve jumbo court files and `rank-art.js` are byte-identical to that release.
- `standard`: traditional top-left and inverted bottom-right corners,
  counted suit pips on A–10, and complete double-ended court illustrations.
  These twelve assets come independently from the earlier `00302dcec6c1965db5440199556fd8def4a6061a`
  deck; only their single blue rectangular frame was removed. They do not
  reuse the cropped jumbo busts. Standard shares the same outlined ranks and
  suit geometry, printed at traditional sizes.

`g.card-strip` exists only in standard and is hidden by the supplied CSS. A
stacking game can hide the full `card-corner`, `pips` and `face-art` groups on
covered cards and show this horizontal index instead. Jumbo uses its same
`card-header` on both complete and covered cards. The package installs no
stacking selectors, drag behaviour or global listeners.

### Shared style preference

`CARD_STYLE_STORAGE_KEY` is `4hao.materials.playing-cards.style.v1` and
`DEFAULT_CARD_STYLE` is `jumbo`. This key is intended to be shared by games
on the same origin; cross-origin browsers do not share localStorage.

- `normalizeCardStyle(value)` returns `standard` only for that exact value;
  all other values return `jumbo`.
- `readCardStyle(storage?)` reads without writing. It defaults to the current
  `globalThis.localStorage`, safely resolved inside the function. Missing
  storage, a throwing getter or a failing `getItem` returns the default.
- `saveCardStyle(style, storage?)` attempts to store the normalized value and
  returns that value even when storage is unavailable or quota/security
  errors occur. The caller can still apply the chosen face for this session.

The same five preference exports are also available from `./prefs.js` (or
`@fourhao/playing-cards/prefs.js`) without importing the SVG renderer.

Pass `null` to use no persistence, or inject an object with `getItem`/`setItem`
for another storage implementation. No storage event listener is installed;
each consuming game decides when to rerender, and may listen for the shared
key on its own.

## Preview and packaging

Open the explicit file URL `/materials/playing-cards/index.html` through a
local static HTTP server to see all 104 faces and change their displayed size.
The catalog is `/materials/index.html`. Use these file URLs even on servers
that disable directory index resolution; all internal catalog links do so.

```sh
cd path/to/playing-cards
npm pack
# Produces fourhao-playing-cards-1.1.0.tgz without installing dependencies.
```

`package.json` whitelists the modules, style, manifest, 24 court illustrations,
complete licenses, README and preview files. There are no install scripts or
dependencies. `manifest.json` records the distributed source files and their
byte/hash identity. The package can be consumed independently of Fourhao.

## Sources and complete licenses

The library, preference helpers, gallery and Fourhao suit silhouettes remain
Fourhao-owned. This private package supports reuse in projects authorized by
the project owner; it is not a public open-source or npm publication grant.
See [LICENSE](./LICENSE). `private: true` still permits local `npm pack` and
installation of its tarball. Third-party material retains its own license
and those upstream grants are not restricted by the project reuse notice:

| Component | Source | License | Adaptation |
| --- | --- | --- | --- |
| Traditional court figures | [Adrian Kennard (RevK)](https://www.me.uk/cards/), [generated SVG deck](https://www.me.uk/cards/makeadeck.cgi?view) | [CC0 1.0 full legal code](./licenses/CC0-1.0.txt) | Standard removes only the centre blue frame; jumbo keeps the published individual transparent bust silhouettes and framing. |
| Thirteen outlined rank marks | [Liberation Sans Bold 2.1.4](https://github.com/liberationfonts/liberation-fonts), outlined by Fourhao | [OFL 1.1 full text](./licenses/OFL-1.1.txt), also embedded in `rank-art.js` | Vector outlines only, named Fourhao jumbo rank artwork; no font binary is distributed or requested. |

Court author/source metadata is retained in all 24 files. The author states
the designs are based on 19th-century Goodall & Son courts and dedicates them
under CC0. Original deck retrieved 2026-11-02; original generated response
SHA256: `500591aee1fff6e2641de9d11298bc6892d3c4896e09dc2b8de79be382c2f922`.
Author license page rechecked 2026-11-03. The CC0 legal text is reproduced from
`https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt`.

Rank copyright: digitized data © 2010 Google Corporation (reserved names
Arimo, Tinos and Cousine), © 2012 Red Hat, Inc. (reserved name Liberation).
OFL notices are retained in full. Fourhao's new symmetric suit outlines use
no screenshot pixels. No Microsoft artwork, proprietary audio, game engine,
member data or network service is included.

## Reusable delivery files

From the Fourhao source repository root, run:

```sh
node code/scripts/package-playing-cards.mjs
```

The local packager writes into `.private/materials/playing-cards/1.1.0/`,
using the source package version for the output directory.
It creates an installable `.tgz` library package and a `.zip` containing
52 independent SVG cards per style, 104 cards in total, with the complete
licenses and a byte/hash index. Every SVG embeds its court illustration as
vector data and needs no font, CSS file or remote image. The two distributions
are generated from this one source package. There is no registry publication.

In another JavaScript project, install the generated local tarball:

```sh
npm install /path/to/fourhao-playing-cards-1.1.0.tgz
```

A non-JavaScript project can use the independent SVG files instead. Preserve
the accompanying ownership, source and third-party license information.
The browser preview is `materials/playing-cards/index.html`; use the explicit
HTML filename when serving with directory indexes disabled.
