@johnmorrisdotca/fuda-cards 0.5.0 → 0.6.1

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
@@ -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.
@@ -112,11 +112,17 @@ Open `demo/tcgdex.html` through the local server to browse the Pokémon Base Set
112
112
 
113
113
  ## Collection viewer
114
114
 
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`, 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
116
 
117
- **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.
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
118
 
119
- `@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`:
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) or `face-down` ("Turned over": it turns over sideways about its vertical axis, like turning a page, so the pile shows the card's `backImage`, or the package's own navy back when it has none). A card never lands with its picture on its head. The 0.6.0 value `upside-down` is still accepted and means `face-down`. 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.
120
+
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.
122
+
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`:
120
126
 
121
127
  ```html
122
128
  <script type="importmap">{"imports":{"@johnmorrisdotca/kazoku-ui/view-controls/define":"/node_modules/@johnmorrisdotca/kazoku-ui/dist/view-controls/define.js"}}</script>
@@ -136,6 +142,8 @@ These are early display prototypes: the case and rotating displays use CSS persp
136
142
 
137
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.
138
144
 
139
- 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.
140
148
 
141
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,39 @@ 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
+ /** How a card taken off lands: still facing up, or turned over sideways. The 0.6.0 value `upside-down` is still accepted and means turned over. */
26
+ private get land();
27
+ private get fanOpen();
17
28
  private get stacked();
18
29
  private q;
30
+ /** 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. */
31
+ private readAddress;
32
+ private writeAddress;
19
33
  private move;
20
34
  private image;
21
35
  private open;
22
36
  private renderDialog;
23
37
  private canDraw;
24
38
  private build;
39
+ /** 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. */
40
+ private pile;
41
+ private renderDeck;
42
+ /** The card that just moved flies between the two piles, turning over sideways on the way if it lands face down. The same element, so the card is never drawn twice. */
43
+ private playFlip;
44
+ private renderFan;
25
45
  private render;
26
46
  }
@@ -1,8 +1,15 @@
1
1
  import { collectionViews, parseCollection, randomDrawIndex, movePage } from './collection.js';
2
+ import { deckLandings, fanLayout, flight, normalizeLanding } from './pile.js';
2
3
  import { zoomView } from './zoom.js';
4
+ import { createChoice, CHOICE_CSS, CHOICE_VARS } from './choice.js';
5
+ import { stackLayout } from './stack.js';
3
6
  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}
7
+ :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}}
8
+ *{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}
9
+ 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}
10
+ button:focus-visible,input:focus-visible,.card:focus-visible{outline:3px solid var(--fc-focus);outline-offset:3px}${CHOICE_CSS}
11
+ .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}}
12
+ .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
13
  .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
14
  .stack .card{position:absolute;width:min(64vw,300px);height:86%;top:7%;left:50%;transition:transform .25s}
8
15
  .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 +18,36 @@ const STYLE = `<style>
11
18
  .story{display:flex;flex-direction:column;align-items:center;gap:1rem;padding:1rem}.story .card{width:min(75%,300px);flex:0 0 90%}
12
19
  .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
20
  .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}}
21
+ .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}
22
+ .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}
23
+ .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)}
24
+ .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}
25
+ .pile.discard[data-land=face-down] .card .turn{transform:rotateY(180deg)}
26
+ .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%}
27
+ 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}
28
+ @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
29
  </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>`;
30
+ 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
31
  const pages = ['binder', 'case'];
19
32
  const scrolling = ['wall', 'story', 'atlas'];
33
+ 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('');
34
+ const ICONS = {
35
+ 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"/>',
36
+ 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"/>',
37
+ binder: rects(3, 2, 9, 9, 11, 10, 2, 1),
38
+ case: '<path d="M3 4h28l-3 6H6z" opacity=".5"/><path d="M6 12h22l-3 8H9z"/>',
39
+ 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"/>',
40
+ 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"/>',
41
+ 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"/>',
42
+ 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"/>',
43
+ 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"/>',
44
+ 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"/>',
45
+ atlas: rects(4, 3, 6, 5.5, 8, 7, 2, 1),
46
+ 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('')
47
+ };
48
+ const icon = (view) => `<svg viewBox="0 0 34 22" aria-hidden="true">${ICONS[view]}</svg>`;
49
+ const reduced = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
50
+ const ADDRESS_KEYS = ['view', 'fan', 'land'];
20
51
  export class FudaCollection extends HTMLElement {
21
52
  root = this.attachShadow({ mode: 'open' });
22
53
  data = [];
@@ -26,21 +57,69 @@ export class FudaCollection extends HTMLElement {
26
57
  back = false;
27
58
  drawFilter = "";
28
59
  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(); }
60
+ tiles;
61
+ landing;
62
+ fanChoice;
63
+ flip = null;
64
+ addressTimer = 0;
65
+ static get observedAttributes() { return ['view', 'page-size', 'columns', 'fan', 'fan-size', 'deck-land', 'deck-messiness', 'deck-seed', 'theme']; }
66
+ 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
67
  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'); }
68
+ /** The card on top of the deck, or the first card of the page or fan (counting from 0). */
69
+ get position() { return this.index; }
70
+ connectedCallback() { if (this.hasAttribute('address'))
71
+ this.readAddress(); this.render(); }
72
+ disconnectedCallback() { clearTimeout(this.addressTimer); }
73
+ 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') {
74
+ this.index = 0;
75
+ this.flip = null;
76
+ } this.render(name === 'view'); }
34
77
  get currentView() { let v = this.getAttribute('view'); return collectionViews.some(x => x.id === v) ? v : 'deck'; }
78
+ /** How a card taken off lands: still facing up, or turned over sideways. The 0.6.0 value `upside-down` is still accepted and means turned over. */
79
+ get land() { return normalizeLanding(this.getAttribute('deck-land')); }
80
+ get fanOpen() { return this.getAttribute('fan') === 'open'; }
35
81
  get stacked() { return ![...pages, ...scrolling].includes(this.currentView); }
36
82
  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);
83
+ /** 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. */
84
+ readAddress() { try {
85
+ const params = new URLSearchParams(location.search);
86
+ for (const key of ADDRESS_KEYS) {
87
+ const value = params.get(key);
88
+ if (value === null)
89
+ continue;
90
+ const attr = key === 'land' ? 'deck-land' : key;
91
+ if (this.getAttribute(attr) !== value)
92
+ this.setAttribute(attr, value);
93
+ }
94
+ }
95
+ catch { } }
96
+ writeAddress() { if (!this.hasAttribute('address'))
97
+ return; clearTimeout(this.addressTimer); this.addressTimer = window.setTimeout(() => { try {
98
+ const url = new URL(location.href);
99
+ const want = { view: this.currentView === 'deck' ? null : this.currentView, fan: this.fanOpen ? 'open' : null, land: this.land === 'face-up' ? null : this.land };
100
+ for (const [k, v] of Object.entries(want)) {
101
+ if (v === null)
102
+ url.searchParams.delete(k);
103
+ else
104
+ url.searchParams.set(k, v);
105
+ }
106
+ history.replaceState(history.state, '', url);
107
+ }
108
+ catch { } }, 250); }
109
+ move(n) {
110
+ if (!this.data.length)
111
+ return;
112
+ const view = this.currentView;
113
+ if (pages.includes(view)) {
114
+ this.index = movePage(this.index, this.data.length, this.pageSize, n);
115
+ }
116
+ else {
117
+ const next = (this.index + n + this.data.length) % this.data.length;
118
+ this.flip = view === 'deck' && Math.abs(n) === 1 && next === this.index + n ? (n > 0 ? 'off' : 'back') : null;
119
+ this.index = next;
120
+ }
121
+ this.render();
40
122
  }
41
- else {
42
- this.index = (this.index + n + this.data.length) % this.data.length;
43
- } this.render(); }
44
123
  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
124
  open(c) { this.selected = c; this.back = false; this.renderDialog(); }
46
125
  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 +143,14 @@ export class FudaCollection extends HTMLElement {
64
143
  if (this.zoom)
65
144
  return;
66
145
  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);
146
+ 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(); } });
147
+ this.q('.displays').append(this.tiles.element);
148
+ this.landing = createChoice({ label: 'A card taken off lands', value: this.land, options: deckLandings.map(l => ({ value: l.id, label: l.label })), onChange: value => { this.setAttribute('deck-land', value); this.writeAddress(); } });
149
+ 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')
150
+ this.setAttribute('fan', 'open');
151
+ else
152
+ this.removeAttribute('fan'); this.writeAddress(); } });
153
+ this.q('.opts').append(this.landing.element, this.fanChoice.element);
70
154
  this.q('.prev').onclick = () => this.move(-1);
71
155
  this.q('.next').onclick = () => this.move(1);
72
156
  const input = this.q('.draw-filter input'), draw = this.q('.draw');
@@ -74,25 +158,136 @@ export class FudaCollection extends HTMLElement {
74
158
  draw.onclick = () => { const next = randomDrawIndex(this.data, this.index, this.drawFilter); if (next === null)
75
159
  return; this.index = next; this.render(); };
76
160
  const stage = this.q('.stage');
77
- this.zoom = zoomView(stage, this.q('.v'), { address: this.hasAttribute('address') });
161
+ this.zoom = zoomView(stage, this.q('.v'), { address: this.hasAttribute('address'), items: '.card,.slot', theme: this.getAttribute('theme') ?? undefined });
78
162
  let startX = 0;
79
163
  stage.addEventListener('touchstart', e => { if (e.touches.length === 1)
80
164
  startX = e.touches[0].clientX; }, { passive: true });
81
- stage.addEventListener('touchend', e => { if (!this.stacked || this.zoom.zoomed() || e.changedTouches.length !== 1)
165
+ stage.addEventListener('touchend', e => { if (!this.stacked || this.currentView === 'deck' || this.zoom.zoomed() || e.changedTouches.length !== 1)
82
166
  return; const dx = e.changedTouches[0].clientX - startX; if (Math.abs(dx) > 45) {
83
167
  if (e.cancelable)
84
168
  e.preventDefault();
85
169
  this.move(dx < 0 ? 1 : -1);
86
170
  } }, { passive: false });
87
- stage.addEventListener('keydown', (e) => { if (!this.stacked || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft'))
171
+ stage.addEventListener('keydown', (e) => { if (!this.stacked || this.currentView === 'deck' || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft'))
88
172
  return; e.preventDefault(); this.move(e.key === 'ArrowRight' ? 1 : -1); this.q('.stack .card:last-child')?.focus(); });
89
173
  }
174
+ /** 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. */
175
+ pile(kind, positions) {
176
+ const pile = document.createElement('div');
177
+ pile.className = `pile ${kind}-pile${kind === 'discard' ? ' discard' : ''}`;
178
+ pile.dataset.land = this.land;
179
+ const messy = Math.min(1, Math.max(0, Number(this.getAttribute('deck-messiness') ?? 0.3)));
180
+ const seed = Number(this.getAttribute('deck-seed') ?? 1) || 1;
181
+ const depth = Math.min(9, positions.length - 1);
182
+ const shown = positions.slice(positions.length - 1 - depth);
183
+ const places = stackLayout(positions.length, { messiness: messy, seed, depth: 9 });
184
+ shown.forEach((at, j) => {
185
+ const top = j === shown.length - 1, c = this.data[at], place = places[j];
186
+ const el = document.createElement('div');
187
+ el.className = `card${top ? ' top' : ''}`;
188
+ el.dataset.i = String(at);
189
+ if (place && !top) {
190
+ el.style.setProperty('--x', String(place.x));
191
+ el.style.setProperty('--y', String(place.y));
192
+ el.style.setProperty('--r', String(place.rotate));
193
+ }
194
+ el.style.setProperty('--k', String(j));
195
+ const fly = document.createElement('div');
196
+ fly.className = 'fly';
197
+ const turn = document.createElement('div');
198
+ turn.className = 'turn';
199
+ const front = document.createElement('div');
200
+ front.className = 'face front';
201
+ const img = document.createElement('img');
202
+ img.src = c.image;
203
+ img.alt = top ? c.name : '';
204
+ img.loading = 'lazy';
205
+ img.onerror = () => { img.replaceWith(document.createTextNode(`Image unavailable: ${c.name}`)); };
206
+ front.append(img);
207
+ const back = document.createElement('div');
208
+ back.className = 'face back';
209
+ if (c.backImage) {
210
+ const b = document.createElement('img');
211
+ b.src = c.backImage;
212
+ b.alt = '';
213
+ b.loading = 'lazy';
214
+ back.append(b);
215
+ }
216
+ else {
217
+ back.classList.add('generic-back');
218
+ back.textContent = 'FUDA';
219
+ }
220
+ turn.append(front, back);
221
+ fly.append(turn);
222
+ el.append(fly);
223
+ if (top) {
224
+ el.setAttribute('role', 'button');
225
+ el.tabIndex = 0;
226
+ el.setAttribute('aria-label', `Inspect ${c.name}`);
227
+ el.onclick = () => this.open(c);
228
+ el.onkeydown = e => { if (e.key === 'Enter' || e.key === ' ') {
229
+ e.preventDefault();
230
+ this.open(c);
231
+ } };
232
+ }
233
+ pile.append(el);
234
+ });
235
+ return pile;
236
+ }
237
+ renderDeck(v) {
238
+ const n = this.data.length, deckPositions = [], discardPositions = [];
239
+ // 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.
240
+ for (let p = 0; p < n - this.index; p++)
241
+ deckPositions.push(n - 1 - p);
242
+ for (let p = 0; p < this.index; p++)
243
+ discardPositions.push(p);
244
+ v.classList.add('deck');
245
+ const slot = () => { const s = document.createElement('div'); s.className = 'slot'; return s; };
246
+ // 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.
247
+ v.append(deckPositions.length ? this.pile('deck', deckPositions) : slot(), discardPositions.length ? this.pile('discard', discardPositions) : slot());
248
+ if (this.flip && !reduced() && n > 1)
249
+ this.playFlip(this.flip, v);
250
+ this.flip = null;
251
+ }
252
+ /** The card that just moved flies between the two piles, turning over sideways on the way if it lands face down. The same element, so the card is never drawn twice. */
253
+ playFlip(direction, v) {
254
+ const deck = v.querySelector('.deck-pile'), discard = v.querySelector('.discard-pile');
255
+ const moved = direction === 'off' ? discard?.querySelector('.card.top') : deck?.querySelector('.card.top');
256
+ if (!moved || !deck || !discard)
257
+ return;
258
+ const dx = discard.offsetLeft - deck.offsetLeft, dy = discard.offsetTop - deck.offsetTop;
259
+ const fly = moved.querySelector('.fly'), turn = moved.querySelector('.turn');
260
+ const from = direction === 'off' ? { x: -dx, y: -dy } : { x: dx, y: dy };
261
+ flight(fly, turn, from, this.land, direction, 700);
262
+ }
263
+ renderFan(v) {
264
+ v.classList.add('fan');
265
+ v.classList.toggle('open', this.fanOpen);
266
+ const size = Math.min(20, Math.max(2, Math.floor(Number(this.getAttribute('fan-size')) || 10))), count = Math.min(size, this.data.length);
267
+ const places = fanLayout(count, Number(this.getAttribute('deck-seed') ?? 1) || 1);
268
+ places.forEach((p, i) => {
269
+ const c = this.data[(this.index + i) % this.data.length], el = this.image(c);
270
+ el.style.setProperty('--i', String(i));
271
+ el.style.setProperty('--n', String(count));
272
+ el.style.setProperty('--z', String(count - i));
273
+ el.style.setProperty('--a', String(p.angle));
274
+ el.style.setProperty('--x', String(p.x));
275
+ el.style.setProperty('--cr', String(p.closedAngle));
276
+ el.style.setProperty('--cx', String(p.closedX));
277
+ el.style.setProperty('--cy', String(p.closedY));
278
+ v.append(el);
279
+ });
280
+ }
90
281
  render(reset = false) {
91
282
  if (!this.isConnected)
92
283
  return;
93
284
  this.build();
94
285
  let view = this.currentView, stage = this.q('.stage'), v = this.q('.v');
95
- this.q('select').value = view;
286
+ this.tiles.set(view);
287
+ this.landing.set(this.land);
288
+ this.fanChoice.set(this.fanOpen ? 'open' : 'closed');
289
+ this.landing.hidden = view !== 'deck';
290
+ this.fanChoice.hidden = view !== 'fan';
96
291
  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
292
  for (const selector of ['.prev', '.next'])
98
293
  this.q(selector).disabled = !this.data.length;
@@ -106,9 +301,14 @@ export class FudaCollection extends HTMLElement {
106
301
  v.replaceChildren();
107
302
  v.style.removeProperty('--columns');
108
303
  this.zoom.minOpen = scrolling.includes(view) ? .5 : 0;
304
+ this.zoom.setTurnable(view === 'deck' && this.data.length > 0);
109
305
  if (!this.data.length) {
110
306
  v.innerHTML = '<p class="empty">No cards in this collection.</p>';
111
307
  }
308
+ else if (view === 'deck')
309
+ this.renderDeck(v);
310
+ else if (view === 'fan')
311
+ this.renderFan(v);
112
312
  else if (pages.includes(view)) {
113
313
  v.classList.add('grid', view);
114
314
  const columns = Math.min(10, Math.max(1, Math.floor(Number(this.getAttribute('columns')) || 3)));
@@ -1,5 +1,7 @@
1
+ export { fanLayout, deckLandings, normalizeLanding } from './pile.js';
2
+ export type { DeckLanding, FanPlace } from './pile.js';
1
3
  /** 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';
4
+ export type CollectionView = 'deck' | 'rolodex' | 'binder' | 'case' | 'jukebox' | 'random' | 'story' | 'wall' | 'tower' | 'spotlight' | 'atlas' | 'fan';
3
5
  export interface CollectionMetadata {
4
6
  set?: string;
5
7
  year?: number;
@@ -1,8 +1,9 @@
1
+ export { fanLayout, deckLandings, normalizeLanding } from './pile.js';
1
2
  export const collectionViews = [
2
3
  { id: 'deck', label: 'Overlapping Deck' }, { id: 'rolodex', label: 'Rolodex' }, { id: 'binder', label: 'Binder Pages' },
3
4
  { id: 'case', label: 'Convention Display Case' }, { id: 'jukebox', label: 'Jukebox Carousel' }, { id: 'random', label: 'Random Draw' },
4
5
  { id: 'story', label: 'Vertical Story Scroll' }, { id: 'wall', label: 'Sliding Gallery Wall' }, { id: 'tower', label: 'Flip Tower' },
5
- { id: 'spotlight', label: 'Spotlight Carousel' }, { id: 'atlas', label: 'Infinite Card Atlas' }
6
+ { id: 'spotlight', label: 'Spotlight Carousel' }, { id: 'atlas', label: 'Infinite Card Atlas' }, { id: 'fan', label: 'Fan of Cards' }
6
7
  ];
7
8
  export function parseCollection(value) {
8
9
  if (value && typeof value === 'object' && !Array.isArray(value) && 'cards' in value)
package/dist/pile.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * How a card taken off a pile lands on the pile at its side: still facing up, or turned over sideways (as a person turns a card, like a
3
+ * page) to show its back. `upside-down` was a 0.6.0 value that spun the picture half way round in its plane; it is still accepted and
4
+ * means `face-down`, so nothing breaks. A card never ends with its picture on its head.
5
+ */
6
+ export type DeckLanding = 'face-up' | 'face-down' | 'upside-down';
7
+ export declare const deckLandings: ReadonlyArray<{
8
+ id: 'face-up' | 'face-down';
9
+ label: string;
10
+ }>;
11
+ /** The landing a value means: `face-down` (also `upside-down` and `turned-over`) is turned over; anything else is still facing up. */
12
+ export declare function normalizeLanding(value: string | null | undefined): 'face-up' | 'face-down';
13
+ /** 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. */
14
+ export interface FanPlace {
15
+ angle: number;
16
+ x: number;
17
+ y: number;
18
+ closedAngle: number;
19
+ closedX: number;
20
+ closedY: number;
21
+ }
22
+ export declare function fanLayout(count: number, seed?: number): FanPlace[];
23
+ /**
24
+ * A card taken off a pile flies to the pile at its side, and turns over sideways on the way if it lands face down; coming back it
25
+ * does the same in reverse. `fly` carries the card across, `turn` carries the turn. `from` is how far the card is from where it ends.
26
+ */
27
+ export declare function flight(fly: HTMLElement, turn: HTMLElement, from: {
28
+ x: number;
29
+ y: number;
30
+ }, land: 'face-up' | 'face-down', direction: 'off' | 'back', ms: number): Animation[];
package/dist/pile.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * What every pile of cards shares: how a card taken off lands, how a fan lies, and how long things take.
3
+ *
4
+ * `<fuda-collection>` (the Overlapping Deck and the other displays that draw a pile) and `<fuda-card stack>` both use this one
5
+ * piece, so a pile fans open and closed, and a card comes off it and goes back, the same way everywhere.
6
+ */
7
+ import { stackLayout } from './stack.js';
8
+ export const deckLandings = [
9
+ { id: 'face-up', label: 'Still facing up' }, { id: 'face-down', label: 'Turned over' }
10
+ ];
11
+ /** The landing a value means: `face-down` (also `upside-down` and `turned-over`) is turned over; anything else is still facing up. */
12
+ export function normalizeLanding(value) {
13
+ return value === 'face-down' || value === 'upside-down' || value === 'turned-over' ? 'face-down' : 'face-up';
14
+ }
15
+ export function fanLayout(count, seed = 1) {
16
+ const n = Math.max(0, Math.floor(count));
17
+ if (!n)
18
+ return [];
19
+ const spread = Math.min(110, 11 * (n - 1)), step = n > 1 ? spread / (n - 1) : 0;
20
+ const nudge = stackLayout(n, { messiness: 0.25, seed, depth: n });
21
+ return Array.from({ length: n }, (_, i) => {
22
+ const under = i >= 1 ? nudge[i - 1] : undefined;
23
+ return {
24
+ angle: Math.round((-spread / 2 + i * step) * 100) / 100,
25
+ x: Math.round((i - (n - 1) / 2) * 0.34 * 1000) / 1000,
26
+ y: 0,
27
+ closedAngle: under ? under.rotate / 3 : 0,
28
+ closedX: under ? under.x : 0,
29
+ closedY: under ? under.y : 0
30
+ };
31
+ });
32
+ }
33
+ /**
34
+ * A card taken off a pile flies to the pile at its side, and turns over sideways on the way if it lands face down; coming back it
35
+ * does the same in reverse. `fly` carries the card across, `turn` carries the turn. `from` is how far the card is from where it ends.
36
+ */
37
+ export function flight(fly, turn, from, land, direction, ms) {
38
+ const options = { duration: ms, easing: 'cubic-bezier(.3,.1,.2,1)' };
39
+ const out = [fly.animate([
40
+ { transform: `translate3d(${from.x}px,${from.y}px,0)` },
41
+ { transform: `translate3d(${from.x / 2}px,${from.y / 2 - 34}px,80px) scale(1.07)`, offset: 0.5 },
42
+ { transform: 'translate3d(0,0,0)' }
43
+ ], options)];
44
+ if (land === 'face-down')
45
+ out.push(turn.animate(direction === 'off' ? [{ transform: 'none' }, { transform: 'rotateY(180deg)' }] : [{ transform: 'rotateY(180deg)' }, { transform: 'none' }], options));
46
+ return out;
47
+ }
package/dist/zoom.d.ts CHANGED
@@ -3,6 +3,8 @@ interface ViewState {
3
3
  zoom: number;
4
4
  panX: number;
5
5
  panY: number;
6
+ yaw?: number;
7
+ tilt?: number;
6
8
  }
7
9
  export interface ZoomControls extends HTMLElement {
8
10
  readonly state: ViewState;
@@ -11,6 +13,7 @@ export interface ZoomControls extends HTMLElement {
11
13
  };
12
14
  view: HTMLElement | undefined;
13
15
  set(next: Partial<ViewState>): void;
16
+ readonly turning?: boolean;
14
17
  setFitScale(scale: number): void;
15
18
  }
16
19
  export interface ZoomOptions {
@@ -20,6 +23,8 @@ export interface ZoomOptions {
20
23
  address?: boolean;
21
24
  /** Put the controls after this element instead of after the stage. */
22
25
  after?: Element;
26
+ /** The colour theme of the controls (`light` or `dark`); left out they follow the page. */
27
+ theme?: string;
23
28
  }
24
29
  export interface ZoomView {
25
30
  controls: ZoomControls;
@@ -30,6 +35,8 @@ export interface ZoomView {
30
35
  /** Go back to the opening view. */
31
36
  reset(): void;
32
37
  zoomed(): boolean;
38
+ /** Let the reader turn the view in 3D (angle, tilt, Auto-turn) or only zoom and move it. Off by default. */
39
+ setTurnable(on: boolean): void;
33
40
  }
34
41
  /**
35
42
  * Zoom, Fit and pan for a flat view. `stage` clips, `view` is its absolutely positioned child that holds the items and is
package/dist/zoom.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import '@johnmorrisdotca/kazoku-ui/view-controls/define';
2
2
  const MARGIN = 12;
3
3
  const ZOOMED = 1.05;
4
- const TAPPABLE = 'button:not(:disabled), a[href]';
4
+ const TAPPABLE = 'button:not(:disabled), a[href], [role=button]';
5
5
  /**
6
6
  * Zoom, Fit and pan for a flat view. `stage` clips, `view` is its absolutely positioned child that holds the items and is
7
7
  * moved and scaled. Fit shows every item at once; the reader's zoom and pan are never reset by a change of content.
@@ -12,7 +12,8 @@ export function zoomView(stage, view, options = {}) {
12
12
  controls.setAttribute('flat', '');
13
13
  controls.setAttribute('ignore', '');
14
14
  controls.setAttribute('zoom-min', '0.4');
15
- controls.setAttribute('theme', 'dark');
15
+ if (options.theme)
16
+ controls.setAttribute('theme', options.theme);
16
17
  if (options.address)
17
18
  controls.setAttribute('address', '');
18
19
  (options.after ?? stage).after(controls);
@@ -21,7 +22,8 @@ export function zoomView(stage, view, options = {}) {
21
22
  stage.addEventListener('dragstart', e => e.preventDefault());
22
23
  let box = { w: 0, h: 0, cx: 0, cy: 0, bw: 0, bh: 0 };
23
24
  let fit = 1;
24
- const self = { controls, minOpen: 0, refresh, reset: () => refresh(true), zoomed: () => controls.state.zoom > ZOOMED };
25
+ let turnable = false;
26
+ const self = { controls, minOpen: 0, refresh, reset: () => refresh(true), zoomed: () => controls.state.zoom > ZOOMED, setTurnable };
25
27
  function measure() {
26
28
  const previous = view.style.transform;
27
29
  view.style.transform = 'none';
@@ -50,7 +52,17 @@ export function zoomView(stage, view, options = {}) {
50
52
  function draw(state) {
51
53
  const scale = fit * state.zoom;
52
54
  view.style.transformOrigin = `${box.cx}px ${box.cy}px`;
53
- view.style.transform = `translate(${box.w / 2 - box.cx + state.panX}px,${box.h / 2 - box.cy + state.panY}px) scale(${scale})`;
55
+ const turn = turnable ? ` rotateX(${state.tilt ?? 0}deg) rotateY(${state.yaw ?? 0}deg)` : '';
56
+ view.style.transform = `translate(${box.w / 2 - box.cx + state.panX}px,${box.h / 2 - box.cy + state.panY}px) scale(${scale})${turn}`;
57
+ }
58
+ function setTurnable(on) {
59
+ if (on === turnable)
60
+ return;
61
+ turnable = on;
62
+ if (!on)
63
+ controls.set({ yaw: 0, tilt: 0 });
64
+ controls.toggleAttribute('flat', !on);
65
+ draw(controls.state);
54
66
  }
55
67
  function refresh(open = false) {
56
68
  measure();
@@ -1,6 +1,13 @@
1
1
  # Collection displays
2
2
 
3
- Fuda supplies reusable frames for a caller's cards and reusable ways to display collections on websites. The hosting site supplies the card data and artwork or interactive content. Initial versions of eleven layouts now exist in `<fuda-collection>`. They are prototypes; the detailed capabilities below remain design goals unless described as implemented in the README.
3
+ Fuda supplies reusable frames for a caller's cards and reusable ways to display collections on websites. The hosting site supplies the card data and artwork or interactive content. Initial versions of twelve layouts now exist in `<fuda-collection>`. They are prototypes; the detailed capabilities below remain design goals unless described as implemented in the README.
4
+
5
+ ## Choosing a display, the deck and the fan (0.6.0)
6
+
7
+ - **Display buttons.** All twelve displays are buttons on screen at once, in a row that spans the width, each with a small picture of its layout. No drop-down. At least 48 px high; 4 to a row on a phone, 6 on a desk; arrow keys move the choice; light and dark follow the reader.
8
+ - **Deck.** A deck and a pile. Next flips the top card off to the pile on the deck's other side, Previous brings it back. The landing is a choice: still facing up, or turned over (a sideways turn about the card's vertical axis, like turning a page, showing the back image or the package's own back). A card never lands with its picture on its head; the 0.6.0 value `upside-down` still works and means turned over. One element flies, so a card is never drawn twice. The deck turns in 3D with the angle, tilt and Auto-turn controls.
9
+ - **Fan.** `view="fan"`: the cards of the deck spread in an arc like a hand of playing cards (about half of each card shows) and close back to the squared-up deck, each card back where it started. The state is in the address (`?fan=open`).
10
+ - Not done: a fan or a pile inside `<fuda-card stack>` (those cards all carry the same picture), dealing more than one card at a time, a pile that fills up with the whole discard history (the pile shows the last ten).
4
11
 
5
12
  ## Zoom, Fit and move (every view)
6
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/fuda-cards",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Fuda Cards: collectible card frames for images and interactive 3D content.",
5
5
  "type": "module",
6
6
  "sideEffects": [