@johnmorrisdotca/fuda-cards 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -3
- package/dist/collection-element.d.ts +24 -3
- package/dist/collection-element.js +207 -82
- package/dist/collection.d.ts +2 -16
- package/dist/collection.js +1 -22
- package/dist/element.d.ts +19 -0
- package/dist/element.js +35 -6
- package/dist/pile-card.d.ts +17 -0
- package/dist/pile-card.js +223 -0
- package/dist/pile.d.ts +73 -0
- package/dist/pile.js +107 -0
- package/dist/zoom.d.ts +8 -0
- package/dist/zoom.js +34 -3
- package/docs/collection-displays.md +6 -4
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { collectionViews,
|
|
1
|
+
import { collectionViews, parseCollection, randomDrawIndex, movePage } from './collection.js';
|
|
2
|
+
import { deckLandings, fanBounds, fanLayout, fanShift, flight, normalizeLanding, timing } from './pile.js';
|
|
2
3
|
import { zoomView } from './zoom.js';
|
|
3
4
|
import { createChoice, CHOICE_CSS, CHOICE_VARS } from './choice.js';
|
|
4
5
|
import { stackLayout } from './stack.js';
|
|
5
6
|
const STYLE = `<style>
|
|
6
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}}
|
|
7
|
-
*{box-sizing:border-box}.shell{background:var(--fc-surface);padding:1rem;border-radius:1rem;display:grid;gap:.9rem}.nav{display:flex;gap:.6rem;align-items:center;justify-content:center;flex-wrap:wrap}.opts{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,
|
|
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%,13.5rem),1fr));gap:.9rem}.opts:not(:has(.choice:not([hidden]))){display:none}.opts .choice{--choice-min:4.6rem}
|
|
8
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}
|
|
9
10
|
button:focus-visible,input:focus-visible,.card:focus-visible{outline:3px solid var(--fc-focus);outline-offset:3px}${CHOICE_CSS}
|
|
10
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}}
|
|
@@ -17,18 +18,26 @@ button:focus-visible,input:focus-visible,.card:focus-visible{outline:3px solid v
|
|
|
17
18
|
.story{display:flex;flex-direction:column;align-items:center;gap:1rem;padding:1rem}.story .card{width:min(75%,300px);flex:0 0 90%}
|
|
18
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}
|
|
19
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%)}
|
|
20
|
-
.stage.deck{perspective:1800px}.v.deck{--w:200px
|
|
21
|
-
.pile .
|
|
21
|
+
.stage:is(.deck,.random,.jukebox,.tower,.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}
|
|
22
|
+
.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}
|
|
23
|
+
.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}
|
|
24
|
+
.v.deck .deck-pile,.v.deck .discard-pile,.v.deck .slot{transition:translate var(--t,0s) var(--ease)}
|
|
25
|
+
.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))}
|
|
26
|
+
.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}
|
|
27
|
+
.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}
|
|
22
28
|
.fly,.turn{position:absolute;inset:0;transform-style:preserve-3d}.face{position:absolute;inset:0;backface-visibility:hidden;-webkit-backface-visibility:hidden;border-radius:5%;overflow:hidden}.face img{display:block;width:100%;height:100%;object-fit:contain;border-radius:3%;box-shadow:0 4px 10px #0008}.face.back{transform:rotateY(180deg)}
|
|
23
29
|
.generic-back{display:grid;place-items:center;background:radial-gradient(ellipse at center,#b78745 0 12%,#152d46 13% 27%,#386988 28% 31%,#10233b 32% 62%,#d2b074 63% 66%,#182c45 67%);border:6px solid #b39158;color:#f7e9bf;font:bold 18px Georgia;letter-spacing:.12em;box-shadow:0 4px 10px #0008}
|
|
24
|
-
.pile.discard[data-land=face-down] .card .turn{transform:rotateY(180deg)}.
|
|
25
|
-
.v.fan{--w:190px;display:grid;place-items:end center;padding-bottom:1rem}.fan .card{grid-area:1/1;position:relative;width:var(--w);aspect-ratio:2.5/3.5;height:auto;transform-origin:50% 165%;z-index:var(--z);transform:translate(calc(var(--cx) * var(--w)),calc(var(--cy) * var(--w))) rotate(calc(var(--cr) * 1deg));transition:transform .7s cubic-bezier(.2,.8,.2,1);transition-delay:calc((var(--n) - var(--i)) * 22ms)}.fan.open .card{transform:translate(calc(var(--x) * var(--w)),0) rotate(calc(var(--a) * 1deg));transition-delay:calc(var(--i) * 28ms)}.fan.open .card:hover,.fan.open .card:focus-visible{translate:0 -14px}.fan .card img{border-radius:6%}
|
|
30
|
+
.pile.discard[data-land=face-down] .card .turn{transform:rotateY(180deg)}.ghost{pointer-events:none}
|
|
26
31
|
dialog{color:var(--fc-text);background:var(--fc-dialog);border:1px solid var(--fc-btn-border);border-radius:1rem;text-align:center;max-width:95vw;max-height:95vh}dialog::backdrop{background:#000c}.detail{display:block;height:min(70vh,600px);max-width:80vw;object-fit:contain;margin:1rem auto}.empty{text-align:center;padding:3rem}
|
|
27
|
-
@media(max-width:600px){.stage{height:var(--fuda-stage-height,clamp(220px,calc(100svh - 570px),620px))}}@media(max-width:500px){.grid{grid-template-columns:repeat(min(2,var(--columns,3)),minmax(0,1fr))}.shell{padding:.7rem}.v.deck{--w:150px
|
|
32
|
+
@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}}
|
|
28
33
|
</style>`;
|
|
29
|
-
const SHELL = `<section class="shell"><div class="displays"></div><div class="stage" tabindex="0" role="group" aria-label="Collection"><div class="v"></div></div><div class="
|
|
34
|
+
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>`;
|
|
30
35
|
const pages = ['binder', 'case'];
|
|
31
36
|
const scrolling = ['wall', 'story', 'atlas'];
|
|
37
|
+
/** 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. */
|
|
38
|
+
const pileViews = ['deck', 'random', 'jukebox', 'tower'];
|
|
39
|
+
/** 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. */
|
|
40
|
+
const gliding = ['rolodex', 'spotlight', 'fan'];
|
|
32
41
|
const rects = (cols, rows, w, h, gx, gy, x0 = 1, y0 = 1) => Array.from({ length: cols * rows }, (_, k) => `<rect x="${x0 + (k % cols) * gx}" y="${y0 + Math.floor(k / cols) * gy}" width="${w}" height="${h}" rx="1" opacity="${0.55 + ((k % cols + Math.floor(k / cols)) % 2) * 0.4}"/>`).join('');
|
|
33
42
|
const ICONS = {
|
|
34
43
|
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"/>',
|
|
@@ -45,8 +54,8 @@ const ICONS = {
|
|
|
45
54
|
fan: [-30, -15, 0, 15, 30].map((a, i) => `<rect x="14" y="1" width="7" height="13" rx="1.2" transform="rotate(${a} 17.5 21)" opacity="${0.45 + i * 0.1}"/>`).join('')
|
|
46
55
|
};
|
|
47
56
|
const icon = (view) => `<svg viewBox="0 0 34 22" aria-hidden="true">${ICONS[view]}</svg>`;
|
|
48
|
-
const
|
|
49
|
-
const
|
|
57
|
+
const ADDRESS_KEYS = ['view', 'fan', 'land', 'animate', 'speed'];
|
|
58
|
+
const NAMES = { land: 'deck-land' };
|
|
50
59
|
export class FudaCollection extends HTMLElement {
|
|
51
60
|
root = this.attachShadow({ mode: 'open' });
|
|
52
61
|
data = [];
|
|
@@ -59,9 +68,12 @@ export class FudaCollection extends HTMLElement {
|
|
|
59
68
|
tiles;
|
|
60
69
|
landing;
|
|
61
70
|
fanChoice;
|
|
71
|
+
animateChoice;
|
|
72
|
+
speedChoice;
|
|
62
73
|
flip = null;
|
|
63
74
|
addressTimer = 0;
|
|
64
|
-
|
|
75
|
+
fanPlaces = [];
|
|
76
|
+
static get observedAttributes() { return ['view', 'page-size', 'columns', 'fan', 'fan-size', 'deck-land', 'deck-messiness', 'deck-seed', 'theme', 'animate', 'speed']; }
|
|
65
77
|
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(); }
|
|
66
78
|
get cards() { return this.data.map(c => ({ ...c, ...(c.metadata ? { metadata: { ...c.metadata } } : {}) })); }
|
|
67
79
|
/** The card on top of the deck, or the first card of the page or fan (counting from 0). */
|
|
@@ -69,23 +81,37 @@ export class FudaCollection extends HTMLElement {
|
|
|
69
81
|
connectedCallback() { if (this.hasAttribute('address'))
|
|
70
82
|
this.readAddress(); this.render(); }
|
|
71
83
|
disconnectedCallback() { clearTimeout(this.addressTimer); }
|
|
72
|
-
attributeChangedCallback(name) {
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
75
|
-
|
|
84
|
+
attributeChangedCallback(name) {
|
|
85
|
+
this.pageSize = Math.min(100, Math.max(1, Math.floor(Number(this.getAttribute('page-size')) || 9)));
|
|
86
|
+
if (name === 'fan' && this.setFan())
|
|
87
|
+
return;
|
|
88
|
+
if (name === 'animate' || name === 'speed') {
|
|
89
|
+
this.timeVars();
|
|
90
|
+
this.syncChoices();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (name === 'view' || name === 'page-size' || name === 'columns') {
|
|
94
|
+
this.index = 0;
|
|
95
|
+
this.flip = null;
|
|
96
|
+
}
|
|
97
|
+
this.render(name === 'view', name === 'view' ? { kind: 'view', dir: 1 } : undefined);
|
|
98
|
+
}
|
|
76
99
|
get currentView() { let v = this.getAttribute('view'); return collectionViews.some(x => x.id === v) ? v : 'deck'; }
|
|
77
|
-
|
|
100
|
+
/** 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. */
|
|
101
|
+
get land() { return normalizeLanding(this.getAttribute('deck-land')); }
|
|
78
102
|
get fanOpen() { return this.getAttribute('fan') === 'open'; }
|
|
79
103
|
get stacked() { return ![...pages, ...scrolling].includes(this.currentView); }
|
|
104
|
+
get piled() { return pileViews.includes(this.currentView); }
|
|
105
|
+
get turnable() { return this.piled || this.currentView === 'fan'; }
|
|
80
106
|
q(selector) { return this.root.querySelector(selector); }
|
|
81
|
-
/** With `address`, the display, the fan
|
|
107
|
+
/** 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. */
|
|
82
108
|
readAddress() { try {
|
|
83
109
|
const params = new URLSearchParams(location.search);
|
|
84
110
|
for (const key of ADDRESS_KEYS) {
|
|
85
111
|
const value = params.get(key);
|
|
86
112
|
if (value === null)
|
|
87
113
|
continue;
|
|
88
|
-
const attr = key
|
|
114
|
+
const attr = NAMES[key] ?? key;
|
|
89
115
|
if (this.getAttribute(attr) !== value)
|
|
90
116
|
this.setAttribute(attr, value);
|
|
91
117
|
}
|
|
@@ -94,7 +120,7 @@ export class FudaCollection extends HTMLElement {
|
|
|
94
120
|
writeAddress() { if (!this.hasAttribute('address'))
|
|
95
121
|
return; clearTimeout(this.addressTimer); this.addressTimer = window.setTimeout(() => { try {
|
|
96
122
|
const url = new URL(location.href);
|
|
97
|
-
const want = { view: this.currentView === 'deck' ? null : this.currentView, fan: this.fanOpen ? 'open' : null, land: this.land === 'face-up' ? null : this.land };
|
|
123
|
+
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 };
|
|
98
124
|
for (const [k, v] of Object.entries(want)) {
|
|
99
125
|
if (v === null)
|
|
100
126
|
url.searchParams.delete(k);
|
|
@@ -113,12 +139,12 @@ export class FudaCollection extends HTMLElement {
|
|
|
113
139
|
}
|
|
114
140
|
else {
|
|
115
141
|
const next = (this.index + n + this.data.length) % this.data.length;
|
|
116
|
-
this.flip =
|
|
142
|
+
this.flip = this.piled && Math.abs(n) === 1 && next === this.index + n ? (n > 0 ? 'off' : 'back') : null;
|
|
117
143
|
this.index = next;
|
|
118
144
|
}
|
|
119
|
-
this.render();
|
|
145
|
+
this.render(false, { kind: 'move', dir: n > 0 ? 1 : -1 });
|
|
120
146
|
}
|
|
121
|
-
image(c) { let button = document.createElement('button'); button.className = 'card'; button.setAttribute('aria-label', `Inspect ${c.name}`); let img = document.createElement('img'); img.src = c.image; img.alt = c.name; img.loading = 'lazy'; img.onerror = () => { img.replaceWith(document.createTextNode(`Image unavailable: ${c.name}`)); }; button.append(img); button.onclick = () => this.open(c); return button; }
|
|
147
|
+
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; }
|
|
122
148
|
open(c) { this.selected = c; this.back = false; this.renderDialog(); }
|
|
123
149
|
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) {
|
|
124
150
|
let img = document.createElement('img');
|
|
@@ -137,48 +163,62 @@ export class FudaCollection extends HTMLElement {
|
|
|
137
163
|
} if (!dlg.open)
|
|
138
164
|
dlg.showModal(); }
|
|
139
165
|
canDraw() { const query = this.drawFilter.trim().toLocaleLowerCase(); return this.data.some(c => c.name.toLocaleLowerCase().includes(query)); }
|
|
166
|
+
/** The one length every move takes, in a custom property the stylesheet reads: `animate="off"` and reduced motion make it 0, `speed` stretches it. */
|
|
167
|
+
timeVars() { const t = timing(this, true), shell = this.root.querySelector('.shell'); if (!shell)
|
|
168
|
+
return t; shell.style.setProperty('--t', t.on ? `${t.ms}ms` : '0s'); if (t.on)
|
|
169
|
+
shell.style.removeProperty('--stag');
|
|
170
|
+
else
|
|
171
|
+
shell.style.setProperty('--stag', '0ms'); return t; }
|
|
172
|
+
syncChoices() { this.animateChoice?.set(this.getAttribute('animate') === 'off' ? 'off' : 'on'); this.speedChoice?.set(['slow', 'quick'].includes(this.getAttribute('speed') ?? '') ? this.getAttribute('speed') : 'normal'); }
|
|
140
173
|
build() {
|
|
141
174
|
if (this.zoom)
|
|
142
175
|
return;
|
|
143
176
|
this.root.innerHTML = STYLE + SHELL;
|
|
177
|
+
const keep = (attr, value) => { if (value === null)
|
|
178
|
+
this.removeAttribute(attr);
|
|
179
|
+
else
|
|
180
|
+
this.setAttribute(attr, value); this.writeAddress(); };
|
|
144
181
|
this.tiles = createChoice({ label: 'Display', layout: 'tiles', value: this.currentView, options: collectionViews.map(v => ({ value: v.id, label: v.label, icon: icon(v.id) })), onChange: value => { this.setAttribute('view', value); this.writeAddress(); } });
|
|
145
182
|
this.q('.displays').append(this.tiles.element);
|
|
146
|
-
this.landing = createChoice({ label: 'A card
|
|
147
|
-
this.fanChoice = createChoice({ label: 'Fan', value: this.fanOpen ? 'open' : 'closed', options: [{ value: 'closed', label: 'Closed
|
|
183
|
+
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(); } });
|
|
184
|
+
this.fanChoice = createChoice({ label: 'Fan', value: this.fanOpen ? 'open' : 'closed', options: [{ value: 'closed', label: 'Closed' }, { value: 'open', label: 'Open' }], onChange: value => { if (value === 'open')
|
|
148
185
|
this.setAttribute('fan', 'open');
|
|
149
186
|
else
|
|
150
187
|
this.removeAttribute('fan'); this.writeAddress(); } });
|
|
151
|
-
this.
|
|
188
|
+
this.animateChoice = createChoice({ label: 'Animate', value: 'on', options: [{ value: 'on', label: 'On' }, { value: 'off', label: 'Off' }], onChange: value => keep('animate', value === 'off' ? 'off' : 'on') });
|
|
189
|
+
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) });
|
|
190
|
+
this.q('.opts').append(this.landing.element, this.fanChoice.element, this.animateChoice.element, this.speedChoice.element);
|
|
191
|
+
this.speedChoice.element.classList.add('speed');
|
|
152
192
|
this.q('.prev').onclick = () => this.move(-1);
|
|
153
193
|
this.q('.next').onclick = () => this.move(1);
|
|
154
194
|
const input = this.q('.draw-filter input'), draw = this.q('.draw');
|
|
155
195
|
input.oninput = () => { this.drawFilter = input.value; draw.disabled = !this.canDraw(); };
|
|
156
196
|
draw.onclick = () => { const next = randomDrawIndex(this.data, this.index, this.drawFilter); if (next === null)
|
|
157
|
-
return; this.index = next; this.render(); };
|
|
197
|
+
return; this.index = next; this.render(false, { kind: 'move', dir: 1 }); };
|
|
158
198
|
const stage = this.q('.stage');
|
|
159
199
|
this.zoom = zoomView(stage, this.q('.v'), { address: this.hasAttribute('address'), items: '.card,.slot', theme: this.getAttribute('theme') ?? undefined });
|
|
160
200
|
let startX = 0;
|
|
161
201
|
stage.addEventListener('touchstart', e => { if (e.touches.length === 1)
|
|
162
202
|
startX = e.touches[0].clientX; }, { passive: true });
|
|
163
|
-
stage.addEventListener('touchend', e => { if (!this.stacked || this.
|
|
203
|
+
stage.addEventListener('touchend', e => { if (!this.stacked || this.piled || this.zoom.zoomed() || e.changedTouches.length !== 1)
|
|
164
204
|
return; const dx = e.changedTouches[0].clientX - startX; if (Math.abs(dx) > 45) {
|
|
165
205
|
if (e.cancelable)
|
|
166
206
|
e.preventDefault();
|
|
167
207
|
this.move(dx < 0 ? 1 : -1);
|
|
168
208
|
} }, { passive: false });
|
|
169
|
-
stage.addEventListener('keydown', (e) => { if (!this.stacked || this.
|
|
209
|
+
stage.addEventListener('keydown', (e) => { if (!this.stacked || this.piled || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft'))
|
|
170
210
|
return; e.preventDefault(); this.move(e.key === 'ArrowRight' ? 1 : -1); this.q('.stack .card:last-child')?.focus(); });
|
|
171
211
|
}
|
|
172
|
-
/** One pile of the deck. `positions` are data indexes from the bottom of the pile to its top; the cards under the top one lie nudged and turned from the seed and the top one lies square. */
|
|
173
|
-
pile(kind, positions) {
|
|
212
|
+
/** 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. */
|
|
213
|
+
pile(kind, positions, fan = []) {
|
|
174
214
|
const pile = document.createElement('div');
|
|
175
215
|
pile.className = `pile ${kind}-pile${kind === 'discard' ? ' discard' : ''}`;
|
|
176
216
|
pile.dataset.land = this.land;
|
|
177
217
|
const messy = Math.min(1, Math.max(0, Number(this.getAttribute('deck-messiness') ?? 0.3)));
|
|
178
218
|
const seed = Number(this.getAttribute('deck-seed') ?? 1) || 1;
|
|
179
|
-
const depth = Math.min(
|
|
219
|
+
const depth = Math.min(positions.length - 1, fan.length ? fan.length - 1 : 9);
|
|
180
220
|
const shown = positions.slice(positions.length - 1 - depth);
|
|
181
|
-
const places = stackLayout(positions.length, { messiness: messy, seed, depth
|
|
221
|
+
const places = stackLayout(positions.length, { messiness: messy, seed, depth });
|
|
182
222
|
shown.forEach((at, j) => {
|
|
183
223
|
const top = j === shown.length - 1, c = this.data[at], place = places[j];
|
|
184
224
|
const el = document.createElement('div');
|
|
@@ -190,6 +230,13 @@ export class FudaCollection extends HTMLElement {
|
|
|
190
230
|
el.style.setProperty('--r', String(place.rotate));
|
|
191
231
|
}
|
|
192
232
|
el.style.setProperty('--k', String(j));
|
|
233
|
+
el.style.setProperty('--j', String(shown.length - 1 - j));
|
|
234
|
+
const f = fan[shown.length - 1 - j];
|
|
235
|
+
if (f) {
|
|
236
|
+
el.style.setProperty('--fx', String(f.x));
|
|
237
|
+
el.style.setProperty('--fa', String(f.angle));
|
|
238
|
+
el.style.setProperty('--i', String(shown.length - 1 - j));
|
|
239
|
+
}
|
|
193
240
|
const fly = document.createElement('div');
|
|
194
241
|
fly.className = 'fly';
|
|
195
242
|
const turn = document.createElement('div');
|
|
@@ -218,11 +265,11 @@ export class FudaCollection extends HTMLElement {
|
|
|
218
265
|
turn.append(front, back);
|
|
219
266
|
fly.append(turn);
|
|
220
267
|
el.append(fly);
|
|
268
|
+
el.onclick = () => this.open(c);
|
|
221
269
|
if (top) {
|
|
222
270
|
el.setAttribute('role', 'button');
|
|
223
|
-
el.tabIndex = 0;
|
|
224
271
|
el.setAttribute('aria-label', `Inspect ${c.name}`);
|
|
225
|
-
el.
|
|
272
|
+
el.tabIndex = 0;
|
|
226
273
|
el.onkeydown = e => { if (e.key === 'Enter' || e.key === ' ') {
|
|
227
274
|
e.preventDefault();
|
|
228
275
|
this.open(c);
|
|
@@ -232,64 +279,133 @@ export class FudaCollection extends HTMLElement {
|
|
|
232
279
|
});
|
|
233
280
|
return pile;
|
|
234
281
|
}
|
|
235
|
-
|
|
282
|
+
/** 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. */
|
|
283
|
+
fanFor(count) { const narrow = (this.clientWidth || innerWidth) < 520; return fanLayout(count, Number(this.getAttribute('deck-seed') ?? 1) || 1, narrow ? 0.3 : 0.34); }
|
|
284
|
+
/** 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. */
|
|
285
|
+
fanVars(v, open) {
|
|
286
|
+
const b = open && this.fanPlaces.length > 1 ? fanBounds(this.fanPlaces) : { left: 0, right: 0, top: 0, bottom: 0 };
|
|
287
|
+
v.classList.toggle('fan-open', open && this.fanPlaces.length > 1);
|
|
288
|
+
for (const [k, x] of [['--fl', b.left], ['--fr', b.right], ['--ft', b.top], ['--fb', b.bottom]])
|
|
289
|
+
v.style.setProperty(k, String(x));
|
|
290
|
+
}
|
|
291
|
+
/** `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. */
|
|
292
|
+
setFan() {
|
|
293
|
+
if (!this.zoom || !(this.piled || this.currentView === 'fan'))
|
|
294
|
+
return false;
|
|
295
|
+
const v = this.q('.v');
|
|
296
|
+
if (!v.classList.contains('deck') || !this.data.length)
|
|
297
|
+
return false;
|
|
298
|
+
const t = this.timeVars();
|
|
299
|
+
this.zoom.animated(() => { this.fanVars(v, this.fanOpen); this.zoom.refresh(); }, t.on ? t.ms : 0);
|
|
300
|
+
this.syncChoices();
|
|
301
|
+
this.fanChoice.set(this.fanOpen ? 'open' : 'closed');
|
|
302
|
+
this.writeAddress();
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
renderDeck(v, fanOnly = false) {
|
|
236
306
|
const n = this.data.length, deckPositions = [], discardPositions = [];
|
|
237
|
-
// The deck is the cards from the top card down (bottom first); the pile is the cards already flipped off, the last one on top.
|
|
238
|
-
for (let p = 0; p < n - this.index; p++)
|
|
239
|
-
deckPositions.push(n - 1 - p);
|
|
240
|
-
for (let p = 0; p < this.index; p++)
|
|
241
|
-
discardPositions.push(p);
|
|
242
307
|
v.classList.add('deck');
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
308
|
+
if (fanOnly) {
|
|
309
|
+
const size = Math.min(10, Math.max(2, Math.floor(Number(this.getAttribute('fan-size')) || 10))), count = Math.min(size, n);
|
|
310
|
+
// The fan window: `count` cards from the first one, wrapping round; the top card is the first and lies on the left when open.
|
|
311
|
+
for (let p = count - 1; p >= 0; p--)
|
|
312
|
+
deckPositions.push((this.index + p) % n);
|
|
313
|
+
v.classList.add('fanonly');
|
|
314
|
+
this.fanPlaces = this.fanFor(count);
|
|
315
|
+
v.append(this.pile('deck', deckPositions, this.fanPlaces));
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
// 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.
|
|
319
|
+
for (let p = 0; p < n - this.index; p++)
|
|
320
|
+
deckPositions.push(n - 1 - p);
|
|
321
|
+
for (let p = 0; p < this.index; p++)
|
|
322
|
+
discardPositions.push(p);
|
|
323
|
+
this.fanPlaces = this.fanFor(Math.min(10, deckPositions.length));
|
|
324
|
+
const slot = () => { const s = document.createElement('div'); s.className = 'slot'; return s; };
|
|
325
|
+
// 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.
|
|
326
|
+
v.append(deckPositions.length ? this.pile('deck', deckPositions, this.fanPlaces) : slot(), discardPositions.length ? this.pile('discard', discardPositions) : slot());
|
|
327
|
+
}
|
|
328
|
+
const extent = document.createElement('div');
|
|
329
|
+
extent.className = 'extent';
|
|
330
|
+
v.append(extent);
|
|
331
|
+
this.fanVars(v, this.fanOpen);
|
|
249
332
|
}
|
|
250
|
-
/** The card that just moved flies between the two piles, turning over on the way if it lands face down
|
|
251
|
-
playFlip(direction, v) {
|
|
333
|
+
/** 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. */
|
|
334
|
+
playFlip(direction, v, ms) {
|
|
252
335
|
const deck = v.querySelector('.deck-pile'), discard = v.querySelector('.discard-pile');
|
|
253
336
|
const moved = direction === 'off' ? discard?.querySelector('.card.top') : deck?.querySelector('.card.top');
|
|
254
337
|
if (!moved || !deck || !discard)
|
|
255
338
|
return;
|
|
256
|
-
const
|
|
339
|
+
const style = getComputedStyle(v), w = parseFloat(style.getPropertyValue('--w')) || 200, gap = parseFloat(style.getPropertyValue('--gap')) || 56, fr = parseFloat(v.style.getPropertyValue('--fr')) || 0;
|
|
340
|
+
const dx = (1 + fr) * w + gap, dy = 0;
|
|
257
341
|
const fly = moved.querySelector('.fly'), turn = moved.querySelector('.turn');
|
|
258
|
-
const
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
turn.animate(direction === 'off' ? [{ transform: 'none' }, { transform: final }] : [{ transform: final }, { transform: 'none' }], options);
|
|
342
|
+
const lead = this.fanOpen && this.fanPlaces.length > 1 ? this.fanPlaces[0] : null, shift = lead ? fanShift(lead) : { x: 0, y: 0 };
|
|
343
|
+
const away = { x: shift.x * w, y: shift.y * w }, spin = lead ? lead.angle : 0;
|
|
344
|
+
// Taking a card off an open fan starts it where the fan holds it; bringing it back ends there.
|
|
345
|
+
const from = direction === 'off' ? { x: -dx + away.x, y: -dy + away.y } : { x: dx - away.x, y: dy - away.y };
|
|
346
|
+
flight(fly, turn, from, this.land, direction, ms, direction === 'off' ? spin : -spin);
|
|
264
347
|
}
|
|
265
|
-
renderFan(v) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
348
|
+
renderFan(v) { this.renderDeck(v, true); }
|
|
349
|
+
/** Where every card is on screen now, by data index. */
|
|
350
|
+
snapshot(v) { const m = new Map(); v.querySelectorAll('[data-i]:not(.ghost)').forEach(el => m.set(el.dataset.i, el.getBoundingClientRect())); return m; }
|
|
351
|
+
/** 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. */
|
|
352
|
+
enter(els, ms, dir = 0, stagger = 18) { let k = 0; for (const el of els)
|
|
353
|
+
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' }); }
|
|
354
|
+
/** 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. */
|
|
355
|
+
play(how, before, left, view, v, ms) {
|
|
356
|
+
if (how.kind === 'view') {
|
|
357
|
+
this.enter(Array.from(v.querySelectorAll('.card,.slot')), ms * 0.7);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (pages.includes(view)) {
|
|
361
|
+
this.enter(Array.from(v.querySelectorAll('.card')), ms * 0.7, how.dir);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (scrolling.includes(view)) {
|
|
365
|
+
const el = v.querySelector(`[data-i="${this.index}"]`);
|
|
366
|
+
if (el)
|
|
367
|
+
this.zoom.reveal(el, ms);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
if (!gliding.includes(view) || this.zoom.turned())
|
|
371
|
+
return;
|
|
372
|
+
const scale = v.offsetWidth ? v.getBoundingClientRect().width / v.offsetWidth : 1;
|
|
373
|
+
const kept = new Set();
|
|
374
|
+
for (const el of Array.from(v.querySelectorAll('.card[data-i]'))) {
|
|
375
|
+
const was = before.get(el.dataset.i), now = el.getBoundingClientRect();
|
|
376
|
+
if (!was || !now.width) {
|
|
377
|
+
this.enter([el], ms * 0.7, how.dir);
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
kept.add(el.dataset.i);
|
|
381
|
+
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;
|
|
382
|
+
el.animate([{ translate: `${dx}px ${dy}px`, scale: was.width / now.width, offset: 0 }], { duration: ms, easing: 'cubic-bezier(.2,.8,.2,1)' });
|
|
383
|
+
}
|
|
384
|
+
const host = v.querySelector('.deck-pile') ?? v;
|
|
385
|
+
for (const old of left) {
|
|
386
|
+
if (kept.has(old.dataset.i))
|
|
387
|
+
continue;
|
|
388
|
+
old.classList.add('ghost');
|
|
389
|
+
old.removeAttribute('role');
|
|
390
|
+
old.tabIndex = -1;
|
|
391
|
+
host.append(old);
|
|
392
|
+
const done = () => old.remove();
|
|
393
|
+
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);
|
|
394
|
+
}
|
|
282
395
|
}
|
|
283
|
-
render(reset = false) {
|
|
396
|
+
render(reset = false, how) {
|
|
284
397
|
if (!this.isConnected)
|
|
285
398
|
return;
|
|
286
399
|
this.build();
|
|
287
400
|
let view = this.currentView, stage = this.q('.stage'), v = this.q('.v');
|
|
401
|
+
const t = this.timeVars(), playing = t.on && how && this.data.length > 0;
|
|
402
|
+
const before = playing ? this.snapshot(v) : new Map(), left = playing && how.kind === 'move' && gliding.includes(view) ? Array.from(v.querySelectorAll('.card:not(.ghost)')) : [];
|
|
288
403
|
this.tiles.set(view);
|
|
289
404
|
this.landing.set(this.land);
|
|
290
405
|
this.fanChoice.set(this.fanOpen ? 'open' : 'closed');
|
|
291
|
-
this.
|
|
292
|
-
this.
|
|
406
|
+
this.syncChoices();
|
|
407
|
+
this.landing.hidden = !this.piled;
|
|
408
|
+
this.fanChoice.hidden = !(this.piled || view === 'fan');
|
|
293
409
|
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';
|
|
294
410
|
for (const selector of ['.prev', '.next'])
|
|
295
411
|
this.q(selector).disabled = !this.data.length;
|
|
@@ -302,12 +418,15 @@ export class FudaCollection extends HTMLElement {
|
|
|
302
418
|
v.className = 'v';
|
|
303
419
|
v.replaceChildren();
|
|
304
420
|
v.style.removeProperty('--columns');
|
|
421
|
+
for (const k of ['--fl', '--fr', '--ft', '--fb'])
|
|
422
|
+
v.style.removeProperty(k);
|
|
305
423
|
this.zoom.minOpen = scrolling.includes(view) ? .5 : 0;
|
|
306
|
-
this.zoom.setTurnable(
|
|
424
|
+
this.zoom.setTurnable(this.turnable && this.data.length > 0);
|
|
425
|
+
this.zoom.items = this.piled || view === 'fan' ? '.extent' : '.card,.slot';
|
|
307
426
|
if (!this.data.length) {
|
|
308
427
|
v.innerHTML = '<p class="empty">No cards in this collection.</p>';
|
|
309
428
|
}
|
|
310
|
-
else if (
|
|
429
|
+
else if (this.piled)
|
|
311
430
|
this.renderDeck(v);
|
|
312
431
|
else if (view === 'fan')
|
|
313
432
|
this.renderFan(v);
|
|
@@ -316,32 +435,38 @@ export class FudaCollection extends HTMLElement {
|
|
|
316
435
|
const columns = Math.min(10, Math.max(1, Math.floor(Number(this.getAttribute('columns')) || 3)));
|
|
317
436
|
v.style.setProperty('--columns', String(columns));
|
|
318
437
|
let start = Math.floor(this.index / this.pageSize) * this.pageSize;
|
|
319
|
-
this.data.slice(start, start + this.pageSize).forEach(c => v.append(this.image(c)));
|
|
438
|
+
this.data.slice(start, start + this.pageSize).forEach((c, k) => v.append(this.image(c, start + k)));
|
|
320
439
|
}
|
|
321
440
|
else if (view === 'wall' || view === 'story') {
|
|
322
441
|
v.classList.add(view);
|
|
323
|
-
this.data.forEach(c => v.append(this.image(c)));
|
|
442
|
+
this.data.forEach((c, k) => v.append(this.image(c, k)));
|
|
324
443
|
}
|
|
325
444
|
else if (view === 'atlas') {
|
|
326
445
|
v.classList.add('atlas');
|
|
327
446
|
let plane = document.createElement('div');
|
|
328
447
|
plane.className = 'plane';
|
|
329
|
-
this.data.forEach(c => plane.append(this.image(c)));
|
|
448
|
+
this.data.forEach((c, k) => plane.append(this.image(c, k)));
|
|
330
449
|
v.append(plane);
|
|
331
450
|
}
|
|
332
451
|
else {
|
|
333
452
|
v.classList.add('stack', view);
|
|
334
453
|
let count = Math.min(3, this.data.length);
|
|
335
454
|
for (let d = count - 1; d >= 0; d--) {
|
|
336
|
-
|
|
455
|
+
const at = (this.index + d) % this.data.length;
|
|
456
|
+
let c = this.data[at], el = this.image(c, at);
|
|
337
457
|
let offset = view === 'rolodex' ? d * 42 : view === 'spotlight' ? d * 70 : d * 14;
|
|
338
|
-
let rotation = view === 'rolodex' ? d * 12 :
|
|
458
|
+
let rotation = view === 'rolodex' ? d * 12 : d * 5;
|
|
339
459
|
el.style.transform = `translateX(calc(-50% + ${offset}px)) rotate(${rotation}deg) scale(${1 - d * .08})`;
|
|
340
460
|
el.style.opacity = String(1 - d * .2);
|
|
341
461
|
v.append(el);
|
|
342
462
|
}
|
|
343
463
|
}
|
|
344
464
|
this.zoom.refresh(reset);
|
|
465
|
+
if (this.flip && this.piled && t.on && this.data.length > 1)
|
|
466
|
+
this.playFlip(this.flip, v, Math.round(t.ms * 1.15));
|
|
467
|
+
this.flip = null;
|
|
468
|
+
if (playing)
|
|
469
|
+
this.play(how, before, left, view, v, t.ms);
|
|
345
470
|
}
|
|
346
471
|
}
|
|
347
472
|
if (!customElements.get('fuda-collection'))
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
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
4
|
export type CollectionView = 'deck' | 'rolodex' | 'binder' | 'case' | 'jukebox' | 'random' | 'story' | 'wall' | 'tower' | 'spotlight' | 'atlas' | 'fan';
|
|
3
5
|
export interface CollectionMetadata {
|
|
@@ -26,19 +28,3 @@ export declare function parseCollection(value: unknown): CollectionCard[];
|
|
|
26
28
|
export declare function randomDrawIndex(cards: CollectionCard[], current: number, filter: string, random?: () => number): number | null;
|
|
27
29
|
/** Return the first card index of a wrapped page. */
|
|
28
30
|
export declare function movePage(index: number, length: number, pageSize: number, delta: number): number;
|
|
29
|
-
/** How a card flipped off the deck lands on the pile at its other side. */
|
|
30
|
-
export type DeckLanding = 'face-up' | 'upside-down' | 'face-down';
|
|
31
|
-
export declare const deckLandings: ReadonlyArray<{
|
|
32
|
-
id: DeckLanding;
|
|
33
|
-
label: string;
|
|
34
|
-
}>;
|
|
35
|
-
/** Where the cards of a fan lie, first card on the left when open and on top when closed. `open` is the fan spread like a hand of playing cards; `closed` is the squared-up deck it starts from and closes back to. */
|
|
36
|
-
export interface FanPlace {
|
|
37
|
-
angle: number;
|
|
38
|
-
x: number;
|
|
39
|
-
y: number;
|
|
40
|
-
closedAngle: number;
|
|
41
|
-
closedX: number;
|
|
42
|
-
closedY: number;
|
|
43
|
-
}
|
|
44
|
-
export declare function fanLayout(count: number, seed?: number): FanPlace[];
|
package/dist/collection.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { fanLayout, deckLandings, normalizeLanding } from './pile.js';
|
|
2
2
|
export const collectionViews = [
|
|
3
3
|
{ id: 'deck', label: 'Overlapping Deck' }, { id: 'rolodex', label: 'Rolodex' }, { id: 'binder', label: 'Binder Pages' },
|
|
4
4
|
{ id: 'case', label: 'Convention Display Case' }, { id: 'jukebox', label: 'Jukebox Carousel' }, { id: 'random', label: 'Random Draw' },
|
|
@@ -63,24 +63,3 @@ export function movePage(index, length, pageSize, delta) {
|
|
|
63
63
|
const page = Math.floor(index / pageSize);
|
|
64
64
|
return (((page + delta) % pages + pages) % pages) * pageSize;
|
|
65
65
|
}
|
|
66
|
-
export const deckLandings = [
|
|
67
|
-
{ id: 'face-up', label: 'Still facing up' }, { id: 'upside-down', label: 'Upside down' }, { id: 'face-down', label: 'Face down' }
|
|
68
|
-
];
|
|
69
|
-
export function fanLayout(count, seed = 1) {
|
|
70
|
-
const n = Math.max(0, Math.floor(count));
|
|
71
|
-
if (!n)
|
|
72
|
-
return [];
|
|
73
|
-
const spread = Math.min(110, 11 * (n - 1)), step = n > 1 ? spread / (n - 1) : 0;
|
|
74
|
-
const nudge = stackLayout(n, { messiness: 0.25, seed, depth: n });
|
|
75
|
-
return Array.from({ length: n }, (_, i) => {
|
|
76
|
-
const under = i >= 1 ? nudge[i - 1] : undefined;
|
|
77
|
-
return {
|
|
78
|
-
angle: Math.round((-spread / 2 + i * step) * 100) / 100,
|
|
79
|
-
x: Math.round((i - (n - 1) / 2) * 0.34 * 1000) / 1000,
|
|
80
|
-
y: 0,
|
|
81
|
-
closedAngle: under ? under.rotate / 3 : 0,
|
|
82
|
-
closedX: under ? under.x : 0,
|
|
83
|
-
closedY: under ? under.y : 0
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
package/dist/element.d.ts
CHANGED
|
@@ -22,6 +22,25 @@ export declare class FudaCard extends HTMLElement {
|
|
|
22
22
|
get stackCount(): number;
|
|
23
23
|
/** Height of the stack in millimetres: the count times a card's thickness. */
|
|
24
24
|
get stackHeight(): number;
|
|
25
|
+
/** How many cards are still in the stack: `stack` less the `taken-off` ones (at least one stays). */
|
|
26
|
+
get heldCount(): number;
|
|
27
|
+
/** True while the stack is fanned open (`fan="open"`, with more than one card). */
|
|
28
|
+
get fanOpen(): boolean;
|
|
29
|
+
/** How far the pile reaches beyond the card's own box, in card widths: an open fan and the pile of cards taken off. It is zero until a pile feature is used. Pages use it to fit the view; `fuda-pile` is sent when it changes. */
|
|
30
|
+
pileBounds: {
|
|
31
|
+
left: number;
|
|
32
|
+
right: number;
|
|
33
|
+
top: number;
|
|
34
|
+
bottom: number;
|
|
35
|
+
};
|
|
36
|
+
/** Take the top card (or `count` cards) off the stack: it flies to a pile at the stack's side and lands as `deck-land` says. At least one card stays. */
|
|
37
|
+
takeOff(count?: number): void;
|
|
38
|
+
/** Bring the card (or `count` cards) back from the pile onto the stack. */
|
|
39
|
+
putBack(count?: number): void;
|
|
40
|
+
pileUsed: boolean;
|
|
41
|
+
private pileModule?;
|
|
42
|
+
/** Fanning, the pile of cards taken off and the controls are drawn by a module that is loaded only when a stack asks for them; a card without them never loads it. */
|
|
43
|
+
private applyPile;
|
|
25
44
|
private wearKey;
|
|
26
45
|
private wearToken;
|
|
27
46
|
private wearModule?;
|