@johnmorrisdotca/fuda-cards 0.2.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -5
- package/dist/element.d.ts +28 -0
- package/dist/element.js +131 -10
- package/dist/index.d.ts +28 -1
- package/dist/index.js +3 -0
- package/dist/materials.d.ts +33 -0
- package/dist/materials.js +48 -0
- package/dist/stack.d.ts +30 -0
- package/dist/stack.js +39 -0
- package/dist/wear.d.ts +104 -0
- package/dist/wear.js +268 -0
- package/docs/materials.md +54 -0
- package/docs/wear.md +66 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Fuda Cards
|
|
2
2
|
|
|
3
|
-
Reusable collectible card frames for caller-provided images and interactive 3D viewers. The core is a standards-based web component, suitable for plain HTML, Angular, React, Vue, Svelte, and other frameworks that support custom elements. No framework or 3D engine is required by the component. `<fuda-card>` imports
|
|
3
|
+
Reusable collectible card frames for caller-provided images and interactive 3D viewers. The core is a standards-based web component, suitable for plain HTML, Angular, React, Vue, Svelte, and other frameworks that support custom elements. No framework or 3D engine is required by the component. `<fuda-card>` imports only its own small modules (the materials and the stack layout); `<fuda-collection>` uses [`@johnmorrisdotca/kazoku-ui`](https://github.com/johnmorrisdotca/kazoku-ui) for its zoom controls (see Collection viewer).
|
|
4
4
|
|
|
5
5
|
This is an early prototype: classic, sport and cosmic are exploratory CSS designs, not yet historically researched recreations or photorealistic materials. The demo uses a still from Uchusen Rockets; see [assets/README.md](assets/README.md) for its model credit.
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ This is an early prototype: classic, sport and cosmic are exploratory CSS design
|
|
|
10
10
|
|
|
11
11
|
## Development
|
|
12
12
|
|
|
13
|
-
Requires Node 22+ and pnpm. Run `pnpm install`, `pnpm check`, then `pnpm dev` and open http://localhost:
|
|
13
|
+
Requires Node 22+ and pnpm. Run `pnpm install`, `pnpm check`, then `pnpm dev` and open http://localhost:8100. `pnpm build` emits JavaScript and TypeScript declarations to `dist/`.
|
|
14
14
|
|
|
15
15
|
## Embed
|
|
16
16
|
|
|
@@ -24,7 +24,7 @@ Requires Node 22+ and pnpm. Run `pnpm install`, `pnpm check`, then `pnpm dev` an
|
|
|
24
24
|
|
|
25
25
|
In a bundler, import `@johnmorrisdotca/fuda-cards/element` once before rendering `<fuda-card>`. Frameworks may require custom-element configuration (for example, Angular's `CUSTOM_ELEMENTS_SCHEMA`). Framework-specific wrappers have not yet been implemented; see [framework integration examples](docs/framework-integration.md). For published releases, install with `npm install @johnmorrisdotca/fuda-cards`.
|
|
26
26
|
|
|
27
|
-
The default slot accepts HTML, including an existing interactive 3D viewer; its owner handles rotation, zoom and model loading. The card has no drag-to-flip handler, leaving pointer interaction to that viewer. Control the card's reverse independently by adding or removing the `flipped` attribute. The demo provides a flip button. Attributes: `title`, `category`, `subtitle`, `description`, `number`, `rarity`, `variant` (`classic`, `sport`, `cosmic`), `finish` (`foil`, `matte`), `thickness` (millimetres, default `0.3`) and `flipped` (boolean). Set the element width to scale it. The main package entry exports the TypeScript options and available variants and finishes without registering the custom element.
|
|
27
|
+
The default slot accepts HTML, including an existing interactive 3D viewer; its owner handles rotation, zoom and model loading. The card has no drag-to-flip handler, leaving pointer interaction to that viewer. Control the card's reverse independently by adding or removing the `flipped` attribute. The demo provides a flip button. Attributes: `title`, `category`, `subtitle`, `description`, `number`, `rarity`, `variant` (`classic`, `sport`, `cosmic`), `finish` (`foil`, `matte`), `thickness` (millimetres, default `0.3`), `material`, `stack`, `wear` and `flipped` (boolean). Set the element width to scale it. The main package entry exports the TypeScript options and available variants and finishes without registering the custom element.
|
|
28
28
|
|
|
29
29
|
3D integrations, framework-specific examples, polished front and back designs, accessibility validation, and photorealistic finishes remain future work.
|
|
30
30
|
|
|
@@ -44,12 +44,34 @@ It keeps `<fuda-card>` (300 px wide, 2.5:3.5, or whatever width your own rule gi
|
|
|
44
44
|
|
|
45
45
|
A card turned past 90° shows its back (the navy FUDA face), never the mirrored front, and the front's Animate button cannot be seen or clicked from behind. The back is the card's own face and is shown for `flipped` too.
|
|
46
46
|
|
|
47
|
-
The card has thickness, drawn to scale at the 63 mm wide card size: set `thickness` in millimetres (default `0.3`,
|
|
47
|
+
The card has thickness, drawn to scale at the 63 mm wide card size: set `thickness` in millimetres (default `0.3`, about 12 pt stock; `0` for a flat card; or pick a `material`, below). The edge is drawn from thin planes between the two faces, so it shows edge-on and at any angle, and it scales with the element's width (a 300px card is about 1.4px thick at the default). It is gold foil for the classic gold frame and card-stock cream for the sport and cosmic variants; override it with the `--fuda-edge` CSS custom property (any CSS background). The drop shadow is on the element itself, so a `filter` must not be added to anything between the card and its faces.
|
|
48
48
|
|
|
49
49
|
```html
|
|
50
50
|
<fuda-card title="Relic" thickness="1.5"></fuda-card>
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
### Materials and stacks
|
|
54
|
+
|
|
55
|
+
`material="<id>"` gives a card the thickness and edge colour of a material, each thickness read from a maker or a standard and cited: card stock at 11, 13 and 16 pt, a plastic bank-size card (0.76 mm), thick trading cards from 35 to 180 pt, a 175 pt booklet card, anodised aluminium (0.8 mm) and stainless steel (0.5 mm). `thickness` still overrides it. [docs/materials.md](docs/materials.md) lists every material, its thickness, its source and what the source says, and what was left out because it could not be sourced (a patch or relic card, for one).
|
|
56
|
+
|
|
57
|
+
`stack="52"` draws that many cards as a stack whose height is the count times a card's thickness (52 cards of the black-core playing-card stock are 16.9 mm; 60 thick 130 pt cards are 198 mm). The count is free, 1 to 1000; the Card Studio has presets with a source (52 playing cards, 52 and two jokers, a 60-card Pokémon deck, a booster pack of 10). Turn the card to see the stack's edge, with a line for each card in the material's colour.
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<fuda-card title="Deck" material="paper-310-black-core" stack="52" stack-messiness="0.3" stack-seed="7"></fuda-card>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The top card is the live card. The block under it is one piece, and with `stack-messiness` above 0 (0 neat to 1 very messy, default 0.3) the `stack-depth` cards under the top one (default 10, at most 52) are drawn as flat stills, nudged and turned from `stack-seed`: the same seed gives the same stack, and a card put on top moves none of those under it. A stack is one 3D scene whatever its count, and it draws nothing while it is at rest: a test checks that a 52-card stack requests no frames at rest. The idea of a pile from neat to messy and its parameters come from [toranpu](https://github.com/johnmorrisdotca/toranpu)'s `<toranpu-pile>`. In script, `card.stackCount` and `card.stackHeight` (mm) are read-only, and the package exports `cardMaterials`, `stackPresets`, `stackHeightMm` and `stackLayout`.
|
|
64
|
+
|
|
65
|
+
### Wear: cards that are not perfect
|
|
66
|
+
|
|
67
|
+
`wear="lightly-played"` draws the card after use: corners that are soft, rounded, chipped or folded (a dog-ear), whitening on the edges, creases, scratches, specks, staining, yellowing and a print that sits off centre. The presets are the plain grading terms: `mint`, `near-mint`, `lightly-played`, `moderately-played`, `heavily-played` and `damaged`; `perfect`, no attribute at all, or an unknown name draws nothing. `wear-seed` fixes where the marks lie, so a card looks the same every time it is drawn. `wear-corners`, `wear-edges`, `wear-surface` and `wear-creases` (0 to 1) change one kind on its own, and `wear="0.5"` sets them all at once.
|
|
68
|
+
|
|
69
|
+
```html
|
|
70
|
+
<fuda-card title="Rookie" wear="moderately-played" wear-seed="7"></fuda-card>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
A perfect card is byte for byte what it was: the wear code is a separate module that `<fuda-card>` loads only when a card asks for wear. [docs/wear.md](docs/wear.md) has the sources for the grading words, the presets with their levels, how each mark is drawn and what is not drawn. The package exports `wearPresets`, `wearLayout`, `wearLevels`, `wearOutline` and `wearOverlaySvg` as plain data.
|
|
74
|
+
|
|
53
75
|
### Whole-card rotation
|
|
54
76
|
|
|
55
77
|
Set `card-spin="center"` for a slow 3D turn around the card’s vertical center, or `card-spin="corner"` for a 3D spin like an ice skater: the card keeps its full size and turns a full 360° around the vertical axis through its bottom-left corner, which stays still at the middle of the element, and shows its back half way round. The card sweeps out to both sides of that point, so give it room (a stage about three times its width and twice its height). Both rotate the entire card, including either face and its content. The default is one turn every 180 seconds; set `--fuda-card-spin-duration` to a positive CSS duration such as `30s`. Set `card-spin-direction="reverse"` to reverse the rotation. Add `card-spin-paused` to pause at the current angle, and remove it to resume. Remove `card-spin` to stop and reset the rotation. These attributes are independent of the artwork `motion` and `playing` attributes and the card’s `flipped` state. Reduced-motion preferences disable the rotation and the flip transition.
|
|
@@ -66,7 +88,7 @@ To review, run `pnpm install` and `pnpm dev`, then open the Card Studio. Under *
|
|
|
66
88
|
|
|
67
89
|
### Moving artwork
|
|
68
90
|
|
|
69
|
-
Set `motion="pan"` on a card containing a slotted `<img>` to enable
|
|
91
|
+
Set `motion="pan"` on a card containing a slotted `<img>` to enable the Animate button on a tall image. The button is a small play or pause mark in the corner of the art, drawn at half strength until you point at it or focus it; its hit target is 48 px square, its accessible name is "Animate the picture" and `aria-pressed` says whether the art is moving. By default the card starts on a still, cropped view; add the boolean `playing` attribute to start with motion. Tapping the button starts the pan, and tapping it again returns to the still. A host can add or remove `playing` to control the state. While the art moves the card also carries a `moving` attribute for styling (read-only: set `playing` or `autoplay` instead). Set `--fuda-focus-x` and `--fuda-focus-y` (for example `50%` and `20%`) to choose the focal point. Cards without the pan option show a still, fully visible image. `pan-direction="up"` starts at the bottom; the default is down. The image travels back and forth by default; set `pan-loop="restart"` to repeat in one direction. Set the CSS custom property `--fuda-pan-duration` (for example, `16s`) to control the duration of each pass. If the image is not taller than the window after filling its width, there may be no vertical distance to pan. Reduced-motion preferences disable the animation and preserve the focused still. This option applies to images; moving a 3D camera is a separate future integration owned by the viewer.
|
|
70
92
|
|
|
71
93
|
```html
|
|
72
94
|
<fuda-card title="Starship" motion="pan" pan-direction="down" style="--fuda-pan-duration: 16s">
|
|
@@ -74,6 +96,14 @@ Set `motion="pan"` on a card containing a slotted `<img>` to enable an Animate b
|
|
|
74
96
|
</fuda-card>
|
|
75
97
|
```
|
|
76
98
|
|
|
99
|
+
**Autoplay when the card is in focus.** Add `autoplay="focus"` and the card moves its art by itself while it is the card in focus, with no tap on the button. One card is in focus at a time: the card under the mouse, the card that holds keyboard focus (Tab to its button), or, on a touch screen, the card you last tapped. When focus moves to another card, or the pointer leaves, or you tap or click somewhere else, the first card returns to its still, so in a row or a grid only one card ever moves. The button stays: press it to pause the focused card (it starts again the next time the card takes focus), and on a touch screen the first tap on it starts the card. `autoplay="focus"` never starts with `prefers-reduced-motion: reduce`. It does not set `playing`, so a host that sets `playing` still decides for itself. The Card Studio has an **Autoplay** choice.
|
|
100
|
+
|
|
101
|
+
```html
|
|
102
|
+
<fuda-card title="Starship" motion="pan" autoplay="focus">
|
|
103
|
+
<img src="starship.jpg" alt="Starship">
|
|
104
|
+
</fuda-card>
|
|
105
|
+
```
|
|
106
|
+
|
|
77
107
|
Planned JSON, API, scanned-card and interactive-content inputs are outlined in [docs/collection-input.md](docs/collection-input.md).
|
|
78
108
|
|
|
79
109
|
## Pokémon binder demo
|
package/dist/element.d.ts
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
export declare class FudaCard extends HTMLElement {
|
|
2
2
|
static observedAttributes: string[];
|
|
3
|
+
private focused;
|
|
4
|
+
private hushed;
|
|
5
|
+
private focusedAtPress?;
|
|
3
6
|
constructor();
|
|
7
|
+
/** With `autoplay="focus"` the card in focus animates its art; leaving it (pointer, keyboard or a tap elsewhere) stops it. */
|
|
8
|
+
private watchFocus;
|
|
9
|
+
/** Put this card in focus (or out of it); the card that had focus is put out, so only one is ever in focus. */
|
|
10
|
+
setFocused(on: boolean): void;
|
|
11
|
+
/** True while the art moves: `playing` is set, or the card is in focus with `autoplay="focus"` and the person has not paused it. Never autoplays with reduced motion. */
|
|
12
|
+
get isMoving(): boolean;
|
|
13
|
+
private toggleMotion;
|
|
4
14
|
/** The art stays invisible until the card has a size on screen and every slotted image has loaded, so it never shows outside the frame. */
|
|
5
15
|
private watchArt;
|
|
6
16
|
connectedCallback(): void;
|
|
17
|
+
disconnectedCallback(): void;
|
|
7
18
|
attributeChangedCallback(name: string): void;
|
|
19
|
+
/** Millimetres thick: the `thickness` attribute, else the `material`'s, else 0.3. */
|
|
20
|
+
get cardThicknessMm(): number;
|
|
21
|
+
/** How many cards the stack holds: the `stack` attribute as a whole number from 1 (one card) to 1000. */
|
|
22
|
+
get stackCount(): number;
|
|
23
|
+
/** Height of the stack in millimetres: the count times a card's thickness. */
|
|
24
|
+
get stackHeight(): number;
|
|
25
|
+
private wearKey;
|
|
26
|
+
private wearToken;
|
|
27
|
+
private wearModule?;
|
|
28
|
+
/** Wear (an imperfect card) is drawn by a module that is loaded only when a card asks for it; a perfect card never loads it. */
|
|
29
|
+
private applyWear;
|
|
30
|
+
/** The wear the card is drawn with: a preset's id, a number, or an empty string when it is perfect. */
|
|
31
|
+
get wear(): string;
|
|
32
|
+
set wear(value: string);
|
|
33
|
+
private stillsKey;
|
|
34
|
+
/** The cards under the top one that are laid out nudged and turned; the rest of the stack is one block with a line for each card on its edge. */
|
|
35
|
+
private drawStills;
|
|
8
36
|
render(): void;
|
|
9
37
|
}
|
package/dist/element.js
CHANGED
|
@@ -1,11 +1,78 @@
|
|
|
1
|
+
import { cardMaterial, stackHeightMm } from './materials.js';
|
|
2
|
+
import { stackLayout } from './stack.js';
|
|
1
3
|
const template = document.createElement('template');
|
|
2
4
|
template.innerHTML = `<style>
|
|
3
|
-
:host{display:inline-block;width:300px;aspect-ratio:2.5/3.5;perspective:var(--fuda-perspective,1000px);container-type:inline-size;filter:drop-shadow(0 12px 14px #0006);--edge:linear-gradient(90deg,#f6dc8c,#b98631 50%,#f6dc8c);font-family:Georgia,serif;color:#27201b}*{box-sizing:border-box}.rotation{height:100%;transform-style:preserve-3d;transform-origin:center center}:host([card-spin="center"]) .rotation{animation:fuda-turn var(--fuda-card-spin-duration, 180s) linear infinite}:host([card-spin="corner"]) .rotation{transform-origin:0 100%;transform:translate(50%,-50%);animation:fuda-corner-turn var(--fuda-card-spin-duration, 180s) linear infinite}:host([card-spin-direction="reverse"]) .rotation{animation-direction:reverse}:host([card-spin-paused]) .rotation{animation-play-state:paused}@keyframes fuda-turn{to{transform:rotateY(360deg)}}@keyframes fuda-corner-turn{from{transform:translate(50%,-50%) rotateY(0)}to{transform:translate(50%,-50%) rotateY(360deg)}}:host([card-view]) .rotation{animation:none;transform:rotateX(var(--fuda-tilt,0deg)) rotateY(var(--fuda-yaw,0deg))}:host([card-view][card-spin="corner"]) .rotation{transform:translate(50%,-50%) rotateX(var(--fuda-tilt,0deg)) rotateY(var(--fuda-yaw,0deg))}@media (prefers-reduced-motion:reduce){:host([card-spin]) .rotation{animation:none}:host .card{transition:none}.art ::slotted(*){transition:none}}.card{--t:calc(var(--mm,.3) * 100cqw / 63);height:100%;position:relative;transform-style:preserve-3d;transition:transform .65s}:host([flipped]) .card{transform:rotateY(180deg)}.face{position:absolute;inset:0;border-radius:15px;backface-visibility:hidden;overflow:hidden}.front{transform:translateZ(calc(var(--t) / 2));padding:13px;background:linear-gradient(135deg,#fbdf87,#ab742c 35%,#ffe9a6 58%,#ae792d);border:2px solid #9c702d}.inner{height:100%;padding:12px;background:linear-gradient(150deg,#f9edc8,#d6b477);border:2px solid #76512a;display:flex;flex-direction:column;gap:8px}.heading,.footer{display:flex;justify-content:space-between;align-items:center;gap:5px}.heading{font-weight:bold;font-size:20px}.badge{font:700 10px sans-serif;letter-spacing:.12em}.art{position:relative;height:53%;border:5px ridge #dcc18a;box-shadow:0 2px 5px #47301488;background:radial-gradient(circle at 50% 35%,#7496a1,#273c4c);overflow:hidden}.art ::slotted(*){width:100%;height:100%;object-fit:contain;display:block;opacity:0;transition:opacity .35s ease}.art.ready ::slotted(*){opacity:1}:host([motion="pan"]) .art ::slotted(img){object-fit:cover;object-position:var(--fuda-focus-x, 50%) var(--fuda-focus-y, 25%)}:host([motion="pan"][
|
|
4
|
-
</style><div class="rotation"><div class="card"><div class="face front"><div class="inner"><div class="heading"><span id="title"></span><span class="badge" id="category"></span></div><div class="art"><slot></slot><button class="motion-button" type="button" aria-pressed="false" hidden
|
|
5
|
+
:host{display:inline-block;width:300px;aspect-ratio:2.5/3.5;perspective:var(--fuda-perspective,1000px);container-type:inline-size;filter:drop-shadow(0 12px 14px #0006);--edge:linear-gradient(90deg,#f6dc8c,#b98631 50%,#f6dc8c);font-family:Georgia,serif;color:#27201b}*{box-sizing:border-box}.rotation{height:100%;transform-style:preserve-3d;transform-origin:center center}:host([card-spin="center"]) .rotation{animation:fuda-turn var(--fuda-card-spin-duration, 180s) linear infinite}:host([card-spin="corner"]) .rotation{transform-origin:0 100%;transform:translate(50%,-50%);animation:fuda-corner-turn var(--fuda-card-spin-duration, 180s) linear infinite}:host([card-spin-direction="reverse"]) .rotation{animation-direction:reverse}:host([card-spin-paused]) .rotation{animation-play-state:paused}@keyframes fuda-turn{to{transform:rotateY(360deg)}}@keyframes fuda-corner-turn{from{transform:translate(50%,-50%) rotateY(0)}to{transform:translate(50%,-50%) rotateY(360deg)}}:host([card-view]) .rotation{animation:none;transform:rotateX(var(--fuda-tilt,0deg)) rotateY(var(--fuda-yaw,0deg))}:host([card-view][card-spin="corner"]) .rotation{transform:translate(50%,-50%) rotateX(var(--fuda-tilt,0deg)) rotateY(var(--fuda-yaw,0deg))}@media (prefers-reduced-motion:reduce){:host([card-spin]) .rotation{animation:none}:host .card{transition:none}.art ::slotted(*){transition:none}}.card{--t:calc(var(--mm,.3) * 100cqw / 63);--pitch:calc(var(--mm1,var(--mm,.3)) * 100cqw / 63);height:100%;position:relative;transform-style:preserve-3d;transition:transform .65s}:host([flipped]) .card{transform:rotateY(180deg)}.face{position:absolute;inset:0;border-radius:15px;backface-visibility:hidden;overflow:hidden}.front{transform:translateZ(calc(var(--t) / 2));padding:13px;background:linear-gradient(135deg,#fbdf87,#ab742c 35%,#ffe9a6 58%,#ae792d);border:2px solid #9c702d}.inner{height:100%;padding:12px;background:linear-gradient(150deg,#f9edc8,#d6b477);border:2px solid #76512a;display:flex;flex-direction:column;gap:8px}.heading,.footer{display:flex;justify-content:space-between;align-items:center;gap:5px}.heading{font-weight:bold;font-size:20px}.badge{font:700 10px sans-serif;letter-spacing:.12em}.art{position:relative;height:53%;border:5px ridge #dcc18a;box-shadow:0 2px 5px #47301488;background:radial-gradient(circle at 50% 35%,#7496a1,#273c4c);overflow:hidden}.art ::slotted(*){width:100%;height:100%;object-fit:contain;display:block;opacity:0;transition:opacity .35s ease}.art.ready ::slotted(*){opacity:1}:host([motion="pan"]) .art ::slotted(img){object-fit:cover;object-position:var(--fuda-focus-x, 50%) var(--fuda-focus-y, 25%)}:host([motion="pan"][moving]) .art ::slotted(img){animation:fuda-pan var(--fuda-pan-duration, 12s) ease-in-out infinite alternate}:host([motion="pan"][pan-loop="restart"]) .art ::slotted(img){animation-direction:normal}:host([motion="pan"][pan-direction="up"]) .art ::slotted(img){animation-direction:alternate-reverse}:host([motion="pan"][pan-direction="up"][pan-loop="restart"]) .art ::slotted(img){animation-direction:reverse}@keyframes fuda-pan{from{object-position:50% 0%}to{object-position:50% 100%}}@media (prefers-reduced-motion:reduce){:host([motion="pan"][moving]) .art ::slotted(img){animation:none}.motion-button{transition:none}}.motion-button{position:absolute;right:0;bottom:0;z-index:1;width:48px;height:48px;padding:0;border:0;background:none;display:grid;place-items:center;cursor:pointer;opacity:.55;transition:opacity .2s;-webkit-tap-highlight-color:transparent}.motion-button:hover,.motion-button:focus-visible,.motion-button[aria-pressed=true]{opacity:1}.motion-button:focus-visible{outline:none}.motion-button:focus-visible .glyph{outline:3px solid white;outline-offset:2px}.glyph{width:26px;height:26px;border-radius:50%;display:grid;place-items:center;background:#101827b3;border:1px solid #fff5;color:white}.glyph svg{width:11px;height:11px;fill:currentColor}.motion-button[aria-pressed=true] .play,.motion-button[aria-pressed=false] .pause{display:none}.motion-button[hidden]{display:none}.subtitle{text-align:center;font:italic 11px Georgia}.description{border-top:1px solid #9d8054;padding-top:9px;font-size:13px;line-height:1.35;flex:1}.footer{border-top:1px solid #9d8054;padding-top:5px;font:700 9px sans-serif;letter-spacing:.08em}.back{transform:rotateY(180deg) translateZ(calc(var(--t) / 2));background:radial-gradient(ellipse at center,#b78745 0 12%,#152d46 13% 27%,#386988 28% 31%,#10233b 32% 62%,#d2b074 63% 66%,#182c45 67%);border:11px solid #b39158;display:grid;place-items:center;color:#f7e9bf}.emblem{width:125px;height:125px;border:2px solid #edd18c;border-radius:50%;display:grid;place-items:center;background:#17334a;box-shadow:0 0 0 7px #967344,0 0 30px #e6c98288;font:bold 23px Georgia;letter-spacing:.12em}.shine{pointer-events:none;position:absolute;inset:0;opacity:.35;mix-blend-mode:screen;background:linear-gradient(125deg,transparent 25%,#fff9 36%,transparent 48%,#7cf6 56%,#f9a5 62%,transparent 70%)}:host([finish=matte]) .shine{display:none}.edge{position:absolute;background:var(--fuda-edge,var(--edge))}.stacked .edge{--dir:180deg;background:repeating-linear-gradient(var(--dir),transparent 0 calc(var(--pitch) * .7),#8886 calc(var(--pitch) * .7) var(--pitch)),var(--fuda-edge,var(--edge))}.stacked .edge.side{--dir:90deg}.stills{display:contents}.still{position:absolute;inset:0;border-radius:15px;border:2px solid #9c702d;pointer-events:none;background:linear-gradient(135deg,#fbdf87,#ab742c 35%,#ffe9a6 58%,#ae792d);transform:translate3d(calc(var(--x) * 100cqw),calc(var(--y) * 100cqw),calc(var(--t) / -2 + var(--pitch) * var(--k))) rotate(calc(var(--r) * 1deg))}:host([variant=sport]) .still{background:linear-gradient(135deg,#ebedef,#525e69,#fff,#47505d);border-color:#394c5b}:host([variant=cosmic]) .still{background:linear-gradient(130deg,#c9b4ff,#433b83,#dabdff,#503969);border-color:#584378}:host([variant=sport]),:host([variant=cosmic]){--edge:#ece4d2}:host([variant=sport]) .front{background:linear-gradient(135deg,#ebedef,#525e69,#fff,#47505d)}:host([variant=sport]) .inner{background:linear-gradient(145deg,#eef1ee,#aebac1);border-color:#394c5b}:host([variant=sport]) .art{border-color:#a9b9c0}:host([variant=cosmic]) .front{background:linear-gradient(130deg,#c9b4ff,#433b83,#dabdff,#503969)}:host([variant=cosmic]) .inner{background:linear-gradient(145deg,#e6dafa,#a997cd);border-color:#584378}
|
|
6
|
+
</style><div class="rotation"><div class="card"><div class="face front"><div class="inner"><div class="heading"><span id="title"></span><span class="badge" id="category"></span></div><div class="art"><slot></slot><button class="motion-button" type="button" aria-pressed="false" aria-label="Animate the picture" title="Animate" hidden><span class="glyph"><svg viewBox="0 0 12 12" aria-hidden="true"><path class="play" d="M3 1.5v9l7.5-4.5z"/><path class="pause" d="M2.5 1.5h2.8v9H2.5zM6.7 1.5h2.8v9H6.7z"/></svg></span></button></div><div class="subtitle" id="subtitle"></div><div class="description" id="description"></div><div class="footer"><span id="number"></span><span>✦ FUDA COLLECTION</span><span id="rarity"></span></div></div><div class="shine"></div></div><div class="face back"><div class="emblem">FUDA</div><div class="shine"></div></div><i class="edge" style="left:50%;top:0;width:calc(100% - 30px);height:var(--t);transform:translate(-50%,-50%) rotate(0deg) rotateX(90deg)"></i><i class="edge" style="left:50%;top:100%;width:calc(100% - 30px);height:var(--t);transform:translate(-50%,-50%) rotate(0deg) rotateX(90deg)"></i><i class="edge side" style="left:0;top:50%;width:var(--t);height:calc(100% - 30px);transform:translate(-50%,-50%) rotateY(90deg)"></i><i class="edge side" style="left:100%;top:50%;width:var(--t);height:calc(100% - 30px);transform:translate(-50%,-50%) rotateY(90deg)"></i><i class="edge" style="left:2.20px;top:9.70px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-67.5deg) rotateX(90deg)"></i><i class="edge" style="left:9.70px;top:2.20px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-22.5deg) rotateX(90deg)"></i><i class="edge" style="left:2.20px;top:calc(100% - 9.70px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(67.5deg) rotateX(90deg)"></i><i class="edge" style="left:9.70px;top:calc(100% - 2.20px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(22.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 2.20px);top:9.70px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(67.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 9.70px);top:2.20px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(22.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 2.20px);top:calc(100% - 9.70px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-67.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 9.70px);top:calc(100% - 2.20px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-22.5deg) rotateX(90deg)"></i><div class="stills"></div></div></div>`;
|
|
5
7
|
const defaults = { title: 'Untitled', category: 'COLLECTIBLE', subtitle: 'An item worth collecting', description: 'Add a description to tell its story.', number: 'NO. 001', rarity: '✦' };
|
|
8
|
+
/** The one card in focus: the card under the pointer, holding keyboard focus or last tapped. Only it may autoplay. */
|
|
9
|
+
let focusedCard = null;
|
|
10
|
+
const reducedMotion = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
11
|
+
document.addEventListener('pointerdown', event => { if (focusedCard && !event.composedPath().includes(focusedCard))
|
|
12
|
+
focusedCard.setFocused(false); }, true);
|
|
6
13
|
export class FudaCard extends HTMLElement {
|
|
7
|
-
static observedAttributes = ['title', 'category', 'subtitle', 'description', 'number', 'rarity', 'motion', 'playing', 'thickness'];
|
|
8
|
-
|
|
14
|
+
static observedAttributes = ['title', 'category', 'subtitle', 'description', 'number', 'rarity', 'motion', 'playing', 'thickness', 'autoplay', 'material', 'stack', 'stack-messiness', 'stack-seed', 'stack-depth', 'wear', 'wear-seed', 'wear-corners', 'wear-edges', 'wear-surface', 'wear-creases'];
|
|
15
|
+
focused = false;
|
|
16
|
+
hushed = false;
|
|
17
|
+
focusedAtPress;
|
|
18
|
+
constructor() { super(); const root = this.attachShadow({ mode: 'open' }); root.append(template.content.cloneNode(true)); const button = root.querySelector('button'); button?.addEventListener('click', () => this.toggleMotion()); this.watchArt(root); this.watchFocus(button); }
|
|
19
|
+
/** With `autoplay="focus"` the card in focus animates its art; leaving it (pointer, keyboard or a tap elsewhere) stops it. */
|
|
20
|
+
watchFocus(button) {
|
|
21
|
+
const auto = () => this.getAttribute('autoplay') === 'focus';
|
|
22
|
+
this.addEventListener('pointerenter', e => { if (auto() && e.pointerType !== 'touch')
|
|
23
|
+
this.setFocused(true); });
|
|
24
|
+
this.addEventListener('pointerleave', e => { if (e.pointerType !== 'touch' && !this.matches(':focus-within'))
|
|
25
|
+
this.setFocused(false); });
|
|
26
|
+
this.addEventListener('pointerdown', e => { if (!auto())
|
|
27
|
+
return; if (e.composedPath().includes(button))
|
|
28
|
+
this.focusedAtPress = this.focused;
|
|
29
|
+
else
|
|
30
|
+
this.setFocused(true); });
|
|
31
|
+
this.addEventListener('focusin', () => { if (auto())
|
|
32
|
+
this.setFocused(true); });
|
|
33
|
+
this.addEventListener('focusout', e => { if (!this.contains(e.relatedTarget) && !this.matches(':hover'))
|
|
34
|
+
this.setFocused(false); });
|
|
35
|
+
}
|
|
36
|
+
/** Put this card in focus (or out of it); the card that had focus is put out, so only one is ever in focus. */
|
|
37
|
+
setFocused(on) {
|
|
38
|
+
if (on && focusedCard && focusedCard !== this)
|
|
39
|
+
focusedCard.setFocused(false);
|
|
40
|
+
if (on)
|
|
41
|
+
focusedCard = this;
|
|
42
|
+
else if (focusedCard === this)
|
|
43
|
+
focusedCard = null;
|
|
44
|
+
if (this.focused === on)
|
|
45
|
+
return;
|
|
46
|
+
this.focused = on;
|
|
47
|
+
if (!on)
|
|
48
|
+
this.hushed = false;
|
|
49
|
+
this.render();
|
|
50
|
+
}
|
|
51
|
+
/** True while the art moves: `playing` is set, or the card is in focus with `autoplay="focus"` and the person has not paused it. Never autoplays with reduced motion. */
|
|
52
|
+
get isMoving() { return this.getAttribute('motion') === 'pan' && (this.hasAttribute('playing') || (this.getAttribute('autoplay') === 'focus' && this.focused && !this.hushed && !reducedMotion())); }
|
|
53
|
+
toggleMotion() {
|
|
54
|
+
const auto = this.getAttribute('autoplay') === 'focus';
|
|
55
|
+
const was = this.focusedAtPress ?? this.focused;
|
|
56
|
+
this.focusedAtPress = undefined;
|
|
57
|
+
if (auto && !was) {
|
|
58
|
+
this.hushed = false;
|
|
59
|
+
this.setFocused(true);
|
|
60
|
+
this.render();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const held = auto;
|
|
64
|
+
if (this.isMoving) {
|
|
65
|
+
this.removeAttribute('playing');
|
|
66
|
+
if (held)
|
|
67
|
+
this.hushed = true;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.hushed = false;
|
|
71
|
+
if (!held || reducedMotion())
|
|
72
|
+
this.setAttribute('playing', '');
|
|
73
|
+
}
|
|
74
|
+
this.render();
|
|
75
|
+
}
|
|
9
76
|
/** The art stays invisible until the card has a size on screen and every slotted image has loaded, so it never shows outside the frame. */
|
|
10
77
|
watchArt(root) {
|
|
11
78
|
const art = root.querySelector('.art'), slot = root.querySelector('slot');
|
|
@@ -19,16 +86,70 @@ export class FudaCard extends HTMLElement {
|
|
|
19
86
|
requestAnimationFrame(update);
|
|
20
87
|
}
|
|
21
88
|
connectedCallback() { this.render(); }
|
|
22
|
-
|
|
89
|
+
disconnectedCallback() { this.setFocused(false); }
|
|
90
|
+
attributeChangedCallback(name) { if (name === 'autoplay' && this.getAttribute('autoplay') !== 'focus')
|
|
91
|
+
this.setFocused(false); if (name === 'motion' && this.getAttribute('motion') !== 'pan' && this.hasAttribute('playing'))
|
|
23
92
|
this.removeAttribute('playing'); if (this.shadowRoot)
|
|
24
93
|
this.render(); }
|
|
25
|
-
|
|
26
|
-
|
|
94
|
+
/** Millimetres thick: the `thickness` attribute, else the `material`'s, else 0.3. */
|
|
95
|
+
get cardThicknessMm() { const asked = Number.parseFloat(this.getAttribute('thickness') ?? ''); return asked >= 0 ? asked : cardMaterial(this.getAttribute('material'))?.thicknessMm ?? 0.3; }
|
|
96
|
+
/** How many cards the stack holds: the `stack` attribute as a whole number from 1 (one card) to 1000. */
|
|
97
|
+
get stackCount() { const n = Math.floor(Number.parseFloat(this.getAttribute('stack') ?? '')); return n >= 1 ? Math.min(1000, n) : 1; }
|
|
98
|
+
/** Height of the stack in millimetres: the count times a card's thickness. */
|
|
99
|
+
get stackHeight() { return stackHeightMm(this.stackCount, this.cardThicknessMm); }
|
|
100
|
+
wearKey = '';
|
|
101
|
+
wearToken = 0;
|
|
102
|
+
wearModule;
|
|
103
|
+
/** Wear (an imperfect card) is drawn by a module that is loaded only when a card asks for it; a perfect card never loads it. */
|
|
104
|
+
applyWear() {
|
|
105
|
+
const num = (name) => { const v = this.getAttribute(name); return v === null || v.trim() === '' ? undefined : Number(v); };
|
|
106
|
+
const key = ['wear', 'wear-seed', 'wear-corners', 'wear-edges', 'wear-surface', 'wear-creases'].map(n => this.getAttribute(n) ?? '').join('|');
|
|
107
|
+
const w = this.getAttribute('wear') ?? '', asked = (w !== '' && w !== 'perfect' && w !== '0') || ['wear-corners', 'wear-edges', 'wear-surface', 'wear-creases'].some(n => this.hasAttribute(n));
|
|
108
|
+
if (key === this.wearKey || (!asked && !this.wearModule))
|
|
109
|
+
return;
|
|
110
|
+
this.wearKey = key;
|
|
111
|
+
const token = ++this.wearToken;
|
|
112
|
+
const draw = (m) => { if (token !== this.wearToken || !this.shadowRoot)
|
|
113
|
+
return; this.wearModule = m; m.applyWear(this.shadowRoot, { wear: this.getAttribute('wear'), seed: num('wear-seed'), corners: num('wear-corners'), edges: num('wear-edges'), surface: num('wear-surface'), creases: num('wear-creases') }); this.dispatchEvent(new CustomEvent('fuda-wear', { detail: { key } })); };
|
|
114
|
+
if (this.wearModule)
|
|
115
|
+
draw(this.wearModule);
|
|
116
|
+
else
|
|
117
|
+
void import('./wear.js').then(draw);
|
|
118
|
+
}
|
|
119
|
+
/** The wear the card is drawn with: a preset's id, a number, or an empty string when it is perfect. */
|
|
120
|
+
get wear() { return this.getAttribute('wear') ?? ''; }
|
|
121
|
+
set wear(value) { if (value)
|
|
122
|
+
this.setAttribute('wear', value);
|
|
27
123
|
else
|
|
28
|
-
|
|
124
|
+
this.removeAttribute('wear'); }
|
|
125
|
+
stillsKey = '';
|
|
126
|
+
/** The cards under the top one that are laid out nudged and turned; the rest of the stack is one block with a line for each card on its edge. */
|
|
127
|
+
drawStills(card, count) {
|
|
128
|
+
const num = (name, fallback) => { const n = Number.parseFloat(this.getAttribute(name) ?? ''); return Number.isFinite(n) ? n : fallback; };
|
|
129
|
+
const messiness = num('stack-messiness', 0.3), seed = num('stack-seed', 1), depth = Math.min(52, Math.max(0, Math.floor(num('stack-depth', 10))));
|
|
130
|
+
const places = count > 1 && messiness > 0 ? stackLayout(count, { messiness, seed, depth }) : [];
|
|
131
|
+
const key = places.length ? JSON.stringify([count, messiness, seed, depth]) : '';
|
|
132
|
+
if (key === this.stillsKey)
|
|
133
|
+
return;
|
|
134
|
+
this.stillsKey = key;
|
|
135
|
+
const holder = card.querySelector('.stills');
|
|
136
|
+
if (holder)
|
|
137
|
+
holder.innerHTML = places.map((p, at) => `<i class="still" style="--x:${p.x};--y:${p.y};--r:${p.rotate};--k:${count - places.length + at}"></i>`).join('');
|
|
138
|
+
}
|
|
139
|
+
render() { const card = this.shadowRoot?.querySelector('.card'); if (card) {
|
|
140
|
+
const mm = this.cardThicknessMm, count = this.stackCount, material = cardMaterial(this.getAttribute('material'));
|
|
141
|
+
card.style.setProperty('--mm', String(mm * count));
|
|
142
|
+
card.style.setProperty('--mm1', String(mm));
|
|
143
|
+
card.classList.toggle('stacked', count > 1);
|
|
144
|
+
if (material)
|
|
145
|
+
card.style.setProperty('--edge', material.edge);
|
|
146
|
+
else
|
|
147
|
+
card.style.removeProperty('--edge');
|
|
148
|
+
this.drawStills(card, count);
|
|
149
|
+
} this.applyWear(); const button = this.shadowRoot?.querySelector('.motion-button'); if (button) {
|
|
29
150
|
button.hidden = this.getAttribute('motion') !== 'pan';
|
|
30
|
-
const active = this.
|
|
31
|
-
|
|
151
|
+
const active = this.isMoving;
|
|
152
|
+
this.toggleAttribute('moving', active);
|
|
32
153
|
button.setAttribute('aria-pressed', String(active));
|
|
33
154
|
} for (const key of FudaCard.observedAttributes) {
|
|
34
155
|
const node = this.shadowRoot?.getElementById(key);
|
package/dist/index.d.ts
CHANGED
|
@@ -10,11 +10,32 @@ export interface CardOptions {
|
|
|
10
10
|
rarity?: string;
|
|
11
11
|
variant?: CardVariant;
|
|
12
12
|
finish?: CardFinish;
|
|
13
|
-
/** Card thickness in millimetres at the 63 mm wide card size;
|
|
13
|
+
/** Card thickness in millimetres at the 63 mm wide card size; overrides the material's. Default 0.3, 0 for a flat card. */
|
|
14
14
|
thickness?: number;
|
|
15
|
+
/** A material's id (see `cardMaterials`): its sourced thickness and edge colour. */
|
|
16
|
+
material?: string;
|
|
17
|
+
/** How many cards the stack holds (1 to 1000); the stack is that many times the card's thickness high. Default 1, one card. */
|
|
18
|
+
stack?: number;
|
|
19
|
+
/** From 0 (squared up) to 1 (very messy) for the cards under the top one. Default 0.3. */
|
|
20
|
+
stackMessiness?: number;
|
|
21
|
+
/** The stack's seed: the same seed lays the same stack the same way. Default 1. */
|
|
22
|
+
stackSeed?: number;
|
|
23
|
+
/** How many cards under the top one are laid out nudged and turned, at most 52. Default 10. */
|
|
24
|
+
stackDepth?: number;
|
|
25
|
+
/** A card that is not perfect: a preset's id (`mint`, `near-mint`, `lightly-played`, `moderately-played`, `heavily-played`, `damaged`) or a number from 0 to 1. Default: perfect, nothing drawn. */
|
|
26
|
+
wear?: string | number;
|
|
27
|
+
/** The wear's seed: the same seed draws the same marks the same way. Default 1. */
|
|
28
|
+
wearSeed?: number;
|
|
29
|
+
/** One level of the wear on its own, from 0 to 1, over the preset's. */
|
|
30
|
+
wearCorners?: number;
|
|
31
|
+
wearEdges?: number;
|
|
32
|
+
wearSurface?: number;
|
|
33
|
+
wearCreases?: number;
|
|
15
34
|
flipped?: boolean;
|
|
16
35
|
motion?: 'still' | 'pan';
|
|
17
36
|
playing?: boolean;
|
|
37
|
+
/** `focus`: the card in focus animates its art (needs `motion: 'pan'`); never with reduced motion. */
|
|
38
|
+
autoplay?: 'focus';
|
|
18
39
|
panDirection?: 'down' | 'up';
|
|
19
40
|
panLoop?: 'alternate' | 'restart';
|
|
20
41
|
cardSpin?: 'center' | 'corner';
|
|
@@ -23,3 +44,9 @@ export interface CardOptions {
|
|
|
23
44
|
}
|
|
24
45
|
export declare const cardVariants: readonly CardVariant[];
|
|
25
46
|
export declare const cardFinishes: readonly CardFinish[];
|
|
47
|
+
export { cardMaterials, cardMaterial, stackPresets, stackHeightMm, mmPerPoint } from './materials.js';
|
|
48
|
+
export type { CardMaterial, CardMaterialGroup, CardMaterialSource, StackPreset } from './materials.js';
|
|
49
|
+
export { stackLayout } from './stack.js';
|
|
50
|
+
export type { StackPlace, StackLayoutOptions } from './stack.js';
|
|
51
|
+
export { wearPresets, wearPreset, wearLevels, wearLayout, wearOutline, wearOverlaySvg } from './wear.js';
|
|
52
|
+
export type { WearPreset, WearLevels, WearOptions, WearFeatures, WearCorner, CornerKind } from './wear.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export const cardVariants = ['classic', 'sport', 'cosmic'];
|
|
2
2
|
export const cardFinishes = ['foil', 'matte'];
|
|
3
|
+
export { cardMaterials, cardMaterial, stackPresets, stackHeightMm, mmPerPoint } from './materials.js';
|
|
4
|
+
export { stackLayout } from './stack.js';
|
|
5
|
+
export { wearPresets, wearPreset, wearLevels, wearLayout, wearOutline, wearOverlaySvg } from './wear.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** A card material with a thickness taken from a maker or a standard, and where it was read. */
|
|
2
|
+
export interface CardMaterialSource {
|
|
3
|
+
label: string;
|
|
4
|
+
url: string;
|
|
5
|
+
/** What the source says, in short. */
|
|
6
|
+
says: string;
|
|
7
|
+
}
|
|
8
|
+
export type CardMaterialGroup = 'paper' | 'plastic' | 'thick-card' | 'metal';
|
|
9
|
+
export interface CardMaterial {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
group: CardMaterialGroup;
|
|
13
|
+
/** Thickness of one card in millimetres. */
|
|
14
|
+
thicknessMm: number;
|
|
15
|
+
/** The colour of the card's edge (a look, not a measurement). */
|
|
16
|
+
edge: string;
|
|
17
|
+
source: CardMaterialSource;
|
|
18
|
+
}
|
|
19
|
+
/** A count of cards for a stack, with where the number comes from. */
|
|
20
|
+
export interface StackPreset {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
count: number;
|
|
24
|
+
source: CardMaterialSource;
|
|
25
|
+
}
|
|
26
|
+
/** One thousandth of an inch ("pt" in card and paper trade talk) in millimetres. */
|
|
27
|
+
export declare const mmPerPoint = 0.0254;
|
|
28
|
+
export declare const cardMaterials: readonly CardMaterial[];
|
|
29
|
+
export declare const stackPresets: readonly StackPreset[];
|
|
30
|
+
/** The material with this id, or undefined. */
|
|
31
|
+
export declare function cardMaterial(id: string | null | undefined): CardMaterial | undefined;
|
|
32
|
+
/** Height of a stack of `count` cards `thicknessMm` thick, in millimetres. */
|
|
33
|
+
export declare function stackHeightMm(count: number, thicknessMm: number): number;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** One thousandth of an inch ("pt" in card and paper trade talk) in millimetres. */
|
|
2
|
+
export const mmPerPoint = 0.0254;
|
|
3
|
+
const pt = (points) => Math.round(points * mmPerPoint * 1000) / 1000;
|
|
4
|
+
const qin = { label: 'Qin Printing, Custom Playing Card Printing', url: 'https://www.qinprinting.com/poker-card-printing/' };
|
|
5
|
+
const holder = (points, slug) => ({
|
|
6
|
+
label: `Ultra PRO, ${points}PT ONE-TOUCH Magnetic Holder`,
|
|
7
|
+
url: `https://ultrapro.com/products/${slug}`,
|
|
8
|
+
says: `holds standard cards (2-1/2" x 3-1/2") up to ${points}pt in thickness`
|
|
9
|
+
});
|
|
10
|
+
const thick = (points, slug) => ({
|
|
11
|
+
id: `card-${points}pt`,
|
|
12
|
+
name: `Thick trading card, ${points} pt`,
|
|
13
|
+
group: 'thick-card',
|
|
14
|
+
thicknessMm: pt(points),
|
|
15
|
+
edge: '#e8dfca',
|
|
16
|
+
source: holder(points, slug)
|
|
17
|
+
});
|
|
18
|
+
export const cardMaterials = [
|
|
19
|
+
{ id: 'paper-250', name: 'Card stock, 250 gsm (11 pt)', group: 'paper', thicknessMm: 0.28, edge: '#efe9da', source: { ...qin, says: 'Premium Cardstock, 250gsm, 0.28mm, 11pt' } },
|
|
20
|
+
{ id: 'paper-310-black-core', name: 'Playing-card stock, black core, 310 gsm (13 pt)', group: 'paper', thicknessMm: 0.325, edge: '#2a2a2e', source: { ...qin, says: 'Black Core Paper, 310gsm, 0.325mm, 13pt' } },
|
|
21
|
+
{ id: 'paper-350', name: 'Heavy card stock, 350 gsm (16 pt)', group: 'paper', thicknessMm: 0.405, edge: '#e9e1cd', source: { ...qin, says: 'Premium Cardstock, 350gsm, 0.405mm, 16pt' } },
|
|
22
|
+
{ id: 'plastic-id1', name: 'Plastic bank-size card (ID-1, PVC)', group: 'plastic', thicknessMm: 0.76, edge: '#f2f2ef', source: { label: 'ISO/IEC 7810 ID-1, as summarised on Wikipedia', url: 'https://en.wikipedia.org/wiki/ISO/IEC_7810', says: '"All card sizes have a thickness of 760±80 μm." Payment cards are generally PVC (Wikipedia, Payment card).' } },
|
|
23
|
+
thick(35, '35pt-uv-one-touch-magnetic-holders-5ct'),
|
|
24
|
+
thick(55, '55pt-uv-one-touch-magnetic-holder'),
|
|
25
|
+
thick(75, '75pt-uv-one-touch-magnetic-holder'),
|
|
26
|
+
thick(100, '100pt-uv-one-touch-magnetic-holder'),
|
|
27
|
+
thick(130, '130pt-uv-one-touch-magnetic-holder'),
|
|
28
|
+
thick(180, '180pt-uv-one-touch-magnetic-holder'),
|
|
29
|
+
{ id: 'booklet-175pt', name: 'Booklet card, 175 pt', group: 'thick-card', thicknessMm: pt(175), edge: '#e8dfca', source: { label: 'Ultra PRO, 175PT Vertical Booklet Card ONE-TOUCH Magnetic Holder', url: 'https://ultrapro.com/products/175pt-vertical-booklet-card-uv-one-touch-magnetic-holder', says: '"Sized to fit Vertical Booklets up to 175pt thickness"' } },
|
|
30
|
+
{ id: 'aluminium-0.8', name: 'Anodised aluminium card, 0.8 mm', group: 'metal', thicknessMm: 0.8, edge: '#c9ced4', source: { label: 'ebamaz anodised aluminium business card blank, 86 x 54 x 0.8 mm (Wood Art Supply listing)', url: 'https://woodartsupply.com/products/ebamaz-metal-business-cards-anodized-aluminum-plaque-plate-86x54x0-8mm-silver-blank-10pcs', says: '"Material: Anodized Aluminum", "Size: 86X54X0.8mm"' } },
|
|
31
|
+
{ id: 'steel-0.5', name: 'Stainless steel card, 0.5 mm', group: 'metal', thicknessMm: 0.5, edge: '#aab0b6', source: { label: 'My Metal Business Card, Metal Business Card Thickness Guide', url: 'https://mymetalbusinesscard.com/blog/metal-business-card-thickness-guide/', says: '"our standard metal business card thickness is 0.5mm"; "A 0.5mm stainless steel business card"' } }
|
|
32
|
+
];
|
|
33
|
+
const wikiDeck = { label: 'Wikipedia, Playing card', url: 'https://en.wikipedia.org/wiki/Playing_card' };
|
|
34
|
+
const wikiPokemon = { label: 'Wikipedia, Pokémon Trading Card Game', url: 'https://en.wikipedia.org/wiki/Pok%C3%A9mon_Trading_Card_Game' };
|
|
35
|
+
export const stackPresets = [
|
|
36
|
+
{ id: 'deck-52', name: 'Playing cards, 52', count: 52, source: { ...wikiDeck, says: '"The 52-card deck is the most popular deck"' } },
|
|
37
|
+
{ id: 'deck-54', name: 'Playing cards with two jokers, 54', count: 54, source: { ...wikiDeck, says: 'commercial packs "often include between one and six jokers, most often two", so 52 + 2' } },
|
|
38
|
+
{ id: 'pokemon-deck', name: 'Pokémon TCG deck, 60', count: 60, source: { ...wikiPokemon, says: 'players "play with 60-card decks"' } },
|
|
39
|
+
{ id: 'pokemon-booster', name: 'Booster pack, about 10', count: 10, source: { ...wikiPokemon, says: '"a collector can pull 10 cards in total" from a booster pack' } }
|
|
40
|
+
];
|
|
41
|
+
/** The material with this id, or undefined. */
|
|
42
|
+
export function cardMaterial(id) {
|
|
43
|
+
return cardMaterials.find(material => material.id === id);
|
|
44
|
+
}
|
|
45
|
+
/** Height of a stack of `count` cards `thicknessMm` thick, in millimetres. */
|
|
46
|
+
export function stackHeightMm(count, thicknessMm) {
|
|
47
|
+
return Math.round(Math.max(1, Math.floor(count)) * thicknessMm * 1000) / 1000;
|
|
48
|
+
}
|
package/dist/stack.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the cards of a stack lie, from neat to messy, the same every time for the same seed.
|
|
3
|
+
*
|
|
4
|
+
* The idea and the three parameters (messiness, seed, depth) come from toranpu's pileLayout
|
|
5
|
+
* (github.com/johnmorrisdotca/toranpu, `src/ui/layout.ts`, MIT). This is written again here for a stack that has a true
|
|
6
|
+
* thickness: a card's height is not faked by moving it down the page, so only the nudge and the turn are laid out.
|
|
7
|
+
*/
|
|
8
|
+
export interface StackPlace {
|
|
9
|
+
/** Across, in card widths from where a square card lies. */
|
|
10
|
+
x: number;
|
|
11
|
+
/** Down, in card widths. */
|
|
12
|
+
y: number;
|
|
13
|
+
/** Turn in degrees. */
|
|
14
|
+
rotate: number;
|
|
15
|
+
}
|
|
16
|
+
export interface StackLayoutOptions {
|
|
17
|
+
/** From 0 (squared up) to 1 (very messy). Unless said, 0.3. */
|
|
18
|
+
messiness?: number;
|
|
19
|
+
/** The stack's own seed: the same seed lays the same stack the same way. Unless said, 1. */
|
|
20
|
+
seed?: number;
|
|
21
|
+
/** How many cards under the top one are laid out at most, so a stack of 52 costs no more than one of 11. Unless said, 10. */
|
|
22
|
+
depth?: number;
|
|
23
|
+
}
|
|
24
|
+
/** A stream of numbers in [0, 1) fixed by a seed (mulberry32). */
|
|
25
|
+
export declare function seededRandom(seed: number): () => number;
|
|
26
|
+
/**
|
|
27
|
+
* The cards under the top one of a stack of `count`, bottom first: the top `depth` of them, as the top card is the live one
|
|
28
|
+
* and lies square. A card's place depends on its number from the bottom, so a card put on top moves none of those under it.
|
|
29
|
+
*/
|
|
30
|
+
export declare function stackLayout(count: number, options?: StackLayoutOptions): StackPlace[];
|
package/dist/stack.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** A stream of numbers in [0, 1) fixed by a seed (mulberry32). */
|
|
2
|
+
export function seededRandom(seed) {
|
|
3
|
+
let state = seed >>> 0;
|
|
4
|
+
return () => {
|
|
5
|
+
state = (state + 0x6d2b79f5) >>> 0;
|
|
6
|
+
let t = state;
|
|
7
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
8
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
9
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const clamp01 = (value) => (Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 1);
|
|
13
|
+
const round = (value) => {
|
|
14
|
+
const kept = Math.round(value * 1000) / 1000;
|
|
15
|
+
return Object.is(kept, -0) ? 0 : kept;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The cards under the top one of a stack of `count`, bottom first: the top `depth` of them, as the top card is the live one
|
|
19
|
+
* and lies square. A card's place depends on its number from the bottom, so a card put on top moves none of those under it.
|
|
20
|
+
*/
|
|
21
|
+
export function stackLayout(count, options = {}) {
|
|
22
|
+
const whole = Math.max(0, Math.floor(Number.isFinite(count) ? count : 0));
|
|
23
|
+
const mess = clamp01(options.messiness ?? 0.3);
|
|
24
|
+
const depth = Math.max(0, Math.floor(options.depth ?? 10));
|
|
25
|
+
const shown = Math.max(0, Math.min(whole - 1, depth));
|
|
26
|
+
const seed = Number.isFinite(options.seed) ? options.seed : 1;
|
|
27
|
+
const places = [];
|
|
28
|
+
for (let at = 0; at < shown; at++) {
|
|
29
|
+
const index = whole - 1 - shown + at;
|
|
30
|
+
const random = seededRandom((seed * 2654435761 + index * 40503) >>> 0);
|
|
31
|
+
const nudge = 0.09 * mess;
|
|
32
|
+
places.push({
|
|
33
|
+
x: round((random() * 2 - 1) * nudge),
|
|
34
|
+
y: round((random() * 2 - 1) * nudge * 0.8),
|
|
35
|
+
rotate: round((random() * 2 - 1) * 14 * mess ** 1.3)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return places;
|
|
39
|
+
}
|
package/dist/wear.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/** How much of each kind of wear, from 0 (none) to 1 (the worst the preset names). */
|
|
2
|
+
export interface WearLevels {
|
|
3
|
+
corners: number;
|
|
4
|
+
edges: number;
|
|
5
|
+
surface: number;
|
|
6
|
+
creases: number;
|
|
7
|
+
/** Yellowing and darkened borders with age. */
|
|
8
|
+
toning: number;
|
|
9
|
+
/** How far the print sits off centre. */
|
|
10
|
+
centering: number;
|
|
11
|
+
}
|
|
12
|
+
export interface WearPreset {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
levels: WearLevels;
|
|
16
|
+
/** What the condition term means in grading language, in a few words. */
|
|
17
|
+
says: string;
|
|
18
|
+
}
|
|
19
|
+
/** From perfect to damaged. The names are the plain grading terms; the numbers are this package's reading of them (docs/wear.md). */
|
|
20
|
+
export declare const wearPresets: readonly WearPreset[];
|
|
21
|
+
export declare function wearPreset(id: string | null | undefined): WearPreset | undefined;
|
|
22
|
+
export interface WearOptions {
|
|
23
|
+
/** A preset's id, or a number from 0 to 1 for all the levels at once. */
|
|
24
|
+
wear?: string | number | null;
|
|
25
|
+
/** The seed: the same seed lays the same marks the same way. Unless said, 1. */
|
|
26
|
+
seed?: number;
|
|
27
|
+
/** Overrides of one level each, from 0 to 1. */
|
|
28
|
+
corners?: number;
|
|
29
|
+
edges?: number;
|
|
30
|
+
surface?: number;
|
|
31
|
+
creases?: number;
|
|
32
|
+
}
|
|
33
|
+
/** The levels a card's wear asks for, or null when it asks for none (no wear, "perfect", an unknown name or all zero). */
|
|
34
|
+
export declare function wearLevels(options: WearOptions): WearLevels | null;
|
|
35
|
+
export type CornerKind = 'sharp' | 'soft' | 'rounded' | 'chipped' | 'dog-eared';
|
|
36
|
+
export interface WearCorner {
|
|
37
|
+
kind: CornerKind;
|
|
38
|
+
/** How far the damage reaches along each edge, in units of a 250 by 350 card. */
|
|
39
|
+
size: number;
|
|
40
|
+
/** Jagged points of a chip, in the corner's own frame. */
|
|
41
|
+
jag: number[];
|
|
42
|
+
}
|
|
43
|
+
export interface WearMark {
|
|
44
|
+
x1: number;
|
|
45
|
+
y1: number;
|
|
46
|
+
x2: number;
|
|
47
|
+
y2: number;
|
|
48
|
+
/** Strength from 0 to 1. */
|
|
49
|
+
a: number;
|
|
50
|
+
/** A crease that broke the print. */
|
|
51
|
+
heavy?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface WearFleck {
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
r: number;
|
|
57
|
+
a: number;
|
|
58
|
+
light: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface WearEdgeFleck {
|
|
61
|
+
x: number;
|
|
62
|
+
y: number;
|
|
63
|
+
w: number;
|
|
64
|
+
h: number;
|
|
65
|
+
a: number;
|
|
66
|
+
}
|
|
67
|
+
export interface WearFace {
|
|
68
|
+
edge: WearEdgeFleck[];
|
|
69
|
+
creases: WearMark[];
|
|
70
|
+
scratches: WearMark[];
|
|
71
|
+
specks: WearFleck[];
|
|
72
|
+
stain: {
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
r: number;
|
|
76
|
+
a: number;
|
|
77
|
+
} | null;
|
|
78
|
+
}
|
|
79
|
+
export interface WearFeatures {
|
|
80
|
+
levels: WearLevels;
|
|
81
|
+
/** Top left, top right, bottom right, bottom left of the front. */
|
|
82
|
+
corners: WearCorner[];
|
|
83
|
+
/** The print's shift off centre in pixels at 300 wide: x and y. */
|
|
84
|
+
centering: {
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
};
|
|
88
|
+
front: WearFace;
|
|
89
|
+
back: WearFace;
|
|
90
|
+
}
|
|
91
|
+
export declare const CARD_W = 250;
|
|
92
|
+
export declare const CARD_H = 350;
|
|
93
|
+
/** The radius of a perfect card's corner in these units (15 px of 300). */
|
|
94
|
+
export declare const BASE_RADIUS = 12.5;
|
|
95
|
+
/** Where every mark of a card lies. A pure function of the levels and the seed: no DOM, nothing at random. */
|
|
96
|
+
export declare function wearLayout(levels: WearLevels, seed?: number): WearFeatures;
|
|
97
|
+
/** The outline of a face as an SVG path in the 250 by 350 box, corners as worn. */
|
|
98
|
+
export declare function wearOutline(features: WearFeatures, face?: 'front' | 'back'): string;
|
|
99
|
+
/** The SVG laid over one face: whitening, folds, creases, scratches, specks, stain and toning. Markup only, no script. */
|
|
100
|
+
export declare function wearOverlaySvg(features: WearFeatures, face?: 'front' | 'back'): string;
|
|
101
|
+
/** Draw a card's wear into its shadow root; calling it again with other options replaces the first. */
|
|
102
|
+
export declare function applyWear(root: ShadowRoot, options: WearOptions): boolean;
|
|
103
|
+
/** Take a card's wear away, leaving the card as it was. */
|
|
104
|
+
export declare function clearWear(root: ShadowRoot): void;
|
package/dist/wear.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wear: a card that is not perfect.
|
|
3
|
+
*
|
|
4
|
+
* Real condition grading looks at four things: corners, edges, surface and centering, and at creases and staining
|
|
5
|
+
* (see docs/wear.md for the sources and what each says). Here a preset sets how much of each there is, from 0 (none) to
|
|
6
|
+
* 1 (the worst the preset names), and a seed lays the marks out, so the same seed draws the same card every time.
|
|
7
|
+
* Everything is drawn: the outline of each face (rounded, chipped or folded corners) and one SVG over each face
|
|
8
|
+
* (whitening, creases, scratches, specks, staining, toning). Nothing here is a picture.
|
|
9
|
+
*
|
|
10
|
+
* This module is loaded by `<fuda-card>` only when a card asks for wear, so a perfect card carries none of it.
|
|
11
|
+
*/
|
|
12
|
+
import { seededRandom } from './stack.js';
|
|
13
|
+
const L = (corners, edges, surface, creases, toning, centering) => ({ corners, edges, surface, creases, toning, centering });
|
|
14
|
+
/** From perfect to damaged. The names are the plain grading terms; the numbers are this package's reading of them (docs/wear.md). */
|
|
15
|
+
export const wearPresets = [
|
|
16
|
+
{ id: 'perfect', name: 'Perfect', levels: L(0, 0, 0, 0, 0, 0), says: 'No imperfections, even close up. Draws nothing.' },
|
|
17
|
+
{ id: 'mint', name: 'Mint', levels: L(0.05, 0.05, 0.06, 0, 0, 0.1), says: 'Nothing to the naked eye; a flaw or two only on close inspection.' },
|
|
18
|
+
{ id: 'near-mint', name: 'Near mint', levels: L(0.18, 0.2, 0.2, 0, 0, 0.2), says: 'Sharp corners, a trace of edge whitening, a few light scratches.' },
|
|
19
|
+
{ id: 'lightly-played', name: 'Lightly played', levels: L(0.38, 0.45, 0.4, 0, 0.05, 0.3), says: 'Very slight corner rounding, whitening on one or two edges, scratches seen when tilted.' },
|
|
20
|
+
{ id: 'moderately-played', name: 'Moderately played', levels: L(0.62, 0.68, 0.62, 0.08, 0.15, 0.45), says: 'Soft or rounded corners, whitening on several edges, obvious scratches, some gloss lost.' },
|
|
21
|
+
{ id: 'heavily-played', name: 'Heavily played', levels: L(0.82, 0.9, 0.85, 0.3, 0.3, 0.6), says: 'Corners that have lost their shape, heavy whitening, deep scratches, minor creases.' },
|
|
22
|
+
{ id: 'damaged', name: 'Damaged', levels: L(1, 1, 1, 0.85, 0.5, 0.8), says: 'Chipped and folded corners, hard creases, staining.' }
|
|
23
|
+
];
|
|
24
|
+
export function wearPreset(id) {
|
|
25
|
+
return wearPresets.find((preset) => preset.id === id);
|
|
26
|
+
}
|
|
27
|
+
const clamp01 = (value) => (Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 0);
|
|
28
|
+
const round = (value) => Math.round(value * 100) / 100;
|
|
29
|
+
/** The levels a card's wear asks for, or null when it asks for none (no wear, "perfect", an unknown name or all zero). */
|
|
30
|
+
export function wearLevels(options) {
|
|
31
|
+
const asked = options.wear;
|
|
32
|
+
let base = L(0, 0, 0, 0, 0, 0);
|
|
33
|
+
if (typeof asked === 'number' && Number.isFinite(asked)) {
|
|
34
|
+
const n = clamp01(asked);
|
|
35
|
+
base = L(n, n, n, n * n, n * 0.5, n);
|
|
36
|
+
}
|
|
37
|
+
else if (typeof asked === 'string' && asked.trim() !== '') {
|
|
38
|
+
const preset = wearPreset(asked.trim());
|
|
39
|
+
if (preset)
|
|
40
|
+
base = preset.levels;
|
|
41
|
+
else if (Number.isFinite(Number(asked)))
|
|
42
|
+
return wearLevels({ ...options, wear: Number(asked) });
|
|
43
|
+
}
|
|
44
|
+
const levels = { ...base };
|
|
45
|
+
for (const key of ['corners', 'edges', 'surface', 'creases']) {
|
|
46
|
+
const given = options[key];
|
|
47
|
+
if (given !== undefined && Number.isFinite(given))
|
|
48
|
+
levels[key] = clamp01(given);
|
|
49
|
+
}
|
|
50
|
+
return Object.values(levels).every((v) => v === 0) ? null : levels;
|
|
51
|
+
}
|
|
52
|
+
export const CARD_W = 250;
|
|
53
|
+
export const CARD_H = 350;
|
|
54
|
+
/** The radius of a perfect card's corner in these units (15 px of 300). */
|
|
55
|
+
export const BASE_RADIUS = 12.5;
|
|
56
|
+
function cornerFor(severity, random) {
|
|
57
|
+
const s = clamp01(severity);
|
|
58
|
+
if (s < 0.1)
|
|
59
|
+
return { kind: 'sharp', size: BASE_RADIUS, jag: [] };
|
|
60
|
+
if (s < 0.35)
|
|
61
|
+
return { kind: 'soft', size: round(BASE_RADIUS + s * 14), jag: [] };
|
|
62
|
+
if (s < 0.6)
|
|
63
|
+
return { kind: 'rounded', size: round(17 + s * 22), jag: [] };
|
|
64
|
+
if (s < 0.8) {
|
|
65
|
+
const size = round(7 + s * 14);
|
|
66
|
+
return { kind: 'chipped', size, jag: [round(0.3 + random() * 0.25), round(0.25 + random() * 0.3), round(0.5 + random() * 0.35), round(0.1 + random() * 0.2)] };
|
|
67
|
+
}
|
|
68
|
+
return { kind: 'dog-eared', size: round(15 + s * 22), jag: [] };
|
|
69
|
+
}
|
|
70
|
+
function faceFor(levels, random) {
|
|
71
|
+
const edge = [];
|
|
72
|
+
const flecks = Math.round(levels.edges * 30);
|
|
73
|
+
for (let i = 0; i < flecks; i++) {
|
|
74
|
+
const side = Math.floor(random() * 4), at = 0.08 + random() * 0.84, len = 2 + random() * (3 + levels.edges * 12), depth = 0.5 + random() * (0.8 + levels.edges * 2.4);
|
|
75
|
+
const a = round(0.7 + random() * 0.3);
|
|
76
|
+
if (side === 0)
|
|
77
|
+
edge.push({ x: round(at * CARD_W), y: 0, w: round(len), h: round(depth), a });
|
|
78
|
+
else if (side === 1)
|
|
79
|
+
edge.push({ x: round(CARD_W - depth), y: round(at * CARD_H), w: round(depth), h: round(len), a });
|
|
80
|
+
else if (side === 2)
|
|
81
|
+
edge.push({ x: round(at * CARD_W), y: round(CARD_H - depth), w: round(len), h: round(depth), a });
|
|
82
|
+
else
|
|
83
|
+
edge.push({ x: 0, y: round(at * CARD_H), w: round(depth), h: round(len), a });
|
|
84
|
+
}
|
|
85
|
+
const scratches = [];
|
|
86
|
+
const lines = Math.round(levels.surface * 9);
|
|
87
|
+
for (let i = 0; i < lines; i++) {
|
|
88
|
+
const x1 = 15 + random() * 220, y1 = 15 + random() * 320, angle = random() * Math.PI, len = 14 + random() * (30 + levels.surface * 60);
|
|
89
|
+
scratches.push({ x1: round(x1), y1: round(y1), x2: round(Math.min(245, Math.max(5, x1 + Math.cos(angle) * len))), y2: round(Math.min(345, Math.max(5, y1 + Math.sin(angle) * len))), a: round(0.15 + random() * 0.35) });
|
|
90
|
+
}
|
|
91
|
+
const specks = [];
|
|
92
|
+
const dots = Math.round(levels.surface * 26);
|
|
93
|
+
for (let i = 0; i < dots; i++)
|
|
94
|
+
specks.push({ x: round(8 + random() * 234), y: round(8 + random() * 334), r: round(0.3 + random() * 0.9), a: round(0.25 + random() * 0.4), light: random() < 0.5 });
|
|
95
|
+
const creases = [];
|
|
96
|
+
const count = levels.creases <= 0.04 ? 0 : Math.min(4, Math.ceil(levels.creases * 3));
|
|
97
|
+
for (let i = 0; i < count; i++) {
|
|
98
|
+
const horizontal = random() < 0.5, along = 0.15 + random() * 0.7, other = 0.15 + random() * 0.7;
|
|
99
|
+
const heavy = levels.creases > 0.5 && i === 0;
|
|
100
|
+
const x1 = horizontal ? 0 : along * CARD_W, y1 = horizontal ? along * CARD_H : 0;
|
|
101
|
+
const x2 = horizontal ? CARD_W : other * CARD_W, y2 = horizontal ? other * CARD_H : CARD_H;
|
|
102
|
+
creases.push({ x1: round(x1), y1: round(y1), x2: round(x2), y2: round(y2), a: round(0.5 + random() * 0.4), heavy });
|
|
103
|
+
}
|
|
104
|
+
const stain = levels.creases > 0.5 || levels.toning > 0.4 ? { x: round(40 + random() * 170), y: round(60 + random() * 230), r: round(25 + random() * 45), a: round(0.12 + levels.toning * 0.25) } : null;
|
|
105
|
+
return { edge, creases, scratches, specks, stain };
|
|
106
|
+
}
|
|
107
|
+
/** Where every mark of a card lies. A pure function of the levels and the seed: no DOM, nothing at random. */
|
|
108
|
+
export function wearLayout(levels, seed = 1) {
|
|
109
|
+
const base = (Number.isFinite(seed) ? seed : 1) * 2654435761;
|
|
110
|
+
const corners = [];
|
|
111
|
+
for (let at = 0; at < 4; at++) {
|
|
112
|
+
const random = seededRandom((base + (at + 1) * 40503) >>> 0);
|
|
113
|
+
corners.push(cornerFor(levels.corners * (0.35 + random() * 0.95), random));
|
|
114
|
+
}
|
|
115
|
+
// A card has at most one folded corner and two chipped ones; the rest are only rounded, as real damage rarely falls on all four.
|
|
116
|
+
let folded = 0, chipped = 0;
|
|
117
|
+
corners.forEach((corner, index) => {
|
|
118
|
+
if (corner.kind === 'dog-eared' && ++folded > 1)
|
|
119
|
+
corners[index] = { kind: 'chipped', size: round(corner.size * 0.45), jag: [0.4, 0.35, 0.6, 0.2] };
|
|
120
|
+
if (corners[index].kind === 'chipped' && ++chipped > 2)
|
|
121
|
+
corners[index] = { kind: 'rounded', size: round(corner.size * 1.6), jag: [] };
|
|
122
|
+
});
|
|
123
|
+
const place = seededRandom((base + 7919) >>> 0);
|
|
124
|
+
const centering = { x: round((place() * 2 - 1) * levels.centering * 7), y: round((place() * 2 - 1) * levels.centering * 5) };
|
|
125
|
+
return { levels, corners, centering, front: faceFor(levels, seededRandom((base + 1000003) >>> 0)), back: faceFor({ ...levels, creases: levels.creases }, seededRandom((base + 2000003) >>> 0)) };
|
|
126
|
+
}
|
|
127
|
+
/** Points of one corner from where it leaves the incoming edge to where it joins the outgoing edge, in the corner's frame (a along the way out, b back along the way in). */
|
|
128
|
+
function cornerPoints(corner) {
|
|
129
|
+
const s = corner.kind === 'sharp' ? BASE_RADIUS : corner.size;
|
|
130
|
+
if (corner.kind === 'dog-eared')
|
|
131
|
+
return [[0, s], [s, 0]];
|
|
132
|
+
if (corner.kind === 'chipped') {
|
|
133
|
+
const [p, q, r, t] = corner.jag;
|
|
134
|
+
return [[0, s], [s * p, s * (1 - q) * 0.9], [s * q * 0.5, s * r * 0.5], [s * (1 - t), s * t], [s, 0]];
|
|
135
|
+
}
|
|
136
|
+
const points = [];
|
|
137
|
+
for (let step = 0; step <= 6; step++) {
|
|
138
|
+
const angle = (step / 6) * (Math.PI / 2);
|
|
139
|
+
points.push([s - s * Math.cos(angle), s - s * Math.sin(angle)]);
|
|
140
|
+
}
|
|
141
|
+
return points;
|
|
142
|
+
}
|
|
143
|
+
/** Which of the front's corners a face's corner is: the back is the front seen from behind, so left and right swap. */
|
|
144
|
+
const frames = [
|
|
145
|
+
{ x: 0, y: 0, a: [1, 0], b: [0, 1] },
|
|
146
|
+
{ x: CARD_W, y: 0, a: [0, 1], b: [-1, 0] },
|
|
147
|
+
{ x: CARD_W, y: CARD_H, a: [-1, 0], b: [0, -1] },
|
|
148
|
+
{ x: 0, y: CARD_H, a: [0, -1], b: [1, 0] }
|
|
149
|
+
];
|
|
150
|
+
const mirrored = [1, 0, 3, 2];
|
|
151
|
+
const at = (frame, a, b) => [round(frame.x + frame.a[0] * a + frame.b[0] * b), round(frame.y + frame.a[1] * a + frame.b[1] * b)];
|
|
152
|
+
/** The corner a face draws at position `index` (0 top left, clockwise as seen on that face). */
|
|
153
|
+
function faceCorner(features, index, face) {
|
|
154
|
+
return features.corners[face === 'front' ? index : mirrored[index]];
|
|
155
|
+
}
|
|
156
|
+
/** The outline of a face as an SVG path in the 250 by 350 box, corners as worn. */
|
|
157
|
+
export function wearOutline(features, face = 'front') {
|
|
158
|
+
const points = [];
|
|
159
|
+
frames.forEach((frame, index) => {
|
|
160
|
+
for (const [a, b] of cornerPoints(faceCorner(features, index, face)))
|
|
161
|
+
points.push(at(frame, a, b));
|
|
162
|
+
});
|
|
163
|
+
return `M${points.map(([x, y]) => `${x} ${y}`).join('L')}Z`;
|
|
164
|
+
}
|
|
165
|
+
function line(m, stroke, width, opacity, extra = '', bend = 0) {
|
|
166
|
+
const nx = -(m.y2 - m.y1), ny = m.x2 - m.x1, len = Math.hypot(nx, ny) || 1;
|
|
167
|
+
const way = bend ? `Q${round((m.x1 + m.x2) / 2 + (nx / len) * bend)} ${round((m.y1 + m.y2) / 2 + (ny / len) * bend)} ${m.x2} ${m.y2}` : `L${m.x2} ${m.y2}`;
|
|
168
|
+
return `<path d="M${m.x1} ${m.y1}${way}" stroke="${stroke}" stroke-width="${width}" opacity="${opacity}" fill="none" stroke-linecap="round"${extra}/>`;
|
|
169
|
+
}
|
|
170
|
+
/** The SVG laid over one face: whitening, folds, creases, scratches, specks, stain and toning. Markup only, no script. */
|
|
171
|
+
export function wearOverlaySvg(features, face = 'front') {
|
|
172
|
+
const data = face === 'front' ? features.front : features.back;
|
|
173
|
+
const levels = features.levels;
|
|
174
|
+
const paper = '#fffaf0';
|
|
175
|
+
const out = [];
|
|
176
|
+
out.push('<defs><radialGradient id="t" cx="50%" cy="48%" r="75%"><stop offset="45%" stop-color="#b8863a" stop-opacity="0"/><stop offset="100%" stop-color="#7a4a14" stop-opacity="1"/></radialGradient><linearGradient id="f" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#fff" stop-opacity="0.5"/><stop offset="1" stop-color="#000" stop-opacity="0.35"/></linearGradient><radialGradient id="s"><stop offset="0" stop-color="#6b4513" stop-opacity="1"/><stop offset="100%" stop-color="#6b4513" stop-opacity="0"/></radialGradient></defs>');
|
|
177
|
+
if (levels.toning > 0)
|
|
178
|
+
out.push(`<rect width="${CARD_W}" height="${CARD_H}" fill="url(#t)" opacity="${round(levels.toning * 0.55)}" style="mix-blend-mode:multiply"/>`);
|
|
179
|
+
if (data.stain)
|
|
180
|
+
out.push(`<circle cx="${data.stain.x}" cy="${data.stain.y}" r="${data.stain.r}" fill="url(#s)" opacity="${data.stain.a}" style="mix-blend-mode:multiply"/>`);
|
|
181
|
+
for (const f of data.specks)
|
|
182
|
+
out.push(`<circle cx="${f.x}" cy="${f.y}" r="${f.r}" fill="${f.light ? '#fff' : '#2b1b08'}" opacity="${f.a}"/>`);
|
|
183
|
+
for (const m of data.scratches)
|
|
184
|
+
out.push(line(m, '#fff', 0.45, m.a));
|
|
185
|
+
for (const m of data.creases) {
|
|
186
|
+
const nx = -(m.y2 - m.y1), ny = m.x2 - m.x1, len = Math.hypot(nx, ny) || 1, ox = round((nx / len) * 0.9), oy = round((ny / len) * 0.9);
|
|
187
|
+
const bend = round((m.a - 0.7) * 14);
|
|
188
|
+
out.push(line({ ...m, x1: round(m.x1 + ox), y1: round(m.y1 + oy), x2: round(m.x2 + ox), y2: round(m.y2 + oy) }, '#2a1a05', m.heavy ? 1.3 : 0.8, round(m.a * 0.4), '', bend));
|
|
189
|
+
out.push(line(m, '#fff', m.heavy ? 1.1 : 0.6, round(m.a * 0.55), '', bend));
|
|
190
|
+
if (m.heavy)
|
|
191
|
+
out.push(line(m, paper, 1.6, 0.8, ' stroke-dasharray="9 5 3 11 6 4"', bend));
|
|
192
|
+
}
|
|
193
|
+
for (const e of data.edge)
|
|
194
|
+
out.push(`<rect x="${e.x}" y="${e.y}" width="${e.w}" height="${e.h}" fill="${paper}" opacity="${e.a}"/>`);
|
|
195
|
+
frames.forEach((frame, index) => {
|
|
196
|
+
const corner = faceCorner(features, index, face);
|
|
197
|
+
const pts = cornerPoints(corner).map(([a, b]) => at(frame, a, b));
|
|
198
|
+
if (corner.kind === 'sharp') {
|
|
199
|
+
if (levels.corners > 0.02)
|
|
200
|
+
out.push(`<circle cx="${at(frame, 1.3, 1.3)[0]}" cy="${at(frame, 1.3, 1.3)[1]}" r="1.3" fill="${paper}" opacity="0.8"/>`);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (corner.kind === 'dog-eared') {
|
|
204
|
+
const s = corner.size, fold = [at(frame, 0, s), at(frame, s, 0), at(frame, s, s)];
|
|
205
|
+
const flap = face === 'front' ? '#183450' : '#e8c46a';
|
|
206
|
+
const shade = [at(frame, 0, s), at(frame, s, 0), at(frame, s + 2.2, s + 2.2)];
|
|
207
|
+
out.push(`<polygon points="${shade.map((p) => p.join(',')).join(' ')}" fill="#000" opacity="0.3"/>`);
|
|
208
|
+
out.push(`<polygon points="${fold.map((p) => p.join(',')).join(' ')}" fill="${flap}" stroke="${paper}" stroke-width="0.8"/>`);
|
|
209
|
+
out.push(`<polygon points="${fold.map((p) => p.join(',')).join(' ')}" fill="url(#f)" opacity="0.55"/>`);
|
|
210
|
+
out.push(`<path d="M${pts.map((p) => p.join(' ')).join('L')}" stroke="${paper}" stroke-width="1.2" fill="none"/>`);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
out.push(`<path d="M${pts.map((p) => p.join(' ')).join('L')}" stroke="${paper}" stroke-width="${corner.kind === 'chipped' ? 2.2 : 1.6}" opacity="0.85" fill="none" stroke-linejoin="round"/>`);
|
|
214
|
+
});
|
|
215
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${CARD_W} ${CARD_H}" preserveAspectRatio="none" aria-hidden="true">${out.join('')}</svg>`;
|
|
216
|
+
}
|
|
217
|
+
const STYLE = '.wear{position:absolute;pointer-events:none;display:block}.wear svg{display:block;width:100%;height:100%}';
|
|
218
|
+
const maskUrl = (path) => `url("data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${CARD_W} ${CARD_H}" preserveAspectRatio="none"><path d="${path}" fill="#000"/></svg>`)}")`;
|
|
219
|
+
/** Draw a card's wear into its shadow root; calling it again with other options replaces the first. */
|
|
220
|
+
export function applyWear(root, options) {
|
|
221
|
+
const levels = wearLevels(options);
|
|
222
|
+
clearWear(root);
|
|
223
|
+
if (!levels)
|
|
224
|
+
return false;
|
|
225
|
+
const features = wearLayout(levels, options.seed ?? 1);
|
|
226
|
+
const style = document.createElement('style');
|
|
227
|
+
style.dataset.wear = '';
|
|
228
|
+
style.textContent = STYLE;
|
|
229
|
+
root.prepend(style);
|
|
230
|
+
for (const face of ['front', 'back']) {
|
|
231
|
+
const element = root.querySelector(`.face.${face}`);
|
|
232
|
+
if (!element)
|
|
233
|
+
continue;
|
|
234
|
+
const holder = document.createElement('div');
|
|
235
|
+
holder.className = 'wear';
|
|
236
|
+
holder.dataset.wear = face;
|
|
237
|
+
holder.style.inset = face === 'front' ? '-2px' : '-11px';
|
|
238
|
+
holder.innerHTML = wearOverlaySvg(features, face);
|
|
239
|
+
element.append(holder);
|
|
240
|
+
const mask = maskUrl(wearOutline(features, face));
|
|
241
|
+
element.style.setProperty('-webkit-mask-image', mask);
|
|
242
|
+
element.style.setProperty('mask-image', mask);
|
|
243
|
+
element.style.setProperty('-webkit-mask-size', '100% 100%');
|
|
244
|
+
element.style.setProperty('mask-size', '100% 100%');
|
|
245
|
+
element.style.setProperty('-webkit-mask-repeat', 'no-repeat');
|
|
246
|
+
element.style.setProperty('mask-repeat', 'no-repeat');
|
|
247
|
+
}
|
|
248
|
+
const front = root.querySelector('.face.front');
|
|
249
|
+
if (front) {
|
|
250
|
+
const { x, y } = features.centering;
|
|
251
|
+
front.style.padding = `${13 + y}px ${13 - x}px ${13 - y}px ${13 + x}px`;
|
|
252
|
+
}
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
/** Take a card's wear away, leaving the card as it was. */
|
|
256
|
+
export function clearWear(root) {
|
|
257
|
+
root.querySelector('style[data-wear]')?.remove();
|
|
258
|
+
for (const holder of Array.from(root.querySelectorAll('.wear')))
|
|
259
|
+
holder.remove();
|
|
260
|
+
for (const element of Array.from(root.querySelectorAll('.face'))) {
|
|
261
|
+
for (const name of ['-webkit-mask-image', 'mask-image', '-webkit-mask-size', 'mask-size', '-webkit-mask-repeat', 'mask-repeat'])
|
|
262
|
+
element.style.removeProperty(name);
|
|
263
|
+
if (element.classList.contains('front'))
|
|
264
|
+
element.style.removeProperty('padding');
|
|
265
|
+
if (!element.getAttribute('style'))
|
|
266
|
+
element.removeAttribute('style');
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Card materials and stacks
|
|
2
|
+
|
|
3
|
+
Every thickness below was read from a maker's page or a standard on 2026-11-02 and is the number the page gives. Nothing is guessed. A material with no maker or standard to cite is not offered.
|
|
4
|
+
|
|
5
|
+
**Units.** `pt` is one thousandth of an inch (0.0254 mm): "a 10 pt. card is 0.010 in (0.254 mm) thick", "12 pt. is 0.012 in (0.3048 mm)" ([Wikipedia, Card stock](https://en.wikipedia.org/wiki/Card_stock), note 2). Where a source gives points only, the millimetres are points times 0.0254.
|
|
6
|
+
|
|
7
|
+
Use a material with `material="<id>"`. It sets the card's thickness and the colour of its edge (the edge colour is how the material looks, not a measurement; `--fuda-edge` still wins). `thickness` (millimetres) overrides the material's thickness. With neither, a card is 0.3 mm thick, as before (12 pt = 0.3048 mm).
|
|
8
|
+
|
|
9
|
+
| id | Material | Thickness (mm) | Source | What the source says |
|
|
10
|
+
|---|---|---|---|---|
|
|
11
|
+
| `paper-250` | Card stock, 250 gsm (11 pt) | 0.28 | [Qin Printing, Custom Playing Card Printing](https://www.qinprinting.com/poker-card-printing/) | Premium Cardstock, 250gsm, 0.28mm, 11pt |
|
|
12
|
+
| `paper-310-black-core` | Playing-card stock, black core, 310 gsm (13 pt) | 0.325 | [Qin Printing, Custom Playing Card Printing](https://www.qinprinting.com/poker-card-printing/) | Black Core Paper, 310gsm, 0.325mm, 13pt |
|
|
13
|
+
| `paper-350` | Heavy card stock, 350 gsm (16 pt) | 0.405 | [Qin Printing, Custom Playing Card Printing](https://www.qinprinting.com/poker-card-printing/) | Premium Cardstock, 350gsm, 0.405mm, 16pt |
|
|
14
|
+
| `plastic-id1` | Plastic bank-size card (ID-1, PVC) | 0.76 | [ISO/IEC 7810 ID-1, as summarised on Wikipedia](https://en.wikipedia.org/wiki/ISO/IEC_7810) | "All card sizes have a thickness of 760±80 μm." Payment cards are generally PVC (Wikipedia, Payment card). |
|
|
15
|
+
| `card-35pt` | Thick trading card, 35 pt | 0.889 | [Ultra PRO, 35PT ONE-TOUCH Magnetic Holder](https://ultrapro.com/products/35pt-uv-one-touch-magnetic-holders-5ct) | holds standard cards (2-1/2" x 3-1/2") up to 35pt in thickness |
|
|
16
|
+
| `card-55pt` | Thick trading card, 55 pt | 1.397 | [Ultra PRO, 55PT ONE-TOUCH Magnetic Holder](https://ultrapro.com/products/55pt-uv-one-touch-magnetic-holder) | holds standard cards (2-1/2" x 3-1/2") up to 55pt in thickness |
|
|
17
|
+
| `card-75pt` | Thick trading card, 75 pt | 1.905 | [Ultra PRO, 75PT ONE-TOUCH Magnetic Holder](https://ultrapro.com/products/75pt-uv-one-touch-magnetic-holder) | holds standard cards (2-1/2" x 3-1/2") up to 75pt in thickness |
|
|
18
|
+
| `card-100pt` | Thick trading card, 100 pt | 2.54 | [Ultra PRO, 100PT ONE-TOUCH Magnetic Holder](https://ultrapro.com/products/100pt-uv-one-touch-magnetic-holder) | holds standard cards (2-1/2" x 3-1/2") up to 100pt in thickness |
|
|
19
|
+
| `card-130pt` | Thick trading card, 130 pt | 3.302 | [Ultra PRO, 130PT ONE-TOUCH Magnetic Holder](https://ultrapro.com/products/130pt-uv-one-touch-magnetic-holder) | holds standard cards (2-1/2" x 3-1/2") up to 130pt in thickness |
|
|
20
|
+
| `card-180pt` | Thick trading card, 180 pt | 4.572 | [Ultra PRO, 180PT ONE-TOUCH Magnetic Holder](https://ultrapro.com/products/180pt-uv-one-touch-magnetic-holder) | holds standard cards (2-1/2" x 3-1/2") up to 180pt in thickness |
|
|
21
|
+
| `booklet-175pt` | Booklet card, 175 pt | 4.445 | [Ultra PRO, 175PT Vertical Booklet Card ONE-TOUCH Magnetic Holder](https://ultrapro.com/products/175pt-vertical-booklet-card-uv-one-touch-magnetic-holder) | "Sized to fit Vertical Booklets up to 175pt thickness" |
|
|
22
|
+
| `aluminium-0.8` | Anodised aluminium card, 0.8 mm | 0.8 | [ebamaz anodised aluminium business card blank, 86 x 54 x 0.8 mm (Wood Art Supply listing)](https://woodartsupply.com/products/ebamaz-metal-business-cards-anodized-aluminum-plaque-plate-86x54x0-8mm-silver-blank-10pcs) | "Material: Anodized Aluminum", "Size: 86X54X0.8mm" |
|
|
23
|
+
| `steel-0.5` | Stainless steel card, 0.5 mm | 0.5 | [My Metal Business Card, Metal Business Card Thickness Guide](https://mymetalbusinesscard.com/blog/metal-business-card-thickness-guide/) | "our standard metal business card thickness is 0.5mm"; "A 0.5mm stainless steel business card" |
|
|
24
|
+
|
|
25
|
+
How to read the table:
|
|
26
|
+
|
|
27
|
+
- The three paper stocks are a card printer's published calipers for playing-card and card stock. A real deck varies by maker and finish.
|
|
28
|
+
- The thick trading cards by point size (`card-35pt` to `card-180pt`) take the largest thickness Ultra PRO says its holder for that size holds ("up to"). A card sold as a given point size is at most that thick. A holder's limit is the maker's own number for a card of that size; it is not a measurement of one particular card.
|
|
29
|
+
- `plastic-id1` is the bank-card standard, 760 ± 80 µm; the PVC is from the payment-card article. A plastic playing card is not this thick.
|
|
30
|
+
- The two metals are single sellers' listings (anodised aluminium blank, 86 x 54 x 0.8 mm) and a metal-card maker's stated standard (stainless steel, 0.5 mm). Metal cards come in other thicknesses; those are not offered because no source for them was found.
|
|
31
|
+
|
|
32
|
+
**Left out because it could not be sourced to a maker or a standard:** a patch or relic card (no maker or standard gives its thickness; use a thick trading card or a booklet card), a graded-card slab, a plastic playing card (only reviewers' measurements were found), brass, copper and titanium cards, and other aluminium and steel thicknesses.
|
|
33
|
+
|
|
34
|
+
A check on the paper numbers: 52 cards come to 52 x 0.28 = 14.6 mm (250 gsm), 52 x 0.3 = 15.6 mm (the card's default, about 12 pt) or 52 x 0.325 = 16.9 mm (black-core playing-card stock).
|
|
35
|
+
|
|
36
|
+
## Stacks
|
|
37
|
+
|
|
38
|
+
`stack="N"` draws N cards, N from 1 to 1000. The height is N times a card's thickness, to scale: 52 cards of 0.325 mm are 16.9 mm. The count is free; these presets have a source:
|
|
39
|
+
|
|
40
|
+
| id | Preset | Cards | Source | What the source says |
|
|
41
|
+
|---|---|---|---|---|
|
|
42
|
+
| `deck-52` | Playing cards, 52 | 52 | [Wikipedia, Playing card](https://en.wikipedia.org/wiki/Playing_card) | "The 52-card deck is the most popular deck" |
|
|
43
|
+
| `deck-54` | Playing cards with two jokers, 54 | 54 | [Wikipedia, Playing card](https://en.wikipedia.org/wiki/Playing_card) | commercial packs "often include between one and six jokers, most often two", so 52 + 2 |
|
|
44
|
+
| `pokemon-deck` | Pokémon TCG deck, 60 | 60 | [Wikipedia, Pokémon Trading Card Game](https://en.wikipedia.org/wiki/Pok%C3%A9mon_Trading_Card_Game) | players "play with 60-card decks" |
|
|
45
|
+
| `pokemon-booster` | Booster pack, about 10 | 10 | [Wikipedia, Pokémon Trading Card Game](https://en.wikipedia.org/wiki/Pok%C3%A9mon_Trading_Card_Game) | "a collector can pull 10 cards in total" from a booster pack |
|
|
46
|
+
|
|
47
|
+
How a stack is drawn (one 3D context, no loop):
|
|
48
|
+
|
|
49
|
+
- The top card is the live `<fuda-card>`. Under it, the whole stack is one block whose edge is the material's colour with a fine line for each card.
|
|
50
|
+
- With messiness above 0, the `stack-depth` cards under the top one (10 unless said, at most 52) are drawn as flat stills: no art, no text, nudged and turned from a seed. Their places depend on their number from the bottom, so a card put on top moves none of those under it. A neat stack (`stack-messiness="0"`) draws no stills.
|
|
51
|
+
- Nothing animates: no timer, no animation frame, no CSS animation. A test checks that a 52-card stack at rest draws and requests no frames (`test/e2e/stack.e2e.mjs`).
|
|
52
|
+
- Attributes: `stack` (count), `stack-messiness` (0 to 1, default 0.3), `stack-seed` (a whole number, default 1), `stack-depth`. The element reads `stackCount` and `stackHeight` (millimetres). The package exports `cardMaterials`, `cardMaterial`, `stackPresets`, `stackHeightMm` and `stackLayout`.
|
|
53
|
+
|
|
54
|
+
The idea of a pile that goes from neat to messy from a seed, and its three parameters (messiness, seed, depth), come from [toranpu](https://github.com/johnmorrisdotca/toranpu) (`pileLayout` in `src/ui/layout.ts`, `<toranpu-pile>`, MIT). The code here is written again for a stack with a true thickness. Sharing the maths between the two packages is proposed to kazoku-ui.
|
package/docs/wear.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Wear: cards that are not perfect
|
|
2
|
+
|
|
3
|
+
`wear` draws a card as it looks after use: corners that are soft, rounded, chipped or folded, whitening on the edges, creases, scratches, specks, staining, yellowing and a print that sits off centre. It is off by default: a card with no `wear` attribute (or `wear="perfect"`) is drawn exactly as before and never loads the wear code.
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<fuda-card title="Rookie" wear="lightly-played" wear-seed="7"></fuda-card>
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
A card's wear is fixed by its preset and its seed, so a card looks the same every time it is drawn and on every device: the same seed lays the same marks, another seed lays others. Nothing is random at draw time and nothing animates.
|
|
10
|
+
|
|
11
|
+
## Attributes
|
|
12
|
+
|
|
13
|
+
| Attribute | Meaning |
|
|
14
|
+
|---|---|
|
|
15
|
+
| `wear` | A preset's id (below), or a number from 0 to 1 for all the levels at once. Empty or `perfect`: no wear. |
|
|
16
|
+
| `wear-seed` | The seed, a whole number. Default 1. |
|
|
17
|
+
| `wear-corners`, `wear-edges`, `wear-surface`, `wear-creases` | One level on its own, 0 to 1, over the preset's. |
|
|
18
|
+
|
|
19
|
+
In script: `card.wear = 'near-mint'`; the options object has `wear`, `wearSeed`, `wearCorners`, `wearEdges`, `wearSurface` and `wearCreases`. The package exports the data without touching the DOM: `wearPresets`, `wearPreset(id)`, `wearLevels(options)`, `wearLayout(levels, seed)` (where every mark lies), `wearOutline(layout, face)` and `wearOverlaySvg(layout, face)`. The code is a separate module (`dist/wear.js`) that `<fuda-card>` loads with a dynamic `import()` only when a card asks for wear.
|
|
20
|
+
|
|
21
|
+
## What real wear looks like, and where the words come from
|
|
22
|
+
|
|
23
|
+
Grading looks at four things: **centering, corners, edges and surface**, with creases, scratches, tears and staining counted as wear. The Wikipedia article on trading cards (section Value, Condition) lists the scale from pristine through mint, near mint, excellent, very good and good to poor, and says that "centering, corners, edges and surface are taken into consideration for imperfections".
|
|
24
|
+
|
|
25
|
+
The five terms most used for cards sold singly are near mint, lightly played, moderately played, heavily played and damaged. A guide that states its own conventions ("marketplace conventions, not official grades", Rare Candy, Pokémon card condition guide) describes them like this, and the presets follow it:
|
|
26
|
+
|
|
27
|
+
- **Near mint**: corners "sharp, no rounding or fraying"; edges "crisp, no whitening or chipping"; no scratch lines; no creases or staining.
|
|
28
|
+
- **Lightly played**: "very slight corner rounding"; "edge whitening on one or two sides"; scratch lines "you'd only notice if you tilted the card".
|
|
29
|
+
- **Moderately played**: corners "clearly soft or rounded"; whitening "consistent around multiple sides"; "obvious scratch lines"; still no creases or bends.
|
|
30
|
+
- **Heavily played**: "corners that have lost their shape entirely"; "heavy whitening on all four edges", possible chipping; "deep scratches"; minor bends or creases.
|
|
31
|
+
- **Damaged**: "punched corners"; "visible creases, hard bends, tears"; "water staining".
|
|
32
|
+
|
|
33
|
+
For the numbered scale, a third-party summary of PSA's standards (cardgrading.app, which says it is not PSA) lists, for the top grades, "factory-sharp points on every corner" at 10, "one corner is allowed to have very slight wear" at 9, "multiple corners with light wear" at 8, "moderate corner wear" at 7, "rounded corners" at 5, and creases and staining at 4 and below; and, for centering, front tolerances widening from 55/45 at 10 to 85/15 at 5. Older cards are held to a softer standard (Wikipedia, same section).
|
|
34
|
+
|
|
35
|
+
**What was not read.** The grading companies' own pages (PSA, Beckett, SGC) and TCGplayer's condition guide returned HTTP 403 to the tools used, so the numbers above come from the secondary sources named, not from the graders. The preset levels are this package's reading of those words, not a grade: no preset is "a PSA 7". The grading companies' names and grades are not used in any preset.
|
|
36
|
+
|
|
37
|
+
## Presets
|
|
38
|
+
|
|
39
|
+
Each level runs from 0 (none) to 1 (the worst the preset names). Levels never fall from one preset to the next (a test checks it).
|
|
40
|
+
|
|
41
|
+
| Id | Name | Corners | Edges | Surface | Creases | Toning | Centering | In plain words |
|
|
42
|
+
|---|---|---|---|---|---|---|---|---|
|
|
43
|
+
| `perfect` | Perfect | 0 | 0 | 0 | 0 | 0 | 0 | No imperfections. Draws nothing. |
|
|
44
|
+
| `mint` | Mint | 0.05 | 0.05 | 0.06 | 0 | 0 | 0.1 | Nothing to the naked eye; a flaw or two only on close inspection. |
|
|
45
|
+
| `near-mint` | Near mint | 0.18 | 0.2 | 0.2 | 0 | 0 | 0.2 | Sharp corners, a trace of edge whitening, a few light scratches. |
|
|
46
|
+
| `lightly-played` | Lightly played | 0.38 | 0.45 | 0.4 | 0 | 0.05 | 0.3 | Very slight corner rounding, whitening on one or two edges, scratches seen when tilted. |
|
|
47
|
+
| `moderately-played` | Moderately played | 0.62 | 0.68 | 0.62 | 0.08 | 0.15 | 0.45 | Soft or rounded corners, whitening on several edges, obvious scratches, some gloss lost. |
|
|
48
|
+
| `heavily-played` | Heavily played | 0.82 | 0.9 | 0.85 | 0.3 | 0.3 | 0.6 | Corners that have lost their shape, heavy whitening, deep scratches, minor creases. |
|
|
49
|
+
| `damaged` | Damaged | 1 | 1 | 1 | 0.85 | 0.5 | 0.8 | Chipped and folded corners, hard creases, staining. |
|
|
50
|
+
|
|
51
|
+
## How each kind of wear is drawn
|
|
52
|
+
|
|
53
|
+
- **Corners.** Each corner has its own severity, from the level and the seed: sharp (a speck of whitening), soft (a larger radius), rounded, chipped (a jagged notch) or folded (a dog-ear that shows the back of the card). A card has at most one folded and two chipped corners; real damage rarely lands on all four. The outline of each face is a mask, so the drop shadow follows it. The back is the front seen from behind, so its corners are the front's mirrored.
|
|
54
|
+
- **Edges.** Small cream flecks of bare stock along the four edges, longer and deeper with more wear.
|
|
55
|
+
- **Surface.** Thin light scratches and dark or light specks. They lie over the face and its shine.
|
|
56
|
+
- **Creases.** Slightly curved lines with a light side and a shadow side; a heavy one also breaks the print (a dashed cream line). None below `moderately-played`.
|
|
57
|
+
- **Toning and staining.** A yellow-brown darkening towards the edges and, from heavy wear, a soft stain.
|
|
58
|
+
- **Centering.** The print sits off centre by up to 7 px across and 5 px down (at 300 px wide) at full level, so one border is wider than the other.
|
|
59
|
+
|
|
60
|
+
## Limits
|
|
61
|
+
|
|
62
|
+
- The 3D edge planes (the card's thickness) keep the perfect card's outline; at 0.3 mm that is about 1 px. A chipped or folded corner shows the thickness's normal corner behind it.
|
|
63
|
+
- Warping and bending of the whole card, rubbed foil patterns, dents and tears across the card are not drawn.
|
|
64
|
+
- Cards under the top one of a `stack` are drawn without wear; only the live top card is worn.
|
|
65
|
+
- `<fuda-collection>` draws the caller's pictures, so it does not apply wear; scans that are already worn show their own wear.
|
|
66
|
+
- Headless Chromium only; not checked on a real phone, Safari or Firefox.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/fuda-cards",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Fuda Cards: collectible card frames for images and interactive 3D content.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
"docs/collection-displays.md",
|
|
35
35
|
"docs/collection-input.md",
|
|
36
36
|
"docs/framework-integration.md",
|
|
37
|
+
"docs/materials.md",
|
|
38
|
+
"docs/wear.md",
|
|
37
39
|
"assets/README.md"
|
|
38
40
|
],
|
|
39
41
|
"engines": {
|