@johnmorrisdotca/fuda-cards 0.6.1 → 0.8.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.
@@ -1,35 +1,44 @@
1
- import { collectionViews, parseCollection, randomDrawIndex, movePage } from './collection.js';
2
- import { deckLandings, fanLayout, flight, normalizeLanding } from './pile.js';
1
+ import { collectionViewAliases, collectionViews, parseCollection, randomDrawIndex, movePage } from './collection.js';
2
+ import { BINDER_CSS, binderCovers, binderLayout, buildLeaf, buildSide, sideCount, spreadCount, spreadOf, spreadSides } from './binder.js';
3
+ import { deckLandings, fanBounds, fanLayout, fanShift, flight, normalizeLanding, timing } from './pile.js';
3
4
  import { zoomView } from './zoom.js';
4
5
  import { createChoice, CHOICE_CSS, CHOICE_VARS } from './choice.js';
5
6
  import { stackLayout } from './stack.js';
6
7
  const STYLE = `<style>
7
8
  :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
+ *{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%,13.5rem),1fr));gap:.9rem}.opts:not(:has(.choice:not([hidden]))){display:none}.opts .choice{--choice-min:4.6rem}
9
10
  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
+ button:focus-visible,input:focus-visible,.card:focus-visible{outline:3px solid var(--fc-focus);outline-offset:3px}${CHOICE_CSS}${BINDER_CSS}
11
12
  .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
13
  .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}
13
14
  .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}
14
15
  .stack .card{position:absolute;width:min(64vw,300px);height:86%;top:7%;left:50%;transition:transform .25s}
15
16
  .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)}
16
- .v.case{perspective:800px}.stage.case{background:linear-gradient(#615346,#222)}.case .card{transform:perspective(600px) rotateX(-15deg)}
17
+ .v.case{perspective:800px}.stage.case{background:linear-gradient(#4a3f33,#1d1914);border:10px solid #6b5436;box-shadow:inset 0 0 26px #000a}.stage.case::after{content:'';position:absolute;inset:0;pointer-events:none;z-index:2;background:linear-gradient(115deg,#ffffff30 0,#ffffff00 28%,#ffffff12 55%,#ffffff00 78%,#ffffff22 100%)}.case .card{transform:perspective(600px) rotateX(-15deg);box-shadow:0 12px 0 -3px #2c251d,0 18px 8px -4px #000a}.case .card img{box-shadow:0 4px 10px #0009}
17
18
  .wall{display:flex;gap:1rem;align-items:center;padding:1rem}.wall .card{height:90%;flex:0 0 190px}
18
19
  .story{display:flex;flex-direction:column;align-items:center;gap:1rem;padding:1rem}.story .card{width:min(75%,300px);flex:0 0 90%}
19
20
  .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}
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%)}
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}
21
+ .stage.spotlight{background:radial-gradient(ellipse at center,#e5ce99,#454054 40%,#171822 78%)}
22
+ .stage:is(.deck,.random,.fan){perspective:1800px}.v.deck{--w:200px;--gap:56px;--fl:0;--fr:0;--ft:0;--fb:0;--ease:cubic-bezier(.2,.8,.2,1);transform-style:preserve-3d}
23
+ .v.deck .pile,.v.deck .slot{position:absolute;left:50%;top:50%;width:var(--w);aspect-ratio:2.5/3.5;margin:calc(var(--w) * -.7) 0 0 calc(var(--w) * -.5);transform-style:preserve-3d}.slot{border:2px dashed var(--fc-btn-border);border-radius:5%;opacity:.55}
24
+ .v.deck .deck-pile{translate:calc(((var(--fl) - var(--fr) - 1) * var(--w) - var(--gap)) / 2) 0}.v.deck .discard-pile,.v.deck .slot{translate:calc(((var(--fl) + var(--fr) + 1) * var(--w) + var(--gap)) / 2) 0}.v.deck.fanonly .deck-pile{translate:calc((var(--fl) - var(--fr)) * var(--w) / 2) 0}
25
+ .v.deck .deck-pile,.v.deck .discard-pile,.v.deck .slot{transition:translate var(--t,0s) var(--ease)}
26
+ .extent{position:absolute;left:50%;top:50%;width:calc((var(--fl) + var(--fr) + 2) * var(--w) + var(--gap));height:calc((1.4 + var(--ft) + var(--fb)) * var(--w));translate:-50% calc(-50% + (var(--fb) - var(--ft)) * var(--w) / 2);visibility:hidden;pointer-events:none}.fanonly .extent{width:calc((var(--fl) + var(--fr) + 1) * var(--w))}
27
+ .pile .card{position:absolute;inset:0;display:block;transform-style:preserve-3d;transform-origin:50% 50%;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));transition:transform var(--t,0s) var(--ease),transform-origin var(--t,0s) var(--ease);transition-delay:calc(var(--j,0) * var(--stag,22ms))}.pile .card:not(.top){pointer-events:none}.pile .card.top{cursor:pointer}
28
+ .fan-open .deck-pile .card{transform-origin:50% 165%;transform:translate3d(calc(var(--fx,0) * var(--w)),0,calc(var(--k,0) * .9px)) rotate(calc(var(--fa,0) * 1deg));transition-delay:calc(var(--i,0) * var(--stag,28ms));pointer-events:auto;cursor:pointer}.fan-open .deck-pile .card:hover,.fan-open .deck-pile .card:focus-visible{translate:0 -14px}
23
29
  .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
30
  .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%}
31
+ .pile.discard[data-land=face-down] .card .turn{transform:rotateY(180deg)}.ghost{pointer-events:none}
27
32
  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}}
33
+ @media(max-width:600px){.stage{height:var(--fuda-stage-height,clamp(220px,calc(100svh - 570px),620px))}}@media(max-width:500px){.opts{grid-template-columns:repeat(2,minmax(0,1fr))}.opts .speed{grid-column:1/-1}.v.deck{--gap:28px}.grid{grid-template-columns:repeat(min(2,var(--columns,3)),minmax(0,1fr))}.shell{padding:.7rem}.v.deck{--w:150px}}@media(prefers-reduced-motion:reduce){*{transition:none!important}}
29
34
  </style>`;
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>`;
35
+ 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="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><div class="opts"></div><dialog aria-label="Card detail"></dialog></section>`;
31
36
  const pages = ['binder', 'case'];
32
37
  const scrolling = ['wall', 'story', 'atlas'];
38
+ /** The displays that draw a pile of cards: they turn in 3D, fan open and closed, and a card comes off them onto a pile at their side. The Fan of Cards is the same pile with only the fan. */
39
+ const pileViews = ['deck', 'random'];
40
+ /** The displays whose cards sit on top of each other: moving to another card glides the cards that stay and lets the one that leaves go. */
41
+ const gliding = ['rolodex', 'spotlight', 'fan'];
33
42
  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
43
  const ICONS = {
35
44
  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"/>',
@@ -46,8 +55,8 @@ const ICONS = {
46
55
  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
56
  };
48
57
  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'];
58
+ const ADDRESS_KEYS = ['view', 'fan', 'land', 'animate', 'speed', 'binder', 'cover', 'sheet', 'pockets'];
59
+ const NAMES = { land: 'deck-land' };
51
60
  export class FudaCollection extends HTMLElement {
52
61
  root = this.attachShadow({ mode: 'open' });
53
62
  data = [];
@@ -60,9 +69,14 @@ export class FudaCollection extends HTMLElement {
60
69
  tiles;
61
70
  landing;
62
71
  fanChoice;
72
+ animateChoice;
73
+ speedChoice;
74
+ binderChoices = {};
75
+ turn = null;
63
76
  flip = null;
64
77
  addressTimer = 0;
65
- static get observedAttributes() { return ['view', 'page-size', 'columns', 'fan', 'fan-size', 'deck-land', 'deck-messiness', 'deck-seed', 'theme']; }
78
+ fanPlaces = [];
79
+ static get observedAttributes() { return ['view', 'page-size', 'columns', 'fan', 'fan-size', 'deck-land', 'deck-messiness', 'deck-seed', 'theme', 'animate', 'speed', 'binder', 'cover', 'sheet', 'pockets']; }
66
80
  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(); }
67
81
  get cards() { return this.data.map(c => ({ ...c, ...(c.metadata ? { metadata: { ...c.metadata } } : {}) })); }
68
82
  /** The card on top of the deck, or the first card of the page or fan (counting from 0). */
@@ -70,24 +84,37 @@ export class FudaCollection extends HTMLElement {
70
84
  connectedCallback() { if (this.hasAttribute('address'))
71
85
  this.readAddress(); this.render(); }
72
86
  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'); }
77
- get currentView() { let v = this.getAttribute('view'); return collectionViews.some(x => x.id === v) ? v : 'deck'; }
87
+ attributeChangedCallback(name) {
88
+ this.pageSize = Math.min(100, Math.max(1, Math.floor(Number(this.getAttribute('page-size')) || 9)));
89
+ if (name === 'fan' && this.setFan())
90
+ return;
91
+ if (name === 'animate' || name === 'speed') {
92
+ this.timeVars();
93
+ this.syncChoices();
94
+ return;
95
+ }
96
+ if (name === 'view' || name === 'page-size' || name === 'columns') {
97
+ this.index = 0;
98
+ this.flip = null;
99
+ }
100
+ this.render(name === 'view', name === 'view' ? { kind: 'view', dir: 1 } : undefined);
101
+ }
102
+ get currentView() { let v = this.getAttribute('view') ?? ''; v = collectionViewAliases[v] ?? v; return collectionViews.some(x => x.id === v) ? v : 'deck'; }
78
103
  /** 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
104
  get land() { return normalizeLanding(this.getAttribute('deck-land')); }
80
105
  get fanOpen() { return this.getAttribute('fan') === 'open'; }
81
106
  get stacked() { return ![...pages, ...scrolling].includes(this.currentView); }
107
+ get piled() { return pileViews.includes(this.currentView); }
108
+ get turnable() { return this.piled || this.currentView === 'fan'; }
82
109
  q(selector) { return this.root.querySelector(selector); }
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. */
110
+ /** With `address`, the display, the fan, the landing, the animation and its speed are kept in the page's address (`?view=fan&fan=open&land=face-down&animate=off`), and a link to it opens the same. */
84
111
  readAddress() { try {
85
112
  const params = new URLSearchParams(location.search);
86
113
  for (const key of ADDRESS_KEYS) {
87
114
  const value = params.get(key);
88
115
  if (value === null)
89
116
  continue;
90
- const attr = key === 'land' ? 'deck-land' : key;
117
+ const attr = NAMES[key] ?? key;
91
118
  if (this.getAttribute(attr) !== value)
92
119
  this.setAttribute(attr, value);
93
120
  }
@@ -96,7 +123,7 @@ export class FudaCollection extends HTMLElement {
96
123
  writeAddress() { if (!this.hasAttribute('address'))
97
124
  return; clearTimeout(this.addressTimer); this.addressTimer = window.setTimeout(() => { try {
98
125
  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 };
126
+ const want = { view: this.currentView === 'deck' ? null : this.currentView, fan: this.fanOpen ? 'open' : null, land: this.land === 'face-up' ? null : this.land, animate: this.getAttribute('animate') === 'off' ? 'off' : null, speed: ['slow', 'quick'].includes(this.getAttribute('speed') ?? '') ? this.getAttribute('speed') : null, binder: this.getAttribute('binder') === 'zip' ? 'zip' : null, cover: binderCovers.some(c => c.id === this.getAttribute('cover')) && this.getAttribute('cover') !== 'green' ? this.getAttribute('cover') : null, sheet: this.getAttribute('sheet') === 'black' ? 'black' : null, pockets: ['4', '12'].includes(this.getAttribute('pockets') ?? '') ? this.getAttribute('pockets') : null };
100
127
  for (const [k, v] of Object.entries(want)) {
101
128
  if (v === null)
102
129
  url.searchParams.delete(k);
@@ -110,17 +137,25 @@ export class FudaCollection extends HTMLElement {
110
137
  if (!this.data.length)
111
138
  return;
112
139
  const view = this.currentView;
113
- if (pages.includes(view)) {
140
+ if (view === 'binder') {
141
+ const per = this.binderLay().per, spreads = spreadCount(sideCount(this.data.length, per)), from = spreadOf(this.index, per), to = (from + n + spreads * Math.abs(n)) % spreads;
142
+ this.turn = { from, to };
143
+ this.index = this.spreadFirst(to);
144
+ }
145
+ else if (pages.includes(view)) {
114
146
  this.index = movePage(this.index, this.data.length, this.pageSize, n);
115
147
  }
116
148
  else {
117
149
  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;
150
+ this.flip = this.piled && Math.abs(n) === 1 && next === this.index + n ? (n > 0 ? 'off' : 'back') : null;
119
151
  this.index = next;
120
152
  }
121
- this.render();
153
+ this.render(false, { kind: 'move', dir: n > 0 ? 1 : -1 });
122
154
  }
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; }
155
+ binderLay() { return binderLayout(this.getAttribute('pockets'), this.getAttribute('columns'), this.getAttribute('page-size')); }
156
+ /** The first card of an opening of the binder: the right-hand page's first card, or the left-hand page's when the right-hand page is past the end. */
157
+ spreadFirst(spread) { const per = this.binderLay().per, sides = sideCount(this.data.length, per); return Math.min(this.data.length - 1, (2 * spread < sides ? 2 * spread : 2 * spread - 1) * per); }
158
+ image(c, at) { let button = document.createElement('button'); button.className = 'card'; button.dataset.i = String(at); 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; }
124
159
  open(c) { this.selected = c; this.back = false; this.renderDialog(); }
125
160
  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) {
126
161
  let img = document.createElement('img');
@@ -139,48 +174,63 @@ export class FudaCollection extends HTMLElement {
139
174
  } if (!dlg.open)
140
175
  dlg.showModal(); }
141
176
  canDraw() { const query = this.drawFilter.trim().toLocaleLowerCase(); return this.data.some(c => c.name.toLocaleLowerCase().includes(query)); }
177
+ /** The one length every move takes, in a custom property the stylesheet reads: `animate="off"` and reduced motion make it 0, `speed` stretches it. */
178
+ timeVars() { const t = timing(this, true), shell = this.root.querySelector('.shell'); if (!shell)
179
+ return t; shell.style.setProperty('--t', t.on ? `${t.ms}ms` : '0s'); if (t.on)
180
+ shell.style.removeProperty('--stag');
181
+ else
182
+ shell.style.setProperty('--stag', '0ms'); return t; }
183
+ syncChoices() { this.animateChoice?.set(this.getAttribute('animate') === 'off' ? 'off' : 'on'); this.speedChoice?.set(['slow', 'quick'].includes(this.getAttribute('speed') ?? '') ? this.getAttribute('speed') : 'normal'); }
142
184
  build() {
143
185
  if (this.zoom)
144
186
  return;
145
187
  this.root.innerHTML = STYLE + SHELL;
188
+ const keep = (attr, value) => { if (value === null)
189
+ this.removeAttribute(attr);
190
+ else
191
+ this.setAttribute(attr, value); this.writeAddress(); };
146
192
  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
193
  this.q('.displays').append(this.tiles.element);
148
194
  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')
195
+ this.fanChoice = createChoice({ label: 'Fan', value: this.fanOpen ? 'open' : 'closed', options: [{ value: 'closed', label: 'Closed' }, { value: 'open', label: 'Open' }], onChange: value => { if (value === 'open')
150
196
  this.setAttribute('fan', 'open');
151
197
  else
152
198
  this.removeAttribute('fan'); this.writeAddress(); } });
153
- this.q('.opts').append(this.landing.element, this.fanChoice.element);
199
+ this.animateChoice = createChoice({ label: 'Animate', value: 'on', options: [{ value: 'on', label: 'On' }, { value: 'off', label: 'Off' }], onChange: value => keep('animate', value === 'off' ? 'off' : 'on') });
200
+ this.speedChoice = createChoice({ label: 'Speed', value: 'normal', options: [{ value: 'slow', label: 'Slow' }, { value: 'normal', label: 'Normal' }, { value: 'quick', label: 'Quick' }], onChange: value => keep('speed', value) });
201
+ const bin = (attr, label, value, options) => { const h = createChoice({ label, value, options, onChange: v => { this.setAttribute(attr, v); this.writeAddress(); } }); this.binderChoices[attr] = h; return h.element; };
202
+ this.q('.opts').append(this.landing.element, this.fanChoice.element, bin('binder', 'Binder', 'ring', [{ value: 'ring', label: 'Ring' }, { value: 'zip', label: 'Zip' }]), bin('cover', 'Cover', 'green', binderCovers.map(c => ({ value: c.id, label: c.label }))), bin('sheet', 'Sheet', 'clear', [{ value: 'clear', label: 'Clear' }, { value: 'black', label: 'Black' }]), bin('pockets', 'Pockets', '9', [{ value: '4', label: '4' }, { value: '9', label: '9' }, { value: '12', label: '12' }]), this.animateChoice.element, this.speedChoice.element);
203
+ this.speedChoice.element.classList.add('speed');
154
204
  this.q('.prev').onclick = () => this.move(-1);
155
205
  this.q('.next').onclick = () => this.move(1);
156
206
  const input = this.q('.draw-filter input'), draw = this.q('.draw');
157
207
  input.oninput = () => { this.drawFilter = input.value; draw.disabled = !this.canDraw(); };
158
208
  draw.onclick = () => { const next = randomDrawIndex(this.data, this.index, this.drawFilter); if (next === null)
159
- return; this.index = next; this.render(); };
209
+ return; this.index = next; this.render(false, { kind: 'move', dir: 1 }); };
160
210
  const stage = this.q('.stage');
161
211
  this.zoom = zoomView(stage, this.q('.v'), { address: this.hasAttribute('address'), items: '.card,.slot', theme: this.getAttribute('theme') ?? undefined });
162
212
  let startX = 0;
163
213
  stage.addEventListener('touchstart', e => { if (e.touches.length === 1)
164
214
  startX = e.touches[0].clientX; }, { passive: true });
165
- stage.addEventListener('touchend', e => { if (!this.stacked || this.currentView === 'deck' || this.zoom.zoomed() || e.changedTouches.length !== 1)
215
+ stage.addEventListener('touchend', e => { if (!this.stacked || this.piled || this.zoom.zoomed() || e.changedTouches.length !== 1)
166
216
  return; const dx = e.changedTouches[0].clientX - startX; if (Math.abs(dx) > 45) {
167
217
  if (e.cancelable)
168
218
  e.preventDefault();
169
219
  this.move(dx < 0 ? 1 : -1);
170
220
  } }, { passive: false });
171
- stage.addEventListener('keydown', (e) => { if (!this.stacked || this.currentView === 'deck' || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft'))
221
+ stage.addEventListener('keydown', (e) => { if (!this.stacked || this.piled || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft'))
172
222
  return; e.preventDefault(); this.move(e.key === 'ArrowRight' ? 1 : -1); this.q('.stack .card:last-child')?.focus(); });
173
223
  }
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) {
224
+ /** 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. A deck's cards also carry where they lie when the fan is open. */
225
+ pile(kind, positions, fan = []) {
176
226
  const pile = document.createElement('div');
177
227
  pile.className = `pile ${kind}-pile${kind === 'discard' ? ' discard' : ''}`;
178
228
  pile.dataset.land = this.land;
179
229
  const messy = Math.min(1, Math.max(0, Number(this.getAttribute('deck-messiness') ?? 0.3)));
180
230
  const seed = Number(this.getAttribute('deck-seed') ?? 1) || 1;
181
- const depth = Math.min(9, positions.length - 1);
231
+ const depth = Math.min(positions.length - 1, fan.length ? fan.length - 1 : 9);
182
232
  const shown = positions.slice(positions.length - 1 - depth);
183
- const places = stackLayout(positions.length, { messiness: messy, seed, depth: 9 });
233
+ const places = stackLayout(positions.length, { messiness: messy, seed, depth });
184
234
  shown.forEach((at, j) => {
185
235
  const top = j === shown.length - 1, c = this.data[at], place = places[j];
186
236
  const el = document.createElement('div');
@@ -192,6 +242,13 @@ export class FudaCollection extends HTMLElement {
192
242
  el.style.setProperty('--r', String(place.rotate));
193
243
  }
194
244
  el.style.setProperty('--k', String(j));
245
+ el.style.setProperty('--j', String(shown.length - 1 - j));
246
+ const f = fan[shown.length - 1 - j];
247
+ if (f) {
248
+ el.style.setProperty('--fx', String(f.x));
249
+ el.style.setProperty('--fa', String(f.angle));
250
+ el.style.setProperty('--i', String(shown.length - 1 - j));
251
+ }
195
252
  const fly = document.createElement('div');
196
253
  fly.className = 'fly';
197
254
  const turn = document.createElement('div');
@@ -220,11 +277,11 @@ export class FudaCollection extends HTMLElement {
220
277
  turn.append(front, back);
221
278
  fly.append(turn);
222
279
  el.append(fly);
280
+ el.onclick = () => this.open(c);
223
281
  if (top) {
224
282
  el.setAttribute('role', 'button');
225
- el.tabIndex = 0;
226
283
  el.setAttribute('aria-label', `Inspect ${c.name}`);
227
- el.onclick = () => this.open(c);
284
+ el.tabIndex = 0;
228
285
  el.onkeydown = e => { if (e.key === 'Enter' || e.key === ' ') {
229
286
  e.preventDefault();
230
287
  this.open(c);
@@ -234,61 +291,204 @@ export class FudaCollection extends HTMLElement {
234
291
  });
235
292
  return pile;
236
293
  }
237
- renderDeck(v) {
294
+ /** Where the fan's cards lie for a pile of this many cards. A phone's fan lies closer across and leans on its angle. */
295
+ fanFor(count) { const narrow = (this.clientWidth || innerWidth) < 520; return fanLayout(count, Number(this.getAttribute('deck-seed') ?? 1) || 1, narrow ? 0.3 : 0.34); }
296
+ /** Open the fan (or close it) on the pile that is on screen, without drawing it again, so every card glides: the open fan's reach is put in custom properties that move the piles apart and the Fit box. */
297
+ fanVars(v, open) {
298
+ const b = open && this.fanPlaces.length > 1 ? fanBounds(this.fanPlaces) : { left: 0, right: 0, top: 0, bottom: 0 };
299
+ v.classList.toggle('fan-open', open && this.fanPlaces.length > 1);
300
+ for (const [k, x] of [['--fl', b.left], ['--fr', b.right], ['--ft', b.top], ['--fb', b.bottom]])
301
+ v.style.setProperty(k, String(x));
302
+ }
303
+ /** `fan` changed: when a pile is on screen, move its cards to or from the fan in place (animated) and fit the view to it. Returns false when there is no pile to move. */
304
+ setFan() {
305
+ if (!this.zoom || !(this.piled || this.currentView === 'fan'))
306
+ return false;
307
+ const v = this.q('.v');
308
+ if (!v.classList.contains('deck') || !this.data.length)
309
+ return false;
310
+ const t = this.timeVars();
311
+ this.zoom.animated(() => { this.fanVars(v, this.fanOpen); this.zoom.refresh(); }, t.on ? t.ms : 0);
312
+ this.syncChoices();
313
+ this.fanChoice.set(this.fanOpen ? 'open' : 'closed');
314
+ this.writeAddress();
315
+ return true;
316
+ }
317
+ renderDeck(v, fanOnly = false) {
238
318
  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
319
  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;
320
+ if (fanOnly) {
321
+ const size = Math.min(10, Math.max(2, Math.floor(Number(this.getAttribute('fan-size')) || 10))), count = Math.min(size, n);
322
+ // The fan window: `count` cards from the first one, wrapping round; the top card is the first and lies on the left when open.
323
+ for (let p = count - 1; p >= 0; p--)
324
+ deckPositions.push((this.index + p) % n);
325
+ v.classList.add('fanonly');
326
+ this.fanPlaces = this.fanFor(count);
327
+ v.append(this.pile('deck', deckPositions, this.fanPlaces));
328
+ }
329
+ else {
330
+ // 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.
331
+ for (let p = 0; p < n - this.index; p++)
332
+ deckPositions.push(n - 1 - p);
333
+ for (let p = 0; p < this.index; p++)
334
+ discardPositions.push(p);
335
+ this.fanPlaces = this.fanFor(Math.min(10, deckPositions.length));
336
+ const slot = () => { const s = document.createElement('div'); s.className = 'slot'; return s; };
337
+ // 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.
338
+ v.append(deckPositions.length ? this.pile('deck', deckPositions, this.fanPlaces) : slot(), discardPositions.length ? this.pile('discard', discardPositions) : slot());
339
+ }
340
+ const extent = document.createElement('div');
341
+ extent.className = 'extent';
342
+ v.append(extent);
343
+ this.fanVars(v, this.fanOpen);
251
344
  }
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) {
345
+ /** 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. An open fan sends the card from where the fan holds it. */
346
+ playFlip(direction, v, ms) {
254
347
  const deck = v.querySelector('.deck-pile'), discard = v.querySelector('.discard-pile');
255
348
  const moved = direction === 'off' ? discard?.querySelector('.card.top') : deck?.querySelector('.card.top');
256
349
  if (!moved || !deck || !discard)
257
350
  return;
258
- const dx = discard.offsetLeft - deck.offsetLeft, dy = discard.offsetTop - deck.offsetTop;
351
+ const style = getComputedStyle(v), w = parseFloat(style.getPropertyValue('--w')) || 200, gap = parseFloat(style.getPropertyValue('--gap')) || 56, fr = parseFloat(v.style.getPropertyValue('--fr')) || 0;
352
+ const dx = (1 + fr) * w + gap, dy = 0;
259
353
  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);
354
+ const lead = this.fanOpen && this.fanPlaces.length > 1 ? this.fanPlaces[0] : null, shift = lead ? fanShift(lead) : { x: 0, y: 0 };
355
+ const away = { x: shift.x * w, y: shift.y * w }, spin = lead ? lead.angle : 0;
356
+ // Taking a card off an open fan starts it where the fan holds it; bringing it back ends there.
357
+ const from = direction === 'off' ? { x: -dx + away.x, y: -dy + away.y } : { x: dx - away.x, y: dy - away.y };
358
+ flight(fly, turn, from, this.land, direction, ms, direction === 'off' ? spin : -spin);
262
359
  }
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
- });
360
+ renderFan(v) { this.renderDeck(v, true); }
361
+ /** Where every card is on screen now, by data index. */
362
+ snapshot(v) { const m = new Map(); v.querySelectorAll('[data-i]:not(.ghost)').forEach(el => m.set(el.dataset.i, el.getBoundingClientRect())); return m; }
363
+ /** Cards that arrive grow and fade in, a little to the side the reader is heading. Only an opening keyframe: they end on the card's own style. */
364
+ enter(els, ms, dir = 0, stagger = 18) { let k = 0; for (const el of els)
365
+ el.animate([{ opacity: 0, translate: `${dir * 36}px 0`, scale: .94, offset: 0 }], { duration: ms, delay: Math.min(k++, 12) * stagger, easing: 'cubic-bezier(.2,.8,.2,1)', fill: 'backwards' }); }
366
+ /** After a card or page change or a switch of display: glide what stays, let what goes leave, bring in what comes. Nothing runs afterwards: each is one animation that ends by itself. */
367
+ play(how, before, left, view, v, ms) {
368
+ if (how.kind === 'view') {
369
+ this.enter(Array.from(v.querySelectorAll('.card,.slot')), ms * 0.7);
370
+ return;
371
+ }
372
+ if (pages.includes(view)) {
373
+ this.enter(Array.from(v.querySelectorAll('.card')), ms * 0.7, how.dir);
374
+ return;
375
+ }
376
+ if (scrolling.includes(view)) {
377
+ const el = v.querySelector(`[data-i="${this.index}"]`);
378
+ if (el)
379
+ this.zoom.reveal(el, ms);
380
+ return;
381
+ }
382
+ if (!gliding.includes(view) || this.zoom.turned())
383
+ return;
384
+ const scale = v.offsetWidth ? v.getBoundingClientRect().width / v.offsetWidth : 1;
385
+ const kept = new Set();
386
+ for (const el of Array.from(v.querySelectorAll('.card[data-i]'))) {
387
+ const was = before.get(el.dataset.i), now = el.getBoundingClientRect();
388
+ if (!was || !now.width) {
389
+ this.enter([el], ms * 0.7, how.dir);
390
+ continue;
391
+ }
392
+ kept.add(el.dataset.i);
393
+ const dx = (was.left + was.width / 2 - now.left - now.width / 2) / scale, dy = (was.top + was.height / 2 - now.top - now.height / 2) / scale;
394
+ el.animate([{ translate: `${dx}px ${dy}px`, scale: was.width / now.width, offset: 0 }], { duration: ms, easing: 'cubic-bezier(.2,.8,.2,1)' });
395
+ }
396
+ const host = v.querySelector('.deck-pile') ?? v;
397
+ for (const old of left) {
398
+ if (kept.has(old.dataset.i))
399
+ continue;
400
+ old.classList.add('ghost');
401
+ old.removeAttribute('role');
402
+ old.tabIndex = -1;
403
+ host.append(old);
404
+ const done = () => old.remove();
405
+ old.animate([{ opacity: 1, translate: '0 0', offset: 0 }, { opacity: 0, translate: `${-how.dir * 60}px 0`, offset: 1 }], { duration: ms * 0.8, easing: 'ease-in' }).finished.then(done, done);
406
+ }
407
+ }
408
+ syncBinder(view) {
409
+ const show = view === 'binder', cur = (attr, dflt, ok) => { const v = this.getAttribute(attr); return v && ok.includes(v) ? v : dflt; };
410
+ const vals = { binder: cur('binder', 'ring', ['ring', 'zip']), cover: cur('cover', 'green', binderCovers.map(c => c.id)), sheet: cur('sheet', 'clear', ['clear', 'black']), pockets: cur('pockets', '9', ['4', '9', '12']) };
411
+ for (const [k, h] of Object.entries(this.binderChoices)) {
412
+ h.hidden = !show;
413
+ h.set(vals[k]);
414
+ }
415
+ }
416
+ binderCount() { const per = this.binderLay().per, sides = sideCount(this.data.length, per), [l, r] = spreadSides(spreadOf(this.index, per), sides); const a = (l < 0 ? r : l) + 1, b = (r < 0 ? l : r) + 1; return a === b ? `Page ${a} / ${sides}` : `Pages ${a}–${b} / ${sides}`; }
417
+ /** The binder: a ring or zip binder open on two facing sheets of pockets. A page turn swings the leaf about the spine, bending as it goes, and shows the pockets on its back. */
418
+ renderBinder(v, t) {
419
+ const layout = this.binderLay(), n = this.data.length, sides = sideCount(n, layout.per), spread = spreadOf(this.index, layout.per);
420
+ const sheet = this.getAttribute('sheet') === 'black' ? 'black' : 'clear', zip = this.getAttribute('binder') === 'zip', cover = binderCovers.find(c => c.id === this.getAttribute('cover')) ?? binderCovers[0];
421
+ v.classList.add('binder');
422
+ v.style.setProperty('--cover', cover.color);
423
+ const pocket = (index, live) => { const c = this.data[index], el = document.createElement('div'); el.className = 'pocket'; if (live)
424
+ el.append(this.image(c, index));
425
+ else {
426
+ const img = document.createElement('img');
427
+ img.src = c.image;
428
+ img.alt = '';
429
+ img.style.cssText = 'width:86%;height:92%;object-fit:contain;border-radius:3%;box-shadow:0 2px 5px #0007';
430
+ el.append(img);
431
+ } return el; };
432
+ const [L, R] = spreadSides(spread, sides), turn = this.turn;
433
+ this.turn = null;
434
+ const flat = turn && t.on && Math.abs(turn.to - turn.from) === 1 ? turn : null;
435
+ const [oldL, oldR] = flat ? spreadSides(flat.from, sides) : [L, R], [newL, newR] = flat ? spreadSides(flat.to, sides) : [L, R];
436
+ const forward = !!flat && flat.to > flat.from;
437
+ const book = document.createElement('div');
438
+ book.className = `book ${zip ? 'b-zip' : 'b-ring'}`;
439
+ const inside = document.createElement('div');
440
+ inside.className = 'inside';
441
+ const left = document.createElement('div'), right = document.createElement('div');
442
+ left.className = 'half';
443
+ right.className = 'half';
444
+ const put = (half, side, where) => { half.replaceChildren(); if (side >= 0)
445
+ half.append(buildSide(side, where, sheet, layout, n, pocket)); };
446
+ // While a leaf swings the half it has not reached yet shows the page it is leaving; the other half already shows the page it uncovers.
447
+ put(left, flat ? (forward ? oldL : newL) : L, 'l');
448
+ put(right, flat ? (forward ? newR : oldR) : R, 'r');
449
+ const spine = document.createElement('div');
450
+ spine.className = 'spine';
451
+ for (const y of [18, 50, 82]) {
452
+ const ring = document.createElement('i');
453
+ ring.className = 'ring';
454
+ ring.style.top = `${y}%`;
455
+ spine.append(ring);
456
+ }
457
+ inside.append(left, right, spine);
458
+ const tab = document.createElement('i');
459
+ tab.className = 'tab';
460
+ book.append(inside, tab);
461
+ v.append(book);
462
+ if (flat) {
463
+ const w = 300, strip = 34, { leaf, slices } = buildLeaf(forward ? oldR : newR, forward ? newL : oldL, sheet, layout, n, pocket, w, strip);
464
+ inside.append(leaf);
465
+ const ms = Math.round(t.ms * 1.4), ease = 'cubic-bezier(.45,.05,.3,1)', a = forward ? [0, -180] : [-180, 0];
466
+ leaf.style.transform = `rotateY(${a[1]}deg)`;
467
+ const swing = leaf.animate([{ transform: `rotateY(${a[0]}deg)` }, { transform: `rotateY(${a[1]}deg)` }], { duration: ms, easing: ease, fill: 'forwards' });
468
+ // Each slice leans on the one before it, so the sheet bends as it swings (the free edge trails) and straightens at the end.
469
+ const bend = forward ? 8 : -8;
470
+ slices.forEach((s, k) => { if (k)
471
+ s.animate([{ transform: 'rotateY(0deg)' }, { transform: `rotateY(${bend}deg)`, offset: .5 }, { transform: 'rotateY(0deg)' }], { duration: ms, easing: ease }); });
472
+ const finish = () => { if (!leaf.isConnected)
473
+ return; put(left, newL, 'l'); put(right, newR, 'r'); leaf.remove(); };
474
+ swing.finished.then(finish, finish);
475
+ }
280
476
  }
281
- render(reset = false) {
477
+ render(reset = false, how) {
282
478
  if (!this.isConnected)
283
479
  return;
284
480
  this.build();
285
481
  let view = this.currentView, stage = this.q('.stage'), v = this.q('.v');
482
+ const t = this.timeVars(), playing = t.on && how && this.data.length > 0;
483
+ const before = playing ? this.snapshot(v) : new Map(), left = playing && how.kind === 'move' && gliding.includes(view) ? Array.from(v.querySelectorAll('.card:not(.ghost)')) : [];
484
+ this.syncBinder(view);
286
485
  this.tiles.set(view);
287
486
  this.landing.set(this.land);
288
487
  this.fanChoice.set(this.fanOpen ? 'open' : 'closed');
289
- this.landing.hidden = view !== 'deck';
290
- this.fanChoice.hidden = view !== 'fan';
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';
488
+ this.syncChoices();
489
+ this.landing.hidden = !this.piled;
490
+ this.fanChoice.hidden = !(this.piled || view === 'fan');
491
+ this.q('.count').textContent = this.data.length ? (view === 'binder' ? this.binderCount() : 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';
292
492
  for (const selector of ['.prev', '.next'])
293
493
  this.q(selector).disabled = !this.data.length;
294
494
  const random = view === 'random';
@@ -300,46 +500,57 @@ export class FudaCollection extends HTMLElement {
300
500
  v.className = 'v';
301
501
  v.replaceChildren();
302
502
  v.style.removeProperty('--columns');
503
+ for (const k of ['--fl', '--fr', '--ft', '--fb'])
504
+ v.style.removeProperty(k);
303
505
  this.zoom.minOpen = scrolling.includes(view) ? .5 : 0;
304
- this.zoom.setTurnable(view === 'deck' && this.data.length > 0);
506
+ this.zoom.setTurnable(this.turnable && this.data.length > 0);
507
+ this.zoom.items = this.piled || view === 'fan' ? '.extent' : view === 'binder' ? '.book' : '.card,.slot';
305
508
  if (!this.data.length) {
306
509
  v.innerHTML = '<p class="empty">No cards in this collection.</p>';
307
510
  }
308
- else if (view === 'deck')
511
+ else if (this.piled)
309
512
  this.renderDeck(v);
310
513
  else if (view === 'fan')
311
514
  this.renderFan(v);
515
+ else if (view === 'binder')
516
+ this.renderBinder(v, t);
312
517
  else if (pages.includes(view)) {
313
518
  v.classList.add('grid', view);
314
519
  const columns = Math.min(10, Math.max(1, Math.floor(Number(this.getAttribute('columns')) || 3)));
315
520
  v.style.setProperty('--columns', String(columns));
316
521
  let start = Math.floor(this.index / this.pageSize) * this.pageSize;
317
- this.data.slice(start, start + this.pageSize).forEach(c => v.append(this.image(c)));
522
+ this.data.slice(start, start + this.pageSize).forEach((c, k) => v.append(this.image(c, start + k)));
318
523
  }
319
524
  else if (view === 'wall' || view === 'story') {
320
525
  v.classList.add(view);
321
- this.data.forEach(c => v.append(this.image(c)));
526
+ this.data.forEach((c, k) => v.append(this.image(c, k)));
322
527
  }
323
528
  else if (view === 'atlas') {
324
529
  v.classList.add('atlas');
325
530
  let plane = document.createElement('div');
326
531
  plane.className = 'plane';
327
- this.data.forEach(c => plane.append(this.image(c)));
532
+ this.data.forEach((c, k) => plane.append(this.image(c, k)));
328
533
  v.append(plane);
329
534
  }
330
535
  else {
331
536
  v.classList.add('stack', view);
332
537
  let count = Math.min(3, this.data.length);
333
538
  for (let d = count - 1; d >= 0; d--) {
334
- let c = this.data[(this.index + d) % this.data.length], el = this.image(c);
539
+ const at = (this.index + d) % this.data.length;
540
+ let c = this.data[at], el = this.image(c, at);
335
541
  let offset = view === 'rolodex' ? d * 42 : view === 'spotlight' ? d * 70 : d * 14;
336
- let rotation = view === 'rolodex' ? d * 12 : view === 'tower' ? 0 : d * 5;
542
+ let rotation = view === 'rolodex' ? d * 12 : d * 5;
337
543
  el.style.transform = `translateX(calc(-50% + ${offset}px)) rotate(${rotation}deg) scale(${1 - d * .08})`;
338
544
  el.style.opacity = String(1 - d * .2);
339
545
  v.append(el);
340
546
  }
341
547
  }
342
548
  this.zoom.refresh(reset);
549
+ if (this.flip && this.piled && t.on && this.data.length > 1)
550
+ this.playFlip(this.flip, v, Math.round(t.ms * 1.15));
551
+ this.flip = null;
552
+ if (playing)
553
+ this.play(how, before, left, view, v, t.ms);
343
554
  }
344
555
  }
345
556
  if (!customElements.get('fuda-collection'))
@@ -19,10 +19,13 @@ export interface CollectionCard {
19
19
  backImage?: string;
20
20
  metadata?: CollectionMetadata;
21
21
  }
22
+ /** The displays, in the order the buttons show them. `jukebox` and `tower` were two more names for the deck's pile of cards (no real counterpart for cards, and the same drawing), so they are no longer offered; see `collectionViewAliases`. */
22
23
  export declare const collectionViews: ReadonlyArray<{
23
24
  id: CollectionView;
24
25
  label: string;
25
26
  }>;
27
+ /** Display names that earlier versions accepted and that now open another display, so a page that sets them keeps working. */
28
+ export declare const collectionViewAliases: Readonly<Record<string, CollectionView>>;
26
29
  export declare function parseCollection(value: unknown): CollectionCard[];
27
30
  /** Choose a matching card, avoiding the current card when another match exists. */
28
31
  export declare function randomDrawIndex(cards: CollectionCard[], current: number, filter: string, random?: () => number): number | null;