@johnmorrisdotca/fuda-cards 0.4.0 → 0.6.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
@@ -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:8000. `pnpm build` emits JavaScript and TypeScript declarations to `dist/`.
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
 
@@ -35,7 +35,7 @@ Collection presentation prototypes are available as a reusable `<fuda-collection
35
35
  A card never shows the art it is about to frame. Until the script has defined `<fuda-card>`, a browser draws your `<img>` at its natural size, so the whole picture flashes before it moves into the frame. Put this one line in the `<head>`, before the script and your own styles, and the card stays invisible while its box is already reserved at the card's size (nothing moves when it appears):
36
36
 
37
37
  ```html
38
- <style>fuda-card:where(:not(:defined)){display:inline-block;width:300px;aspect-ratio:2.5/3.5;overflow:hidden;visibility:hidden}fuda-collection:where(:not(:defined)){display:block;min-height:calc(var(--fuda-stage-height,clamp(300px,calc(100svh - 440px),620px)) + 200px)}</style>
38
+ <style>fuda-card:where(:not(:defined)){display:inline-block;width:300px;aspect-ratio:2.5/3.5;overflow:hidden;visibility:hidden}fuda-collection:where(:not(:defined)){display:block;min-height:calc(var(--fuda-stage-height,clamp(300px,calc(100svh - 440px),620px)) + 380px)}</style>
39
39
  ```
40
40
 
41
41
  It keeps `<fuda-card>` (300 px wide, 2.5:3.5, or whatever width your own rule gives it) and `<fuda-collection>` (the height of its view, `--fuda-stage-height`) in place. Once defined, the card also keeps the art invisible until the card has a size on screen and every slotted image has loaded, then fades it in (no fade with `prefers-reduced-motion`). Without the line the card still reveals the art only inside its frame after it is defined, but the browser may show the raw picture until your script runs. If scripts never run, the card stays blank; add `<noscript><style>fuda-card:not(:defined){visibility:visible}</style></noscript>` if you want the plain picture then.
@@ -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.
@@ -102,11 +112,17 @@ Open `demo/tcgdex.html` through the local server to browse the Pokémon Base Set
102
112
 
103
113
  ## Collection viewer
104
114
 
105
- Run `pnpm dev` and open `/demo/collections-component.html`. Import `@johnmorrisdotca/fuda-cards/collection-element` to register the element, then set its `cards` property to an array of `{ id, name, image, backImage? }`. Image URLs are loaded by the viewer's browser. `id` is optional on input (the position is used if omitted); IDs must be unique. Set `view` to `deck`, `rolodex`, `binder`, `case`, `jukebox`, `random`, `story`, `wall`, `tower`, `spotlight`, or `atlas`. Set `page-size` for the binder and case (1–100 cards) and `columns` (1–10) for their grid; small screens use at most two columns. In random view, filter card names to limit the draw; the draw button is disabled when no cards match.
115
+ Run `pnpm dev` and open `/demo/collections-component.html`. Import `@johnmorrisdotca/fuda-cards/collection-element` to register the element, then set its `cards` property to an array of `{ id, name, image, backImage? }`. Image URLs are loaded by the viewer's browser. `id` is optional on input (the position is used if omitted); IDs must be unique. Set `view` to `deck`, `rolodex`, `binder`, `case`, `jukebox`, `random`, `story`, `wall`, `tower`, `spotlight`, `atlas` or `fan`. Set `page-size` for the binder and case (1–100 cards) and `columns` (1–10) for their grid; small screens use at most two columns. In random view, filter card names to limit the draw; the draw button is disabled when no cards match.
116
+
117
+ **Choosing a display.** The twelve displays are a row of buttons across the top, each with a small picture of its layout and its name, at least 48 px high, one chosen, wrapping on a phone (4 to a row, 6 on a desk). It is a radio group: one tab stop, the arrow keys move the choice. There is no drop-down. The colours follow the reader's light or dark setting; set `theme="light"` or `theme="dark"` to choose for them.
118
+
119
+ **The deck.** `view="deck"` draws a deck of up to ten cards (with a seeded, slightly messy lie: `deck-messiness` 0 to 1, default 0.3, and `deck-seed`) and, beside it, a pile. **Next** flips the top card off the deck: it lifts, flies across and lands on the pile at the deck's other side; **Previous** brings it back. Where it lands is a choice: `deck-land="face-up"` (still facing up, the default), `upside-down` (it spins half way round in its plane) or `face-down` (it turns over about its vertical axis, so the pile shows the card's `backImage`, or the package's own navy back when it has none). The same card element flies, so a card is never drawn twice; with reduced motion it moves without flying. **Rotate the deck**: the deck's view controls have the angle, tilt and Auto-turn (the other displays are flat), and the whole table, both piles, turns in 3D: seen from behind you see the backs of the deck and the faces of a face-down pile.
106
120
 
107
- **Zoom, Fit and move in every view.** Under each view sit the `@johnmorrisdotca/kazoku-ui` view controls: **−**, **2×**, **+** and **Fit**, and, once zoomed in, four arrows to move the view. Ctrl or Command with the wheel (or a trackpad pinch) and a two-finger pinch zoom about the pointer; zoomed in, a drag or the wheel moves the view, even when the drag starts on a card; the keys `+`, `−` and `0` work with the view focused. **Fit** shows every card the view draws (the whole binder or case page, every card of the wall, the story and the atlas). The wall, story and atlas open at half size or larger so a card can be read, and the others open at Fit. A tap or click on a card still opens it, and zooming, moving or paging never resets the other: turning to the next card or page keeps your zoom, and zooming keeps the card or page you are on. No view turns in 3D, so all eleven use zoom and move only. Nothing animates the zoom, so reduced motion needs no special case. Add the boolean `address` attribute to keep the zoom in the page address (`?zoom=2`). Set `--fuda-stage-height` on the element to change the height of the view (default: the window height less 440 px, between 300 and 620 px) so the controls stay on screen.
121
+ **The fan.** `view="fan"` fans the cards out like a hand of playing cards: `fan="open"` spreads up to ten (`fan-size`, 2 to 20) in an arc so that about half of each card shows, and without it the same cards are squared up into the deck they started as. Opening and closing animate every card in turn (none with reduced motion), and closing puts each card back exactly where it started. The Open fan and Closed deck buttons under the view, or the attribute, do it.
108
122
 
109
- `@johnmorrisdotca/kazoku-ui` is a runtime dependency of the package (it was a development dependency until 0.2.0). A bundler resolves it. On a plain HTML page without a bundler, add an import map next to the module script, with the package served from `node_modules` or a copy of its `dist`:
123
+ **Zoom, Fit and move in every view.** Under each view sit the `@johnmorrisdotca/kazoku-ui` view controls: **−**, **2×**, **+** and **Fit**, and, once zoomed in, four arrows to move the view. Ctrl or Command with the wheel (or a trackpad pinch) and a two-finger pinch zoom about the pointer; zoomed in, a drag or the wheel moves the view, even when the drag starts on a card; the keys `+`, `−` and `0` work with the view focused. **Fit** shows every card the view draws (the whole binder or case page, every card of the wall, the story and the atlas). The wall, story and atlas open at half size or larger so a card can be read, and the others open at Fit. A tap or click on a card still opens it, and zooming, moving or paging never resets the other: turning to the next card or page keeps your zoom, and zooming keeps the card or page you are on. The deck is the one view that also turns in 3D (see below); the other eleven use zoom and move only. Nothing animates the zoom, so reduced motion needs no special case. Add the boolean `address` attribute to keep the zoom, the display, the fan and the landing in the page address (`?view=fan&fan=open&land=face-down&zoom=2`); a link to it opens the same view. Set `--fuda-stage-height` on the element to change the height of the view (default: the window height less 440 px, between 300 and 620 px) so the controls stay on screen.
124
+
125
+ `@johnmorrisdotca/kazoku-ui` is a runtime dependency of the package (it was a development dependency until 0.2.0). Choice buttons, the light and dark colours and the address are written in the package, because kazoku-ui has no shared part for them yet. A bundler resolves it. On a plain HTML page without a bundler, add an import map next to the module script, with the package served from `node_modules` or a copy of its `dist`:
110
126
 
111
127
  ```html
112
128
  <script type="importmap">{"imports":{"@johnmorrisdotca/kazoku-ui/view-controls/define":"/node_modules/@johnmorrisdotca/kazoku-ui/dist/view-controls/define.js"}}</script>
@@ -126,6 +142,8 @@ These are early display prototypes: the case and rotating displays use CSS persp
126
142
 
127
143
  Saved demo collections are scoped to the selected profile. Use “Import older saved collections” to copy pre-profile saves without overwriting same-named collections; the originals remain intact. The demo supports JSON export and deletion, and storage stays local to this browser.
128
144
 
129
- The collection component demo includes three fictional demo users—Alex, Sam, and Riley—with different example collections. Select a user to switch the displayed cards. These are local demo profiles, not accounts; the existing named-collection save/load remains local to the browser and separate from the demo profiles.
145
+ `demo/vintage.html` shows real 1909 to 1911 hockey and baseball cards whose pictures are in the public domain (Wikimedia Commons and The Met's Open Access, each card's rights checked one by one), loaded from their sources and never shipped; [docs/card-images.md](docs/card-images.md) says what card-picture sources exist, their terms and what was not used (no free hockey or baseball card API with pictures was found).
146
+
147
+ The collection component demo includes three fictional demo users—Alex, Sam, and Riley—with different example collections: Alex has 25 Base Set cards (a 5 by 5 page), Sam a pack of 10 and Riley 5 consoles. Select a user to switch the displayed cards. These are local demo profiles, not accounts; the existing named-collection save/load remains local to the browser and separate from the demo profiles.
130
148
 
131
149
  Development priorities and handoff notes: [feature roadmap](docs/feature-roadmap.md) · [work log](docs/work-log.md).
@@ -0,0 +1,38 @@
1
+ /**
2
+ * A row of buttons for choosing one of a few things, in place of a drop-down: every option is on screen at once, spans the
3
+ * width, is at least 48 px high, shows its choice clearly and wraps on a phone. It is a radio group: one tab stop, the arrow
4
+ * keys move the choice, and a screen reader hears "Display, Binder Pages, 3 of 12".
5
+ *
6
+ * Used by `<fuda-collection>` and by the demo pages. The colours come from CSS custom properties (`--fc-*`), with the
7
+ * defaults of the dark theme; `CHOICE_VARS` has both themes.
8
+ */
9
+ export interface ChoiceOption {
10
+ value: string;
11
+ label: string;
12
+ /** Inline SVG markup for a small picture above the label (decorative). */
13
+ icon?: string;
14
+ }
15
+ export interface ChoiceHandle {
16
+ readonly element: HTMLElement;
17
+ /** Choose a value without telling `onChange`. */
18
+ set(value: string): void;
19
+ get(): string;
20
+ /** Show or hide the whole group. */
21
+ hidden: boolean;
22
+ }
23
+ export interface ChoiceConfig {
24
+ label: string;
25
+ options: readonly ChoiceOption[];
26
+ value: string;
27
+ onChange(value: string): void;
28
+ /** `tiles` stacks the icon over the label; `row` (the default) puts them side by side. */
29
+ layout?: 'tiles' | 'row';
30
+ }
31
+ /** The colours, for the dark theme (the default) and the light one. */
32
+ export declare const CHOICE_VARS: {
33
+ readonly dark: "--fc-surface:#20212c;--fc-text:#f6f4f1;--fc-muted:#b9b6c4;--fc-btn:#353747;--fc-btn-border:#79798c;--fc-accent:#ffd27e;--fc-on-accent:#241a05;--fc-stage-1:#52495a;--fc-stage-2:#222330;--fc-focus:#ffd27e;--fc-dialog:#242632";
34
+ readonly light: "--fc-surface:#f3efe6;--fc-text:#231e18;--fc-muted:#5b5346;--fc-btn:#fffdf8;--fc-btn-border:#a99d86;--fc-accent:#6d4400;--fc-on-accent:#ffffff;--fc-stage-1:#ebe2d0;--fc-stage-2:#cdc1a9;--fc-focus:#6d4400;--fc-dialog:#fbf8f1";
35
+ };
36
+ export declare const CHOICE_CSS = ".choice{display:grid;gap:.4rem;min-width:0}.choice[hidden]{display:none}.choice-label{font:700 .75rem system-ui;letter-spacing:.08em;text-transform:uppercase;color:var(--fc-muted,#b9b6c4)}\n.choice-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(var(--choice-min,7.5rem),1fr));gap:.5rem}\n.choice-list button{display:flex;align-items:center;justify-content:center;gap:.5rem;min-height:48px;padding:.45rem .7rem;font:600 .9rem system-ui;line-height:1.15;text-align:center;color:var(--fc-text,#f6f4f1);background:var(--fc-btn,#353747);border:2px solid var(--fc-btn-border,#79798c);border-radius:.7rem;cursor:pointer;-webkit-tap-highlight-color:transparent;transition:background .15s,border-color .15s}\n.choice-list.tiles button{flex-direction:column;gap:.2rem;min-height:56px;font-size:.8rem}.choice-list button svg{width:34px;height:22px;flex:none;fill:currentColor;opacity:.9}\n.choice-list button:hover{border-color:var(--fc-accent,#ffd27e)}.choice-list button[aria-checked=true]{background:var(--fc-accent,#ffd27e);border-color:var(--fc-accent,#ffd27e);color:var(--fc-on-accent,#241a05);box-shadow:0 0 0 2px var(--fc-surface,#20212c),0 0 0 4px var(--fc-accent,#ffd27e)}\n.choice-list button:focus-visible{outline:3px solid var(--fc-focus,#ffd27e);outline-offset:3px}@media(prefers-reduced-motion:reduce){.choice-list button{transition:none}}";
37
+ /** Build the group. The caller puts `element` in the page and adds `CHOICE_CSS` once to the same root. */
38
+ export declare function createChoice(config: ChoiceConfig): ChoiceHandle;
package/dist/choice.js ADDED
@@ -0,0 +1,77 @@
1
+ /** The colours, for the dark theme (the default) and the light one. */
2
+ export const CHOICE_VARS = {
3
+ dark: '--fc-surface:#20212c;--fc-text:#f6f4f1;--fc-muted:#b9b6c4;--fc-btn:#353747;--fc-btn-border:#79798c;--fc-accent:#ffd27e;--fc-on-accent:#241a05;--fc-stage-1:#52495a;--fc-stage-2:#222330;--fc-focus:#ffd27e;--fc-dialog:#242632',
4
+ light: '--fc-surface:#f3efe6;--fc-text:#231e18;--fc-muted:#5b5346;--fc-btn:#fffdf8;--fc-btn-border:#a99d86;--fc-accent:#6d4400;--fc-on-accent:#ffffff;--fc-stage-1:#ebe2d0;--fc-stage-2:#cdc1a9;--fc-focus:#6d4400;--fc-dialog:#fbf8f1'
5
+ };
6
+ export const CHOICE_CSS = `.choice{display:grid;gap:.4rem;min-width:0}.choice[hidden]{display:none}.choice-label{font:700 .75rem system-ui;letter-spacing:.08em;text-transform:uppercase;color:var(--fc-muted,#b9b6c4)}
7
+ .choice-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(var(--choice-min,7.5rem),1fr));gap:.5rem}
8
+ .choice-list button{display:flex;align-items:center;justify-content:center;gap:.5rem;min-height:48px;padding:.45rem .7rem;font:600 .9rem system-ui;line-height:1.15;text-align:center;color:var(--fc-text,#f6f4f1);background:var(--fc-btn,#353747);border:2px solid var(--fc-btn-border,#79798c);border-radius:.7rem;cursor:pointer;-webkit-tap-highlight-color:transparent;transition:background .15s,border-color .15s}
9
+ .choice-list.tiles button{flex-direction:column;gap:.2rem;min-height:56px;font-size:.8rem}.choice-list button svg{width:34px;height:22px;flex:none;fill:currentColor;opacity:.9}
10
+ .choice-list button:hover{border-color:var(--fc-accent,#ffd27e)}.choice-list button[aria-checked=true]{background:var(--fc-accent,#ffd27e);border-color:var(--fc-accent,#ffd27e);color:var(--fc-on-accent,#241a05);box-shadow:0 0 0 2px var(--fc-surface,#20212c),0 0 0 4px var(--fc-accent,#ffd27e)}
11
+ .choice-list button:focus-visible{outline:3px solid var(--fc-focus,#ffd27e);outline-offset:3px}@media(prefers-reduced-motion:reduce){.choice-list button{transition:none}}`;
12
+ /** Build the group. The caller puts `element` in the page and adds `CHOICE_CSS` once to the same root. */
13
+ export function createChoice(config) {
14
+ const element = document.createElement('div');
15
+ element.className = 'choice';
16
+ const label = document.createElement('span');
17
+ label.className = 'choice-label';
18
+ label.textContent = config.label;
19
+ const list = document.createElement('div');
20
+ list.className = `choice-list${config.layout === 'tiles' ? ' tiles' : ''}`;
21
+ list.setAttribute('role', 'radiogroup');
22
+ list.setAttribute('aria-label', config.label);
23
+ let current = config.value;
24
+ const buttons = config.options.map((option) => {
25
+ const button = document.createElement('button');
26
+ button.type = 'button';
27
+ button.setAttribute('role', 'radio');
28
+ button.dataset.value = option.value;
29
+ button.innerHTML = `${option.icon ?? ''}<span>${option.label.replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' })[c])}</span>`;
30
+ button.addEventListener('click', () => choose(option.value, true));
31
+ return button;
32
+ });
33
+ function mark() {
34
+ buttons.forEach((button) => {
35
+ const on = button.dataset.value === current;
36
+ button.setAttribute('aria-checked', String(on));
37
+ button.tabIndex = on ? 0 : -1;
38
+ });
39
+ if (!buttons.some((b) => b.tabIndex === 0) && buttons[0])
40
+ buttons[0].tabIndex = 0;
41
+ }
42
+ function choose(value, notify) {
43
+ const changed = value !== current;
44
+ current = value;
45
+ mark();
46
+ if (notify && changed)
47
+ config.onChange(value);
48
+ }
49
+ list.addEventListener('keydown', (event) => {
50
+ const at = buttons.findIndex((b) => b.dataset.value === current);
51
+ let next = -1;
52
+ if (event.key === 'ArrowRight' || event.key === 'ArrowDown')
53
+ next = (at + 1) % buttons.length;
54
+ else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp')
55
+ next = (at - 1 + buttons.length) % buttons.length;
56
+ else if (event.key === 'Home')
57
+ next = 0;
58
+ else if (event.key === 'End')
59
+ next = buttons.length - 1;
60
+ if (next < 0)
61
+ return;
62
+ event.preventDefault();
63
+ event.stopPropagation();
64
+ choose(buttons[next].dataset.value, true);
65
+ buttons[next].focus();
66
+ });
67
+ list.append(...buttons);
68
+ element.append(label, list);
69
+ mark();
70
+ return {
71
+ element,
72
+ set: (value) => choose(value, false),
73
+ get: () => current,
74
+ get hidden() { return element.hidden; },
75
+ set hidden(value) { element.hidden = value; }
76
+ };
77
+ }
@@ -8,19 +8,38 @@ export declare class FudaCollection extends HTMLElement {
8
8
  private back;
9
9
  private drawFilter;
10
10
  private zoom;
11
+ private tiles?;
12
+ private landing?;
13
+ private fanChoice?;
14
+ private flip;
15
+ private addressTimer;
11
16
  static get observedAttributes(): string[];
12
17
  set cards(value: CollectionCard[]);
13
18
  get cards(): CollectionCard[];
19
+ /** The card on top of the deck, or the first card of the page or fan (counting from 0). */
20
+ get position(): number;
14
21
  connectedCallback(): void;
22
+ disconnectedCallback(): void;
15
23
  attributeChangedCallback(name: string): void;
16
24
  private get currentView();
25
+ private get land();
26
+ private get fanOpen();
17
27
  private get stacked();
18
28
  private q;
29
+ /** With `address`, the display, the fan and the landing are kept in the page's address (`?view=fan&fan=open&land=face-down`), and a link to it opens the same. */
30
+ private readAddress;
31
+ private writeAddress;
19
32
  private move;
20
33
  private image;
21
34
  private open;
22
35
  private renderDialog;
23
36
  private canDraw;
24
37
  private build;
38
+ /** One pile of the deck. `positions` are data indexes from the bottom of the pile to its top; the cards under the top one lie nudged and turned from the seed and the top one lies square. */
39
+ private pile;
40
+ private renderDeck;
41
+ /** The card that just moved flies between the two piles, turning over on the way if it lands face down (or spinning if it lands upside down). The same element, so the card is never drawn twice. */
42
+ private playFlip;
43
+ private renderFan;
25
44
  private render;
26
45
  }
@@ -1,8 +1,14 @@
1
- import { collectionViews, parseCollection, randomDrawIndex, movePage } from './collection.js';
1
+ import { collectionViews, deckLandings, fanLayout, parseCollection, randomDrawIndex, movePage } from './collection.js';
2
2
  import { zoomView } from './zoom.js';
3
+ import { createChoice, CHOICE_CSS, CHOICE_VARS } from './choice.js';
4
+ import { stackLayout } from './stack.js';
3
5
  const STYLE = `<style>
4
- :host{display:block;color:#f6f4f1;font:16px system-ui}*{box-sizing:border-box}.shell{background:#20212c;padding:1rem;border-radius:1rem}header,.nav{display:flex;gap:.6rem;align-items:center;justify-content:center;flex-wrap:wrap}button,select{font:inherit;color:inherit;background:#353747;border:1px solid #79798c;border-radius:.5rem;padding:.55rem .8rem;cursor:pointer}button:focus-visible,select:focus-visible{outline:3px solid #ffd27e}
5
- .stage{position:relative;height:var(--fuda-stage-height,clamp(300px,calc(100svh - 440px),620px));overflow:hidden;border-radius:1rem;margin:1rem 0 .5rem;background:radial-gradient(ellipse,#52495a,#222330 68%)}.stage:focus-visible{outline:3px solid #ffd27e;outline-offset:2px}.v{position:absolute;inset:0}kazoku-view-controls{display:block;margin-bottom:.75rem}
6
+ :host{display:block;${CHOICE_VARS.dark};color:var(--fc-text);font:16px system-ui}@media(prefers-color-scheme:light){:host(:not([theme="dark"])){${CHOICE_VARS.light}}}:host([theme="light"]){${CHOICE_VARS.light}}:host([theme="dark"]){${CHOICE_VARS.dark}}
7
+ *{box-sizing:border-box}.shell{background:var(--fc-surface);padding:1rem;border-radius:1rem;display:grid;gap:.9rem}.nav{display:flex;gap:.6rem;align-items:center;justify-content:center;flex-wrap:wrap}.opts{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,18rem),1fr));gap:.9rem}.opts:not(:has(.choice:not([hidden]))){display:none}
8
+ button,input{font:inherit;color:inherit}.nav button,dialog button{min-height:48px;min-width:48px;background:var(--fc-btn);border:2px solid var(--fc-btn-border);border-radius:.7rem;padding:.5rem 1rem;cursor:pointer}.nav button:disabled{opacity:.45;cursor:default}.nav input{min-height:48px;background:var(--fc-btn);border:2px solid var(--fc-btn-border);border-radius:.7rem;padding:.5rem .8rem}
9
+ button:focus-visible,input:focus-visible,.card:focus-visible{outline:3px solid var(--fc-focus);outline-offset:3px}${CHOICE_CSS}
10
+ .displays .choice-list{grid-template-columns:repeat(3,minmax(0,1fr))}@media(min-width:340px){.displays .choice-list{grid-template-columns:repeat(4,minmax(0,1fr))}.displays .choice-list button{min-height:50px;padding:.3rem .25rem;font-size:.7rem}.displays .choice-list svg{width:28px;height:18px}}@media(min-width:800px){.displays .choice-list{grid-template-columns:repeat(6,minmax(0,1fr))}.displays .choice-list button{min-height:56px;padding:.45rem .7rem;font-size:.8rem}.displays .choice-list svg{width:34px;height:22px}}
11
+ .stage{position:relative;height:var(--fuda-stage-height,clamp(300px,calc(100svh - 440px),620px));overflow:hidden;border-radius:1rem;background:radial-gradient(ellipse,var(--fc-stage-1),var(--fc-stage-2) 68%)}.stage:focus-visible{outline:3px solid var(--fc-focus);outline-offset:2px}.v{position:absolute;inset:0}kazoku-view-controls{display:block}
6
12
  .card{padding:0;border:0;background:transparent;line-height:0}.card img{width:100%;height:100%;object-fit:contain;border-radius:5%;box-shadow:0 6px 16px #0009}
7
13
  .stack .card{position:absolute;width:min(64vw,300px);height:86%;top:7%;left:50%;transition:transform .25s}
8
14
  .grid{display:grid;grid-template-columns:repeat(var(--columns,3),minmax(0,1fr));gap:1rem;padding:1rem;align-content:start}.grid .card{height:clamp(130px,24vw,220px)}
@@ -11,12 +17,36 @@ const STYLE = `<style>
11
17
  .story{display:flex;flex-direction:column;align-items:center;gap:1rem;padding:1rem}.story .card{width:min(75%,300px);flex:0 0 90%}
12
18
  .plane{position:absolute;left:0;top:0;display:grid;gap:18px;grid-template-columns:repeat(var(--atlas-cols,5),140px);padding:30px}.plane .card{height:195px}
13
19
  .stage.jukebox{border:12px solid #aa7147;box-shadow:inset 0 0 20px #fbb579}.stage.spotlight{background:radial-gradient(ellipse at center,#e5ce99,#454054 40%,#171822 78%)}
14
- dialog{color:white;background:#242632;border:1px solid #777;border-radius:1rem;text-align:center;max-width:95vw;max-height:95vh}dialog::backdrop{background:#000c}.detail{display:block;height:min(70vh,600px);max-width:80vw;object-fit:contain;margin:1rem auto}.empty{text-align:center;padding:3rem}
15
- @media(max-width:500px){.grid{grid-template-columns:repeat(min(2,var(--columns,3)),minmax(0,1fr))}}@media(prefers-reduced-motion:reduce){*{transition:none!important}}
20
+ .stage.deck{perspective:1800px}.v.deck{--w:200px;display:flex;align-items:center;justify-content:center;gap:56px;transform-style:preserve-3d}.pile,.slot{position:relative;flex:none;width:var(--w);aspect-ratio:2.5/3.5;transform-style:preserve-3d}.slot{border:2px dashed var(--fc-btn-border);border-radius:5%;opacity:.55}
21
+ .pile .card{position:absolute;inset:0;display:block;transform-style:preserve-3d;transform:translate3d(calc(var(--x,0) * var(--w)),calc(var(--y,0) * var(--w)),calc(var(--k,0) * .9px)) rotate(calc(var(--r,0) * 1deg))}.pile .card:not(.top){pointer-events:none}.pile .card.top{cursor:pointer}
22
+ .fly,.turn{position:absolute;inset:0;transform-style:preserve-3d}.face{position:absolute;inset:0;backface-visibility:hidden;-webkit-backface-visibility:hidden;border-radius:5%;overflow:hidden}.face img{display:block;width:100%;height:100%;object-fit:contain;border-radius:3%;box-shadow:0 4px 10px #0008}.face.back{transform:rotateY(180deg)}
23
+ .generic-back{display:grid;place-items:center;background:radial-gradient(ellipse at center,#b78745 0 12%,#152d46 13% 27%,#386988 28% 31%,#10233b 32% 62%,#d2b074 63% 66%,#182c45 67%);border:6px solid #b39158;color:#f7e9bf;font:bold 18px Georgia;letter-spacing:.12em;box-shadow:0 4px 10px #0008}
24
+ .pile.discard[data-land=face-down] .card .turn{transform:rotateY(180deg)}.pile.discard[data-land=upside-down] .card .turn{transform:rotate(180deg)}
25
+ .v.fan{--w:190px;display:grid;place-items:end center;padding-bottom:1rem}.fan .card{grid-area:1/1;position:relative;width:var(--w);aspect-ratio:2.5/3.5;height:auto;transform-origin:50% 165%;z-index:var(--z);transform:translate(calc(var(--cx) * var(--w)),calc(var(--cy) * var(--w))) rotate(calc(var(--cr) * 1deg));transition:transform .7s cubic-bezier(.2,.8,.2,1);transition-delay:calc((var(--n) - var(--i)) * 22ms)}.fan.open .card{transform:translate(calc(var(--x) * var(--w)),0) rotate(calc(var(--a) * 1deg));transition-delay:calc(var(--i) * 28ms)}.fan.open .card:hover,.fan.open .card:focus-visible{translate:0 -14px}.fan .card img{border-radius:6%}
26
+ dialog{color:var(--fc-text);background:var(--fc-dialog);border:1px solid var(--fc-btn-border);border-radius:1rem;text-align:center;max-width:95vw;max-height:95vh}dialog::backdrop{background:#000c}.detail{display:block;height:min(70vh,600px);max-width:80vw;object-fit:contain;margin:1rem auto}.empty{text-align:center;padding:3rem}
27
+ @media(max-width:600px){.stage{height:var(--fuda-stage-height,clamp(220px,calc(100svh - 570px),620px))}}@media(max-width:500px){.grid{grid-template-columns:repeat(min(2,var(--columns,3)),minmax(0,1fr))}.shell{padding:.7rem}.v.deck{--w:150px;gap:28px}.v.fan{--w:150px}}@media(prefers-reduced-motion:reduce){*{transition:none!important}}
16
28
  </style>`;
17
- const SHELL = `<section class="shell"><header><label>Display <select aria-label="Collection display"></select></label></header><div class="stage" tabindex="0" role="group" aria-label="Collection"><div class="v"></div></div><div class="nav"><button class="prev">← Previous</button><span class="count" aria-live="polite"></span><button class="next">Next →</button><label class="draw-filter" hidden>Filter cards <input type="search" aria-label="Filter cards for random draw"></label><button class="draw" hidden>Draw a card</button></div><dialog aria-label="Card detail"></dialog></section>`;
29
+ const SHELL = `<section class="shell"><div class="displays"></div><div class="stage" tabindex="0" role="group" aria-label="Collection"><div class="v"></div></div><div class="opts"></div><div class="nav"><button class="prev">← Previous</button><span class="count" aria-live="polite"></span><button class="next">Next →</button><label class="draw-filter" hidden>Filter cards <input type="search" aria-label="Filter cards for random draw"></label><button class="draw" hidden>Draw a card</button></div><dialog aria-label="Card detail"></dialog></section>`;
18
30
  const pages = ['binder', 'case'];
19
31
  const scrolling = ['wall', 'story', 'atlas'];
32
+ const rects = (cols, rows, w, h, gx, gy, x0 = 1, y0 = 1) => Array.from({ length: cols * rows }, (_, k) => `<rect x="${x0 + (k % cols) * gx}" y="${y0 + Math.floor(k / cols) * gy}" width="${w}" height="${h}" rx="1" opacity="${0.55 + ((k % cols + Math.floor(k / cols)) % 2) * 0.4}"/>`).join('');
33
+ const ICONS = {
34
+ deck: '<rect x="9" y="4" width="14" height="14" rx="2" opacity=".45"/><rect x="6" y="2" width="14" height="14" rx="2" opacity=".7"/><rect x="3" y="0" width="14" height="14" rx="2"/>',
35
+ rolodex: '<rect x="2" y="9" width="12" height="10" rx="1.5" opacity=".4"/><rect x="8" y="5" width="12" height="10" rx="1.5" opacity=".7"/><rect x="14" y="1" width="12" height="10" rx="1.5"/>',
36
+ binder: rects(3, 2, 9, 9, 11, 10, 2, 1),
37
+ case: '<path d="M3 4h28l-3 6H6z" opacity=".5"/><path d="M6 12h22l-3 8H9z"/>',
38
+ jukebox: '<path d="M5 20V9a12 9 0 0 1 24 0v11z" opacity=".5"/><rect x="11" y="9" width="12" height="9" rx="1.5"/>',
39
+ random: '<rect x="9" y="1" width="16" height="18" rx="3"/><circle cx="14" cy="6" r="1.6" fill="#0008"/><circle cx="20" cy="14" r="1.6" fill="#0008"/><circle cx="17" cy="10" r="1.6" fill="#0008"/>',
40
+ story: '<rect x="11" y="0" width="12" height="7" rx="1.5"/><rect x="11" y="8" width="12" height="7" rx="1.5" opacity=".7"/><rect x="11" y="16" width="12" height="6" rx="1.5" opacity=".4"/>',
41
+ wall: '<rect x="0" y="3" width="9" height="14" rx="1.5" opacity=".5"/><rect x="12" y="3" width="10" height="14" rx="1.5"/><rect x="25" y="3" width="9" height="14" rx="1.5" opacity=".5"/>',
42
+ tower: '<rect x="9" y="1" width="16" height="4" rx="1"/><rect x="9" y="7" width="16" height="4" rx="1" opacity=".8"/><rect x="9" y="13" width="16" height="4" rx="1" opacity=".6"/><rect x="9" y="19" width="16" height="3" rx="1" opacity=".4"/>',
43
+ spotlight: '<rect x="11" y="0" width="12" height="18" rx="2"/><rect x="1" y="5" width="8" height="12" rx="1.5" opacity=".4"/><rect x="25" y="5" width="8" height="12" rx="1.5" opacity=".4"/>',
44
+ atlas: rects(4, 3, 6, 5.5, 8, 7, 2, 1),
45
+ fan: [-30, -15, 0, 15, 30].map((a, i) => `<rect x="14" y="1" width="7" height="13" rx="1.2" transform="rotate(${a} 17.5 21)" opacity="${0.45 + i * 0.1}"/>`).join('')
46
+ };
47
+ const icon = (view) => `<svg viewBox="0 0 34 22" aria-hidden="true">${ICONS[view]}</svg>`;
48
+ const reduced = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
49
+ const ADDRESS_KEYS = ['view', 'fan', 'land'];
20
50
  export class FudaCollection extends HTMLElement {
21
51
  root = this.attachShadow({ mode: 'open' });
22
52
  data = [];
@@ -26,21 +56,68 @@ export class FudaCollection extends HTMLElement {
26
56
  back = false;
27
57
  drawFilter = "";
28
58
  zoom = null;
29
- static get observedAttributes() { return ['view', 'page-size', 'columns']; }
30
- set cards(value) { this.data = parseCollection(value); this.index = Math.min(this.index, Math.max(0, this.data.length - 1)); this.render(); }
59
+ tiles;
60
+ landing;
61
+ fanChoice;
62
+ flip = null;
63
+ addressTimer = 0;
64
+ static get observedAttributes() { return ['view', 'page-size', 'columns', 'fan', 'fan-size', 'deck-land', 'deck-messiness', 'deck-seed', 'theme']; }
65
+ set cards(value) { this.data = parseCollection(value); this.index = Math.min(this.index, Math.max(0, this.data.length - 1)); this.flip = null; this.render(); }
31
66
  get cards() { return this.data.map(c => ({ ...c, ...(c.metadata ? { metadata: { ...c.metadata } } : {}) })); }
32
- connectedCallback() { this.render(); }
33
- attributeChangedCallback(name) { this.pageSize = Math.min(100, Math.max(1, Math.floor(Number(this.getAttribute('page-size')) || 9))); this.index = 0; this.render(name === 'view'); }
67
+ /** The card on top of the deck, or the first card of the page or fan (counting from 0). */
68
+ get position() { return this.index; }
69
+ connectedCallback() { if (this.hasAttribute('address'))
70
+ this.readAddress(); this.render(); }
71
+ disconnectedCallback() { clearTimeout(this.addressTimer); }
72
+ attributeChangedCallback(name) { this.pageSize = Math.min(100, Math.max(1, Math.floor(Number(this.getAttribute('page-size')) || 9))); if (name === 'view' || name === 'page-size' || name === 'columns') {
73
+ this.index = 0;
74
+ this.flip = null;
75
+ } this.render(name === 'view'); }
34
76
  get currentView() { let v = this.getAttribute('view'); return collectionViews.some(x => x.id === v) ? v : 'deck'; }
77
+ get land() { const v = this.getAttribute('deck-land'); return deckLandings.some(l => l.id === v) ? v : 'face-up'; }
78
+ get fanOpen() { return this.getAttribute('fan') === 'open'; }
35
79
  get stacked() { return ![...pages, ...scrolling].includes(this.currentView); }
36
80
  q(selector) { return this.root.querySelector(selector); }
37
- move(n) { if (!this.data.length)
38
- return; if (pages.includes(this.currentView)) {
39
- this.index = movePage(this.index, this.data.length, this.pageSize, n);
81
+ /** With `address`, the display, the fan and the landing are kept in the page's address (`?view=fan&fan=open&land=face-down`), and a link to it opens the same. */
82
+ readAddress() { try {
83
+ const params = new URLSearchParams(location.search);
84
+ for (const key of ADDRESS_KEYS) {
85
+ const value = params.get(key);
86
+ if (value === null)
87
+ continue;
88
+ const attr = key === 'land' ? 'deck-land' : key;
89
+ if (this.getAttribute(attr) !== value)
90
+ this.setAttribute(attr, value);
91
+ }
92
+ }
93
+ catch { } }
94
+ writeAddress() { if (!this.hasAttribute('address'))
95
+ return; clearTimeout(this.addressTimer); this.addressTimer = window.setTimeout(() => { try {
96
+ const url = new URL(location.href);
97
+ const want = { view: this.currentView === 'deck' ? null : this.currentView, fan: this.fanOpen ? 'open' : null, land: this.land === 'face-up' ? null : this.land };
98
+ for (const [k, v] of Object.entries(want)) {
99
+ if (v === null)
100
+ url.searchParams.delete(k);
101
+ else
102
+ url.searchParams.set(k, v);
103
+ }
104
+ history.replaceState(history.state, '', url);
105
+ }
106
+ catch { } }, 250); }
107
+ move(n) {
108
+ if (!this.data.length)
109
+ return;
110
+ const view = this.currentView;
111
+ if (pages.includes(view)) {
112
+ this.index = movePage(this.index, this.data.length, this.pageSize, n);
113
+ }
114
+ else {
115
+ const next = (this.index + n + this.data.length) % this.data.length;
116
+ this.flip = view === 'deck' && Math.abs(n) === 1 && next === this.index + n ? (n > 0 ? 'off' : 'back') : null;
117
+ this.index = next;
118
+ }
119
+ this.render();
40
120
  }
41
- else {
42
- this.index = (this.index + n + this.data.length) % this.data.length;
43
- } this.render(); }
44
121
  image(c) { let button = document.createElement('button'); button.className = 'card'; button.setAttribute('aria-label', `Inspect ${c.name}`); let img = document.createElement('img'); img.src = c.image; img.alt = c.name; img.loading = 'lazy'; img.onerror = () => { img.replaceWith(document.createTextNode(`Image unavailable: ${c.name}`)); }; button.append(img); button.onclick = () => this.open(c); return button; }
45
122
  open(c) { this.selected = c; this.back = false; this.renderDialog(); }
46
123
  renderDialog() { let dlg = this.q('dialog'); dlg.replaceChildren(); let close = document.createElement('button'); close.textContent = 'Close'; close.onclick = () => dlg.close(); dlg.append(close); if (this.selected) {
@@ -64,9 +141,14 @@ export class FudaCollection extends HTMLElement {
64
141
  if (this.zoom)
65
142
  return;
66
143
  this.root.innerHTML = STYLE + SHELL;
67
- const select = this.q('select');
68
- collectionViews.forEach(v => select.add(new Option(v.label, v.id)));
69
- select.onchange = () => this.setAttribute('view', select.value);
144
+ this.tiles = createChoice({ label: 'Display', layout: 'tiles', value: this.currentView, options: collectionViews.map(v => ({ value: v.id, label: v.label, icon: icon(v.id) })), onChange: value => { this.setAttribute('view', value); this.writeAddress(); } });
145
+ this.q('.displays').append(this.tiles.element);
146
+ this.landing = createChoice({ label: 'A card flipped off the deck lands', value: this.land, options: deckLandings.map(l => ({ value: l.id, label: l.label })), onChange: value => { this.setAttribute('deck-land', value); this.writeAddress(); } });
147
+ this.fanChoice = createChoice({ label: 'Fan', value: this.fanOpen ? 'open' : 'closed', options: [{ value: 'closed', label: 'Closed deck' }, { value: 'open', label: 'Open fan' }], onChange: value => { if (value === 'open')
148
+ this.setAttribute('fan', 'open');
149
+ else
150
+ this.removeAttribute('fan'); this.writeAddress(); } });
151
+ this.q('.opts').append(this.landing.element, this.fanChoice.element);
70
152
  this.q('.prev').onclick = () => this.move(-1);
71
153
  this.q('.next').onclick = () => this.move(1);
72
154
  const input = this.q('.draw-filter input'), draw = this.q('.draw');
@@ -74,25 +156,140 @@ export class FudaCollection extends HTMLElement {
74
156
  draw.onclick = () => { const next = randomDrawIndex(this.data, this.index, this.drawFilter); if (next === null)
75
157
  return; this.index = next; this.render(); };
76
158
  const stage = this.q('.stage');
77
- this.zoom = zoomView(stage, this.q('.v'), { address: this.hasAttribute('address') });
159
+ this.zoom = zoomView(stage, this.q('.v'), { address: this.hasAttribute('address'), items: '.card,.slot', theme: this.getAttribute('theme') ?? undefined });
78
160
  let startX = 0;
79
161
  stage.addEventListener('touchstart', e => { if (e.touches.length === 1)
80
162
  startX = e.touches[0].clientX; }, { passive: true });
81
- stage.addEventListener('touchend', e => { if (!this.stacked || this.zoom.zoomed() || e.changedTouches.length !== 1)
163
+ stage.addEventListener('touchend', e => { if (!this.stacked || this.currentView === 'deck' || this.zoom.zoomed() || e.changedTouches.length !== 1)
82
164
  return; const dx = e.changedTouches[0].clientX - startX; if (Math.abs(dx) > 45) {
83
165
  if (e.cancelable)
84
166
  e.preventDefault();
85
167
  this.move(dx < 0 ? 1 : -1);
86
168
  } }, { passive: false });
87
- stage.addEventListener('keydown', (e) => { if (!this.stacked || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft'))
169
+ stage.addEventListener('keydown', (e) => { if (!this.stacked || this.currentView === 'deck' || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft'))
88
170
  return; e.preventDefault(); this.move(e.key === 'ArrowRight' ? 1 : -1); this.q('.stack .card:last-child')?.focus(); });
89
171
  }
172
+ /** One pile of the deck. `positions` are data indexes from the bottom of the pile to its top; the cards under the top one lie nudged and turned from the seed and the top one lies square. */
173
+ pile(kind, positions) {
174
+ const pile = document.createElement('div');
175
+ pile.className = `pile ${kind}-pile${kind === 'discard' ? ' discard' : ''}`;
176
+ pile.dataset.land = this.land;
177
+ const messy = Math.min(1, Math.max(0, Number(this.getAttribute('deck-messiness') ?? 0.3)));
178
+ const seed = Number(this.getAttribute('deck-seed') ?? 1) || 1;
179
+ const depth = Math.min(9, positions.length - 1);
180
+ const shown = positions.slice(positions.length - 1 - depth);
181
+ const places = stackLayout(positions.length, { messiness: messy, seed, depth: 9 });
182
+ shown.forEach((at, j) => {
183
+ const top = j === shown.length - 1, c = this.data[at], place = places[j];
184
+ const el = document.createElement('div');
185
+ el.className = `card${top ? ' top' : ''}`;
186
+ el.dataset.i = String(at);
187
+ if (place && !top) {
188
+ el.style.setProperty('--x', String(place.x));
189
+ el.style.setProperty('--y', String(place.y));
190
+ el.style.setProperty('--r', String(place.rotate));
191
+ }
192
+ el.style.setProperty('--k', String(j));
193
+ const fly = document.createElement('div');
194
+ fly.className = 'fly';
195
+ const turn = document.createElement('div');
196
+ turn.className = 'turn';
197
+ const front = document.createElement('div');
198
+ front.className = 'face front';
199
+ const img = document.createElement('img');
200
+ img.src = c.image;
201
+ img.alt = top ? c.name : '';
202
+ img.loading = 'lazy';
203
+ img.onerror = () => { img.replaceWith(document.createTextNode(`Image unavailable: ${c.name}`)); };
204
+ front.append(img);
205
+ const back = document.createElement('div');
206
+ back.className = 'face back';
207
+ if (c.backImage) {
208
+ const b = document.createElement('img');
209
+ b.src = c.backImage;
210
+ b.alt = '';
211
+ b.loading = 'lazy';
212
+ back.append(b);
213
+ }
214
+ else {
215
+ back.classList.add('generic-back');
216
+ back.textContent = 'FUDA';
217
+ }
218
+ turn.append(front, back);
219
+ fly.append(turn);
220
+ el.append(fly);
221
+ if (top) {
222
+ el.setAttribute('role', 'button');
223
+ el.tabIndex = 0;
224
+ el.setAttribute('aria-label', `Inspect ${c.name}`);
225
+ el.onclick = () => this.open(c);
226
+ el.onkeydown = e => { if (e.key === 'Enter' || e.key === ' ') {
227
+ e.preventDefault();
228
+ this.open(c);
229
+ } };
230
+ }
231
+ pile.append(el);
232
+ });
233
+ return pile;
234
+ }
235
+ renderDeck(v) {
236
+ const n = this.data.length, deckPositions = [], discardPositions = [];
237
+ // The deck is the cards from the top card down (bottom first); the pile is the cards already flipped off, the last one on top.
238
+ for (let p = 0; p < n - this.index; p++)
239
+ deckPositions.push(n - 1 - p);
240
+ for (let p = 0; p < this.index; p++)
241
+ discardPositions.push(p);
242
+ v.classList.add('deck');
243
+ const slot = () => { const s = document.createElement('div'); s.className = 'slot'; return s; };
244
+ // The deck is on the left and the pile on its other side; an empty pile is a dashed slot, so Fit does not jump when the first card lands.
245
+ v.append(deckPositions.length ? this.pile('deck', deckPositions) : slot(), discardPositions.length ? this.pile('discard', discardPositions) : slot());
246
+ if (this.flip && !reduced() && n > 1)
247
+ this.playFlip(this.flip, v);
248
+ this.flip = null;
249
+ }
250
+ /** The card that just moved flies between the two piles, turning over on the way if it lands face down (or spinning if it lands upside down). The same element, so the card is never drawn twice. */
251
+ playFlip(direction, v) {
252
+ const deck = v.querySelector('.deck-pile'), discard = v.querySelector('.discard-pile');
253
+ const moved = direction === 'off' ? discard?.querySelector('.card.top') : deck?.querySelector('.card.top');
254
+ if (!moved || !deck || !discard)
255
+ return;
256
+ const dx = discard.offsetLeft - deck.offsetLeft, dy = discard.offsetTop - deck.offsetTop;
257
+ const fly = moved.querySelector('.fly'), turn = moved.querySelector('.turn');
258
+ const from = direction === 'off' ? { x: -dx, y: -dy } : { x: dx, y: dy };
259
+ const options = { duration: 700, easing: 'cubic-bezier(.3,.1,.2,1)' };
260
+ fly.animate([{ transform: `translate3d(${from.x}px,${from.y}px,0)` }, { transform: `translate3d(${from.x / 2}px,${from.y / 2 - 34}px,80px) scale(1.07)`, offset: .5 }, { transform: 'translate3d(0,0,0)' }], options);
261
+ const land = this.land, final = land === 'face-down' ? 'rotateY(180deg)' : land === 'upside-down' ? 'rotate(180deg)' : 'none';
262
+ if (final !== 'none')
263
+ turn.animate(direction === 'off' ? [{ transform: 'none' }, { transform: final }] : [{ transform: final }, { transform: 'none' }], options);
264
+ }
265
+ renderFan(v) {
266
+ v.classList.add('fan');
267
+ v.classList.toggle('open', this.fanOpen);
268
+ const size = Math.min(20, Math.max(2, Math.floor(Number(this.getAttribute('fan-size')) || 10))), count = Math.min(size, this.data.length);
269
+ const places = fanLayout(count, Number(this.getAttribute('deck-seed') ?? 1) || 1);
270
+ places.forEach((p, i) => {
271
+ const c = this.data[(this.index + i) % this.data.length], el = this.image(c);
272
+ el.style.setProperty('--i', String(i));
273
+ el.style.setProperty('--n', String(count));
274
+ el.style.setProperty('--z', String(count - i));
275
+ el.style.setProperty('--a', String(p.angle));
276
+ el.style.setProperty('--x', String(p.x));
277
+ el.style.setProperty('--cr', String(p.closedAngle));
278
+ el.style.setProperty('--cx', String(p.closedX));
279
+ el.style.setProperty('--cy', String(p.closedY));
280
+ v.append(el);
281
+ });
282
+ }
90
283
  render(reset = false) {
91
284
  if (!this.isConnected)
92
285
  return;
93
286
  this.build();
94
287
  let view = this.currentView, stage = this.q('.stage'), v = this.q('.v');
95
- this.q('select').value = view;
288
+ this.tiles.set(view);
289
+ this.landing.set(this.land);
290
+ this.fanChoice.set(this.fanOpen ? 'open' : 'closed');
291
+ this.landing.hidden = view !== 'deck';
292
+ this.fanChoice.hidden = view !== 'fan';
96
293
  this.q('.count').textContent = this.data.length ? (pages.includes(view) ? `Page ${Math.floor(this.index / this.pageSize) + 1} / ${Math.ceil(this.data.length / this.pageSize)}` : `${this.index + 1} / ${this.data.length}`) : 'No cards';
97
294
  for (const selector of ['.prev', '.next'])
98
295
  this.q(selector).disabled = !this.data.length;
@@ -106,9 +303,14 @@ export class FudaCollection extends HTMLElement {
106
303
  v.replaceChildren();
107
304
  v.style.removeProperty('--columns');
108
305
  this.zoom.minOpen = scrolling.includes(view) ? .5 : 0;
306
+ this.zoom.setTurnable(view === 'deck' && this.data.length > 0);
109
307
  if (!this.data.length) {
110
308
  v.innerHTML = '<p class="empty">No cards in this collection.</p>';
111
309
  }
310
+ else if (view === 'deck')
311
+ this.renderDeck(v);
312
+ else if (view === 'fan')
313
+ this.renderFan(v);
112
314
  else if (pages.includes(view)) {
113
315
  v.classList.add('grid', view);
114
316
  const columns = Math.min(10, Math.max(1, Math.floor(Number(this.getAttribute('columns')) || 3)));
@@ -1,5 +1,5 @@
1
1
  /** Browser-native collection viewer. Import this module to register <fuda-collection>. */
2
- export type CollectionView = 'deck' | 'rolodex' | 'binder' | 'case' | 'jukebox' | 'random' | 'story' | 'wall' | 'tower' | 'spotlight' | 'atlas';
2
+ export type CollectionView = 'deck' | 'rolodex' | 'binder' | 'case' | 'jukebox' | 'random' | 'story' | 'wall' | 'tower' | 'spotlight' | 'atlas' | 'fan';
3
3
  export interface CollectionMetadata {
4
4
  set?: string;
5
5
  year?: number;
@@ -26,3 +26,19 @@ export declare function parseCollection(value: unknown): CollectionCard[];
26
26
  export declare function randomDrawIndex(cards: CollectionCard[], current: number, filter: string, random?: () => number): number | null;
27
27
  /** Return the first card index of a wrapped page. */
28
28
  export declare function movePage(index: number, length: number, pageSize: number, delta: number): number;
29
+ /** How a card flipped off the deck lands on the pile at its other side. */
30
+ export type DeckLanding = 'face-up' | 'upside-down' | 'face-down';
31
+ export declare const deckLandings: ReadonlyArray<{
32
+ id: DeckLanding;
33
+ label: string;
34
+ }>;
35
+ /** Where the cards of a fan lie, first card on the left when open and on top when closed. `open` is the fan spread like a hand of playing cards; `closed` is the squared-up deck it starts from and closes back to. */
36
+ export interface FanPlace {
37
+ angle: number;
38
+ x: number;
39
+ y: number;
40
+ closedAngle: number;
41
+ closedX: number;
42
+ closedY: number;
43
+ }
44
+ export declare function fanLayout(count: number, seed?: number): FanPlace[];