@johnmorrisdotca/fuda-cards 0.2.1 → 0.4.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 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 nothing; `<fuda-collection>` uses [`@johnmorrisdotca/kazoku-ui`](https://github.com/johnmorrisdotca/kazoku-ui) for its zoom controls (see Collection viewer).
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
 
@@ -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` 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,24 @@ 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`, a standard trading card of about 12 pt stock; roughly `0.8` for a metal card and `1` to `1.5` for a patch or relic card; `0` for a flat card). 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.
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
+
53
65
  ### Whole-card rotation
54
66
 
55
67
  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 +78,7 @@ To review, run `pnpm install` and `pnpm dev`, then open the Card Studio. Under *
66
78
 
67
79
  ### Moving artwork
68
80
 
69
- Set `motion="pan"` on a card containing a slotted `<img>` to enable an Animate button on a tall image. By default the card starts on a still, cropped view; add the boolean `playing` attribute to start with motion. Tapping Animate starts the pan, and tapping Stop returns to the still. A host can add or remove `playing` to control the state. 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.
81
+ 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
82
 
71
83
  ```html
72
84
  <fuda-card title="Starship" motion="pan" pan-direction="down" style="--fuda-pan-duration: 16s">
@@ -74,6 +86,14 @@ Set `motion="pan"` on a card containing a slotted `<img>` to enable an Animate b
74
86
  </fuda-card>
75
87
  ```
76
88
 
89
+ **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.
90
+
91
+ ```html
92
+ <fuda-card title="Starship" motion="pan" autoplay="focus">
93
+ <img src="starship.jpg" alt="Starship">
94
+ </fuda-card>
95
+ ```
96
+
77
97
  Planned JSON, API, scanned-card and interactive-content inputs are outlined in [docs/collection-input.md](docs/collection-input.md).
78
98
 
79
99
  ## Pokémon binder demo
package/dist/element.d.ts CHANGED
@@ -1,9 +1,29 @@
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 stillsKey;
26
+ /** 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
+ private drawStills;
8
28
  render(): void;
9
29
  }
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"][playing]) .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"][playing]) .art ::slotted(img){animation:none}}.motion-button{position:absolute;right:6px;bottom:6px;z-index:1;border:1px solid #fff9;border-radius:20px;padding:5px 9px;background:#101827dd;color:white;font:600 10px system-ui;cursor:pointer}.motion-button:focus-visible{outline:3px solid white;outline-offset:2px}.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))}: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}
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>▶ Animate</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" style="left:0;top:50%;width:var(--t);height:calc(100% - 30px);transform:translate(-50%,-50%) rotateY(90deg)"></i><i class="edge" 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></div>`;
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
- constructor() { super(); const root = this.attachShadow({ mode: 'open' }); root.append(template.content.cloneNode(true)); root.querySelector('button')?.addEventListener('click', () => this.toggleAttribute('playing')); this.watchArt(root); }
14
+ static observedAttributes = ['title', 'category', 'subtitle', 'description', 'number', 'rarity', 'motion', 'playing', 'thickness', 'autoplay', 'material', 'stack', 'stack-messiness', 'stack-seed', 'stack-depth'];
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,45 @@ export class FudaCard extends HTMLElement {
19
86
  requestAnimationFrame(update);
20
87
  }
21
88
  connectedCallback() { this.render(); }
22
- attributeChangedCallback(name) { if (name === 'motion' && this.getAttribute('motion') !== 'pan' && this.hasAttribute('playing'))
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
- render() { const mm = Number.parseFloat(this.getAttribute('thickness') ?? ''); const card = this.shadowRoot?.querySelector('.card'); if (mm >= 0)
26
- card?.style.setProperty('--mm', String(mm));
27
- else
28
- card?.style.removeProperty('--mm'); const button = this.shadowRoot?.querySelector('.motion-button'); if (button) {
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
+ stillsKey = '';
101
+ /** 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
+ drawStills(card, count) {
103
+ const num = (name, fallback) => { const n = Number.parseFloat(this.getAttribute(name) ?? ''); return Number.isFinite(n) ? n : fallback; };
104
+ 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))));
105
+ const places = count > 1 && messiness > 0 ? stackLayout(count, { messiness, seed, depth }) : [];
106
+ const key = places.length ? JSON.stringify([count, messiness, seed, depth]) : '';
107
+ if (key === this.stillsKey)
108
+ return;
109
+ this.stillsKey = key;
110
+ const holder = card.querySelector('.stills');
111
+ if (holder)
112
+ 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('');
113
+ }
114
+ render() { const card = this.shadowRoot?.querySelector('.card'); if (card) {
115
+ const mm = this.cardThicknessMm, count = this.stackCount, material = cardMaterial(this.getAttribute('material'));
116
+ card.style.setProperty('--mm', String(mm * count));
117
+ card.style.setProperty('--mm1', String(mm));
118
+ card.classList.toggle('stacked', count > 1);
119
+ if (material)
120
+ card.style.setProperty('--edge', material.edge);
121
+ else
122
+ card.style.removeProperty('--edge');
123
+ this.drawStills(card, count);
124
+ } const button = this.shadowRoot?.querySelector('.motion-button'); if (button) {
29
125
  button.hidden = this.getAttribute('motion') !== 'pan';
30
- const active = this.hasAttribute('playing');
31
- button.textContent = active ? '■ Stop' : '▶ Animate';
126
+ const active = this.isMoving;
127
+ this.toggleAttribute('moving', active);
32
128
  button.setAttribute('aria-pressed', String(active));
33
129
  } for (const key of FudaCard.observedAttributes) {
34
130
  const node = this.shadowRoot?.getElementById(key);
package/dist/index.d.ts CHANGED
@@ -10,11 +10,23 @@ 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; default 0.3, 0 for a flat card. */
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;
15
25
  flipped?: boolean;
16
26
  motion?: 'still' | 'pan';
17
27
  playing?: boolean;
28
+ /** `focus`: the card in focus animates its art (needs `motion: 'pan'`); never with reduced motion. */
29
+ autoplay?: 'focus';
18
30
  panDirection?: 'down' | 'up';
19
31
  panLoop?: 'alternate' | 'restart';
20
32
  cardSpin?: 'center' | 'corner';
@@ -23,3 +35,7 @@ export interface CardOptions {
23
35
  }
24
36
  export declare const cardVariants: readonly CardVariant[];
25
37
  export declare const cardFinishes: readonly CardFinish[];
38
+ export { cardMaterials, cardMaterial, stackPresets, stackHeightMm, mmPerPoint } from './materials.js';
39
+ export type { CardMaterial, CardMaterialGroup, CardMaterialSource, StackPreset } from './materials.js';
40
+ export { stackLayout } from './stack.js';
41
+ export type { StackPlace, StackLayoutOptions } from './stack.js';
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
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';
@@ -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
+ }
@@ -0,0 +1,28 @@
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
+ /**
25
+ * 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
+ * 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.
27
+ */
28
+ 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
+ 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
+ }
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/fuda-cards",
3
- "version": "0.2.1",
3
+ "version": "0.4.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,7 @@
34
34
  "docs/collection-displays.md",
35
35
  "docs/collection-input.md",
36
36
  "docs/framework-integration.md",
37
+ "docs/materials.md",
37
38
  "assets/README.md"
38
39
  ],
39
40
  "engines": {