@johnmorrisdotca/fuda-cards 0.4.0 → 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 +12 -2
- package/dist/element.d.ts +8 -0
- package/dist/element.js +27 -2
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -0
- package/dist/stack.d.ts +2 -0
- package/dist/stack.js +1 -1
- package/dist/wear.d.ts +104 -0
- package/dist/wear.js +268 -0
- package/docs/wear.md +66 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -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`), `material`, `stack` 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
|
|
|
@@ -62,6 +62,16 @@ The card has thickness, drawn to scale at the 63 mm wide card size: set `thickne
|
|
|
62
62
|
|
|
63
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
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
|
+
|
|
65
75
|
### Whole-card rotation
|
|
66
76
|
|
|
67
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.
|
package/dist/element.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ export declare class FudaCard extends HTMLElement {
|
|
|
22
22
|
get stackCount(): number;
|
|
23
23
|
/** Height of the stack in millimetres: the count times a card's thickness. */
|
|
24
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);
|
|
25
33
|
private stillsKey;
|
|
26
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. */
|
|
27
35
|
private drawStills;
|
package/dist/element.js
CHANGED
|
@@ -11,7 +11,7 @@ const reducedMotion = () => typeof matchMedia === 'function' && matchMedia('(pre
|
|
|
11
11
|
document.addEventListener('pointerdown', event => { if (focusedCard && !event.composedPath().includes(focusedCard))
|
|
12
12
|
focusedCard.setFocused(false); }, true);
|
|
13
13
|
export class FudaCard extends HTMLElement {
|
|
14
|
-
static observedAttributes = ['title', 'category', 'subtitle', 'description', 'number', 'rarity', 'motion', 'playing', 'thickness', 'autoplay', 'material', 'stack', 'stack-messiness', 'stack-seed', 'stack-depth'];
|
|
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
15
|
focused = false;
|
|
16
16
|
hushed = false;
|
|
17
17
|
focusedAtPress;
|
|
@@ -97,6 +97,31 @@ export class FudaCard extends HTMLElement {
|
|
|
97
97
|
get stackCount() { const n = Math.floor(Number.parseFloat(this.getAttribute('stack') ?? '')); return n >= 1 ? Math.min(1000, n) : 1; }
|
|
98
98
|
/** Height of the stack in millimetres: the count times a card's thickness. */
|
|
99
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);
|
|
123
|
+
else
|
|
124
|
+
this.removeAttribute('wear'); }
|
|
100
125
|
stillsKey = '';
|
|
101
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. */
|
|
102
127
|
drawStills(card, count) {
|
|
@@ -121,7 +146,7 @@ export class FudaCard extends HTMLElement {
|
|
|
121
146
|
else
|
|
122
147
|
card.style.removeProperty('--edge');
|
|
123
148
|
this.drawStills(card, count);
|
|
124
|
-
} const button = this.shadowRoot?.querySelector('.motion-button'); if (button) {
|
|
149
|
+
} this.applyWear(); const button = this.shadowRoot?.querySelector('.motion-button'); if (button) {
|
|
125
150
|
button.hidden = this.getAttribute('motion') !== 'pan';
|
|
126
151
|
const active = this.isMoving;
|
|
127
152
|
this.toggleAttribute('moving', active);
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,15 @@ export interface CardOptions {
|
|
|
22
22
|
stackSeed?: number;
|
|
23
23
|
/** How many cards under the top one are laid out nudged and turned, at most 52. Default 10. */
|
|
24
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;
|
|
25
34
|
flipped?: boolean;
|
|
26
35
|
motion?: 'still' | 'pan';
|
|
27
36
|
playing?: boolean;
|
|
@@ -39,3 +48,5 @@ export { cardMaterials, cardMaterial, stackPresets, stackHeightMm, mmPerPoint }
|
|
|
39
48
|
export type { CardMaterial, CardMaterialGroup, CardMaterialSource, StackPreset } from './materials.js';
|
|
40
49
|
export { stackLayout } from './stack.js';
|
|
41
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
|
@@ -2,3 +2,4 @@ export const cardVariants = ['classic', 'sport', 'cosmic'];
|
|
|
2
2
|
export const cardFinishes = ['foil', 'matte'];
|
|
3
3
|
export { cardMaterials, cardMaterial, stackPresets, stackHeightMm, mmPerPoint } from './materials.js';
|
|
4
4
|
export { stackLayout } from './stack.js';
|
|
5
|
+
export { wearPresets, wearPreset, wearLevels, wearLayout, wearOutline, wearOverlaySvg } from './wear.js';
|
package/dist/stack.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface StackLayoutOptions {
|
|
|
21
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
22
|
depth?: number;
|
|
23
23
|
}
|
|
24
|
+
/** A stream of numbers in [0, 1) fixed by a seed (mulberry32). */
|
|
25
|
+
export declare function seededRandom(seed: number): () => number;
|
|
24
26
|
/**
|
|
25
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
|
|
26
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.
|
package/dist/stack.js
CHANGED
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
|
+
}
|
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": [
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"docs/collection-input.md",
|
|
36
36
|
"docs/framework-integration.md",
|
|
37
37
|
"docs/materials.md",
|
|
38
|
+
"docs/wear.md",
|
|
38
39
|
"assets/README.md"
|
|
39
40
|
],
|
|
40
41
|
"engines": {
|