@johnmorrisdotca/fuda-cards 0.10.1 → 0.12.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/LICENSE +21 -0
- package/NOTICE.md +16 -0
- package/README.md +106 -33
- package/dist/binder.d.ts +4 -6
- package/dist/binder.js +32 -23
- package/dist/card-markup.d.ts +2 -0
- package/dist/card-markup.js +59 -0
- package/dist/card-options.d.ts +131 -0
- package/dist/card-options.js +48 -0
- package/dist/card-styles.d.ts +2 -0
- package/dist/card-styles.js +314 -0
- package/dist/choice.d.ts +1 -1
- package/dist/choice.js +27 -23
- package/dist/collection-address.d.ts +8 -0
- package/dist/collection-address.js +52 -0
- package/dist/collection-binder-view.d.ts +9 -0
- package/dist/collection-binder-view.js +123 -0
- package/dist/collection-controls.d.ts +2 -0
- package/dist/collection-controls.js +143 -0
- package/dist/collection-deck.d.ts +11 -0
- package/dist/collection-deck.js +165 -0
- package/dist/collection-dialog.d.ts +2 -0
- package/dist/collection-dialog.js +28 -0
- package/dist/collection-element.d.ts +36 -67
- package/dist/collection-element.js +283 -484
- package/dist/collection-host.d.ts +5 -0
- package/dist/collection-host.js +1 -0
- package/dist/collection-icons.d.ts +3 -0
- package/dist/collection-icons.js +19 -0
- package/dist/collection-motion.d.ts +11 -0
- package/dist/collection-motion.js +72 -0
- package/dist/collection-styles.d.ts +4 -0
- package/dist/collection-styles.js +336 -0
- package/dist/collection-views.d.ts +8 -0
- package/dist/collection-views.js +8 -0
- package/dist/collection.d.ts +154 -11
- package/dist/collection.js +140 -34
- package/dist/element-define.d.ts +2 -0
- package/dist/element-define.js +3 -0
- package/dist/element.d.ts +20 -1
- package/dist/element.js +289 -98
- package/dist/index.d.ts +9 -52
- package/dist/index.js +5 -5
- package/dist/live-3d.d.ts +87 -4
- package/dist/live-3d.js +120 -52
- package/dist/materials.d.ts +117 -6
- package/dist/materials.js +246 -28
- package/dist/motion.d.ts +2 -0
- package/dist/motion.js +4 -0
- package/dist/pile-card.js +138 -91
- package/dist/pile.d.ts +61 -8
- package/dist/pile.js +89 -29
- package/dist/stack.d.ts +42 -6
- package/dist/stack.js +28 -3
- package/dist/version.d.ts +11 -0
- package/dist/version.js +11 -0
- package/dist/wear.d.ts +147 -9
- package/dist/wear.js +273 -89
- package/dist/zoom.d.ts +1 -1
- package/dist/zoom.js +73 -42
- package/docs/API.md +138 -134
- package/docs/collection-displays.md +4 -4
- package/docs/collection-input.md +5 -5
- package/docs/framework-integration.md +1 -1
- package/docs/guides/architecture.md +8 -8
- package/docs/guides/bundlers.md +60 -0
- package/docs/guides/card-element.md +26 -2
- package/docs/guides/collections.md +2 -2
- package/docs/guides/embed-in-an-iframe.md +39 -0
- package/docs/guides/frameworks.md +93 -66
- package/docs/guides/getting-started.md +4 -2
- package/docs/guides/html-and-cdn.md +86 -0
- package/docs/guides/ja/architecture.md +4 -4
- package/docs/guides/ja/bundlers.md +60 -0
- package/docs/guides/ja/card-element.md +26 -2
- package/docs/guides/ja/collections.md +2 -2
- package/docs/guides/ja/embed-in-an-iframe.md +39 -0
- package/docs/guides/ja/frameworks.md +93 -66
- package/docs/guides/ja/getting-started.md +4 -2
- package/docs/guides/ja/html-and-cdn.md +86 -0
- package/docs/guides/ja/live-3d.md +37 -24
- package/docs/guides/ja/materials-and-stacks.md +4 -4
- package/docs/guides/ja/troubleshooting.md +2 -2
- package/docs/guides/ja/typescript-and-node.md +45 -0
- package/docs/guides/ja/upgrading.md +7 -2
- package/docs/guides/ja/wear.md +1 -1
- package/docs/guides/live-3d.md +37 -24
- package/docs/guides/materials-and-stacks.md +4 -4
- package/docs/guides/troubleshooting.md +2 -2
- package/docs/guides/typescript-and-node.md +45 -0
- package/docs/guides/upgrading.md +7 -2
- package/docs/guides/wear.md +1 -1
- package/docs/live-3d.md +1 -18
- package/docs/materials.md +15 -11
- package/docs/wear.md +4 -12
- package/package.json +57 -10
|
@@ -1,162 +1,197 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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}
|
|
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)}
|
|
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}
|
|
31
|
-
.pile.discard[data-land=face-down] .card:not(.flat) .turn{transform:rotateY(180deg)}.card.flat .turn{transform:rotateY(calc(var(--fuda-yaw,0) * -1deg)) rotateX(calc(var(--fuda-tilt,0) * -1deg))}.ghost{pointer-events:none}
|
|
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}
|
|
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}}
|
|
34
|
-
</style>`;
|
|
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>`;
|
|
36
|
-
const pages = ['binder', 'case'];
|
|
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'];
|
|
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('');
|
|
43
|
-
const ICONS = {
|
|
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"/>',
|
|
45
|
-
rolodex: '<rect x="2" y="9" width="12" height="10" rx="1.5" opacity=".4"/><rect x="8" y="5" width="12" height="10" rx="1.5" opacity=".7"/><rect x="14" y="1" width="12" height="10" rx="1.5"/>',
|
|
46
|
-
binder: rects(3, 2, 9, 9, 11, 10, 2, 1),
|
|
47
|
-
case: '<path d="M3 4h28l-3 6H6z" opacity=".5"/><path d="M6 12h22l-3 8H9z"/>',
|
|
48
|
-
jukebox: '<path d="M5 20V9a12 9 0 0 1 24 0v11z" opacity=".5"/><rect x="11" y="9" width="12" height="9" rx="1.5"/>',
|
|
49
|
-
random: '<rect x="9" y="1" width="16" height="18" rx="3"/><circle cx="14" cy="6" r="1.6" fill="#0008"/><circle cx="20" cy="14" r="1.6" fill="#0008"/><circle cx="17" cy="10" r="1.6" fill="#0008"/>',
|
|
50
|
-
story: '<rect x="11" y="0" width="12" height="7" rx="1.5"/><rect x="11" y="8" width="12" height="7" rx="1.5" opacity=".7"/><rect x="11" y="16" width="12" height="6" rx="1.5" opacity=".4"/>',
|
|
51
|
-
wall: '<rect x="0" y="3" width="9" height="14" rx="1.5" opacity=".5"/><rect x="12" y="3" width="10" height="14" rx="1.5"/><rect x="25" y="3" width="9" height="14" rx="1.5" opacity=".5"/>',
|
|
52
|
-
tower: '<rect x="9" y="1" width="16" height="4" rx="1"/><rect x="9" y="7" width="16" height="4" rx="1" opacity=".8"/><rect x="9" y="13" width="16" height="4" rx="1" opacity=".6"/><rect x="9" y="19" width="16" height="3" rx="1" opacity=".4"/>',
|
|
53
|
-
spotlight: '<rect x="11" y="0" width="12" height="18" rx="2"/><rect x="1" y="5" width="8" height="12" rx="1.5" opacity=".4"/><rect x="25" y="5" width="8" height="12" rx="1.5" opacity=".4"/>',
|
|
54
|
-
atlas: rects(4, 3, 6, 5.5, 8, 7, 2, 1),
|
|
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('')
|
|
56
|
-
};
|
|
57
|
-
const icon = (view) => `<svg viewBox="0 0 34 22" aria-hidden="true">${ICONS[view]}</svg>`;
|
|
58
|
-
const ADDRESS_KEYS = ['view', 'fan', 'land', 'animate', 'speed', 'binder', 'cover', 'sheet', 'pockets'];
|
|
59
|
-
const NAMES = { land: 'deck-land' };
|
|
1
|
+
import { binderLayout, sideCount, spreadCount, spreadOf } from "./binder.js";
|
|
2
|
+
import { collectionViewAliases, collectionViews, isCard, movePage, parseCollection, } from "./collection.js";
|
|
3
|
+
import { readAddress, writeAddress } from "./collection-address.js";
|
|
4
|
+
import { binderPageCount, renderBinder, syncBinderChoices } from "./collection-binder-view.js";
|
|
5
|
+
import { buildControls } from "./collection-controls.js";
|
|
6
|
+
import { applyFan, playFlip, renderDeck } from "./collection-deck.js";
|
|
7
|
+
import { renderDetail } from "./collection-dialog.js";
|
|
8
|
+
import { playMove, snapshotRects } from "./collection-motion.js";
|
|
9
|
+
import { gliding, pages, pileViews, scrolling } from "./collection-views.js";
|
|
10
|
+
import { normalizeLanding, timing } from "./pile.js";
|
|
11
|
+
/**
|
|
12
|
+
* `<fuda-collection>`: a whole collection in one of ten displays (a deck, a rolodex, binder pages, a display case, a random draw, a story scroll, a gallery wall,
|
|
13
|
+
* a spotlight, a card table, a fan), with zoom, Fit and Centre, the choices kept in the page address and a card detail on a press. Give it
|
|
14
|
+
* `cards` (see {@link parseCollection}) and a `view`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts no-run
|
|
18
|
+
* import "@johnmorrisdotca/fuda-cards/collection-element";
|
|
19
|
+
* import type { FudaCollection } from "@johnmorrisdotca/fuda-cards/collection-element";
|
|
20
|
+
*
|
|
21
|
+
* const collection = document.createElement("fuda-collection") as FudaCollection;
|
|
22
|
+
* collection.setAttribute("view", "binder");
|
|
23
|
+
* collection.cards = { cards: [{ name: "Explorer One", image: "one.jpg" }] };
|
|
24
|
+
* document.body.append(collection);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
60
27
|
export class FudaCollection extends HTMLElement {
|
|
61
|
-
|
|
28
|
+
/** @internal */
|
|
29
|
+
root = this.attachShadow({ mode: "open" });
|
|
30
|
+
/** @internal */
|
|
62
31
|
data = [];
|
|
32
|
+
/** @internal */
|
|
63
33
|
index = 0;
|
|
34
|
+
/** @internal */
|
|
64
35
|
pageSize = 9;
|
|
36
|
+
/** @internal */
|
|
65
37
|
selected = null;
|
|
38
|
+
/** @internal */
|
|
66
39
|
back = false;
|
|
40
|
+
/** @internal */
|
|
67
41
|
drawFilter = "";
|
|
42
|
+
/** @internal */
|
|
68
43
|
zoom = null;
|
|
44
|
+
/** @internal */
|
|
69
45
|
tiles;
|
|
46
|
+
/** @internal */
|
|
70
47
|
landing;
|
|
48
|
+
/** @internal */
|
|
71
49
|
fanChoice;
|
|
50
|
+
/** @internal */
|
|
72
51
|
animateChoice;
|
|
52
|
+
/** @internal */
|
|
73
53
|
speedChoice;
|
|
54
|
+
/** @internal */
|
|
74
55
|
binderChoices = {};
|
|
56
|
+
/** @internal */
|
|
75
57
|
turn = null;
|
|
58
|
+
/** @internal */
|
|
76
59
|
flip = null;
|
|
60
|
+
/** @internal */
|
|
77
61
|
addressTimer = 0;
|
|
62
|
+
/** @internal */
|
|
78
63
|
fanPlaces = [];
|
|
79
64
|
liveSetup = null;
|
|
80
65
|
liveOff = [];
|
|
81
|
-
static get observedAttributes() {
|
|
82
|
-
|
|
83
|
-
|
|
66
|
+
static get observedAttributes() {
|
|
67
|
+
return [
|
|
68
|
+
"view",
|
|
69
|
+
"page-size",
|
|
70
|
+
"columns",
|
|
71
|
+
"fan",
|
|
72
|
+
"fan-size",
|
|
73
|
+
"deck-land",
|
|
74
|
+
"deck-messiness",
|
|
75
|
+
"deck-seed",
|
|
76
|
+
"theme",
|
|
77
|
+
"animate",
|
|
78
|
+
"speed",
|
|
79
|
+
"binder",
|
|
80
|
+
"cover",
|
|
81
|
+
"sheet",
|
|
82
|
+
"pockets",
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
set cards(value) {
|
|
86
|
+
this.data = parseCollection(value);
|
|
87
|
+
this.index = Math.min(this.index, Math.max(0, this.data.length - 1));
|
|
88
|
+
this.flip = null;
|
|
89
|
+
this.render();
|
|
90
|
+
}
|
|
91
|
+
get cards() {
|
|
92
|
+
return this.data.map((c) => ({ ...c, ...(c.metadata ? { metadata: { ...c.metadata } } : {}) }));
|
|
93
|
+
}
|
|
84
94
|
/** Live 3D: the card in focus turns in 3D on the page's one WebGL context, and every other card stays its picture. Nothing 3D loads until a card is focused. */
|
|
85
|
-
set live(value) {
|
|
86
|
-
|
|
95
|
+
set live(value) {
|
|
96
|
+
this.liveSetup = value;
|
|
97
|
+
this.render();
|
|
98
|
+
}
|
|
99
|
+
get live() {
|
|
100
|
+
return this.liveSetup;
|
|
101
|
+
}
|
|
87
102
|
/** The cards are drawn again on every move, so their live views are made again too: the pictures stay in the shared cache. */
|
|
88
|
-
attachLive(v) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
103
|
+
attachLive(v) {
|
|
104
|
+
for (const off of this.liveOff)
|
|
105
|
+
off();
|
|
106
|
+
this.liveOff = [];
|
|
107
|
+
const setup = this.liveSetup;
|
|
108
|
+
if (!setup)
|
|
109
|
+
return;
|
|
110
|
+
for (const el of Array.from(v.querySelectorAll(".card[data-i]:not(.ghost)"))) {
|
|
111
|
+
const c = this.data[Number(el.dataset.i)];
|
|
112
|
+
const item = c && setup.item(c);
|
|
113
|
+
if (!item)
|
|
114
|
+
continue;
|
|
115
|
+
const still = el.querySelector("img") ?? undefined;
|
|
116
|
+
this.liveOff.push(setup.cards.add(el, item, still ? { still } : {}));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
97
119
|
/** The card on top of the deck, or the first card of the page or fan (counting from 0). */
|
|
98
|
-
get position() {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
120
|
+
get position() {
|
|
121
|
+
return this.index;
|
|
122
|
+
}
|
|
123
|
+
connectedCallback() {
|
|
124
|
+
if (this.hasAttribute("address"))
|
|
125
|
+
readAddress(this);
|
|
126
|
+
this.render();
|
|
127
|
+
}
|
|
128
|
+
disconnectedCallback() {
|
|
129
|
+
clearTimeout(this.addressTimer);
|
|
130
|
+
for (const off of this.liveOff)
|
|
131
|
+
off();
|
|
132
|
+
this.liveOff = [];
|
|
133
|
+
}
|
|
103
134
|
attributeChangedCallback(name) {
|
|
104
|
-
this.pageSize = Math.min(100, Math.max(1, Math.floor(Number(this.getAttribute(
|
|
105
|
-
if (name ===
|
|
135
|
+
this.pageSize = Math.min(100, Math.max(1, Math.floor(Number(this.getAttribute("page-size")) || 9)));
|
|
136
|
+
if (name === "fan" && this.setFan())
|
|
106
137
|
return;
|
|
107
|
-
if (name ===
|
|
138
|
+
if (name === "animate" || name === "speed") {
|
|
108
139
|
this.timeVars();
|
|
109
140
|
this.syncChoices();
|
|
110
141
|
return;
|
|
111
142
|
}
|
|
112
|
-
if (name ===
|
|
143
|
+
if (name === "view" || name === "page-size" || name === "columns") {
|
|
113
144
|
this.index = 0;
|
|
114
145
|
this.flip = null;
|
|
115
146
|
}
|
|
116
|
-
this.render(name ===
|
|
147
|
+
this.render(name === "view", name === "view" ? { kind: "view", dir: 1 } : undefined);
|
|
148
|
+
}
|
|
149
|
+
/** @internal */
|
|
150
|
+
get currentView() {
|
|
151
|
+
let v = this.getAttribute("view") ?? "";
|
|
152
|
+
v = collectionViewAliases[v] ?? v;
|
|
153
|
+
return collectionViews.some((x) => x.id === v) ? v : "deck";
|
|
117
154
|
}
|
|
118
|
-
get currentView() { let v = this.getAttribute('view') ?? ''; v = collectionViewAliases[v] ?? v; return collectionViews.some(x => x.id === v) ? v : 'deck'; }
|
|
119
155
|
/** 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. */
|
|
120
|
-
|
|
121
|
-
get
|
|
122
|
-
|
|
123
|
-
|
|
156
|
+
/** @internal */
|
|
157
|
+
get land() {
|
|
158
|
+
return normalizeLanding(this.getAttribute("deck-land"));
|
|
159
|
+
}
|
|
160
|
+
/** @internal */
|
|
161
|
+
get fanOpen() {
|
|
162
|
+
return this.getAttribute("fan") === "open";
|
|
163
|
+
}
|
|
164
|
+
/** @internal */
|
|
165
|
+
get stacked() {
|
|
166
|
+
return ![...pages, ...scrolling].includes(this.currentView);
|
|
167
|
+
}
|
|
168
|
+
/** @internal */
|
|
169
|
+
get piled() {
|
|
170
|
+
return pileViews.includes(this.currentView);
|
|
171
|
+
}
|
|
124
172
|
/** Only a card turns: a collection of objects (no card in it) never turns, and in a mixed one the objects stay square to the reader while the cards turn. */
|
|
125
|
-
|
|
126
|
-
get
|
|
127
|
-
|
|
128
|
-
/** 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. */
|
|
129
|
-
readAddress() { try {
|
|
130
|
-
const params = new URLSearchParams(location.search);
|
|
131
|
-
for (const key of ADDRESS_KEYS) {
|
|
132
|
-
const value = params.get(key);
|
|
133
|
-
if (value === null)
|
|
134
|
-
continue;
|
|
135
|
-
const attr = NAMES[key] ?? key;
|
|
136
|
-
if (this.getAttribute(attr) !== value)
|
|
137
|
-
this.setAttribute(attr, value);
|
|
138
|
-
}
|
|
173
|
+
/** @internal */
|
|
174
|
+
get hasCards() {
|
|
175
|
+
return this.data.some(isCard);
|
|
139
176
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
url.searchParams.delete(k);
|
|
148
|
-
else
|
|
149
|
-
url.searchParams.set(k, v);
|
|
150
|
-
}
|
|
151
|
-
history.replaceState(history.state, '', url);
|
|
177
|
+
/** @internal */
|
|
178
|
+
get turnable() {
|
|
179
|
+
return (this.piled || this.currentView === "fan") && this.hasCards;
|
|
180
|
+
}
|
|
181
|
+
/** @internal */
|
|
182
|
+
q(selector) {
|
|
183
|
+
return this.root.querySelector(selector);
|
|
152
184
|
}
|
|
153
|
-
|
|
185
|
+
/** @internal */
|
|
154
186
|
move(n) {
|
|
155
187
|
if (!this.data.length)
|
|
156
188
|
return;
|
|
157
189
|
const view = this.currentView;
|
|
158
|
-
if (view ===
|
|
159
|
-
const per = this.binderLay().per
|
|
190
|
+
if (view === "binder") {
|
|
191
|
+
const per = this.binderLay().per;
|
|
192
|
+
const spreads = spreadCount(sideCount(this.data.length, per));
|
|
193
|
+
const from = spreadOf(this.index, per);
|
|
194
|
+
const to = (from + n + spreads * Math.abs(n)) % spreads;
|
|
160
195
|
this.turn = { from, to };
|
|
161
196
|
this.index = this.spreadFirst(to);
|
|
162
197
|
}
|
|
@@ -165,420 +200,184 @@ export class FudaCollection extends HTMLElement {
|
|
|
165
200
|
}
|
|
166
201
|
else {
|
|
167
202
|
const next = (this.index + n + this.data.length) % this.data.length;
|
|
168
|
-
this.flip = this.piled && Math.abs(n) === 1 && next === this.index + n ? (n > 0 ?
|
|
203
|
+
this.flip = this.piled && Math.abs(n) === 1 && next === this.index + n ? (n > 0 ? "off" : "back") : null;
|
|
169
204
|
this.index = next;
|
|
170
205
|
}
|
|
171
|
-
this.render(false, { kind:
|
|
206
|
+
this.render(false, { kind: "move", dir: n > 0 ? 1 : -1 });
|
|
207
|
+
}
|
|
208
|
+
/** @internal */
|
|
209
|
+
binderLay() {
|
|
210
|
+
return binderLayout(this.getAttribute("pockets"), this.getAttribute("columns"), this.getAttribute("page-size"));
|
|
172
211
|
}
|
|
173
|
-
binderLay() { return binderLayout(this.getAttribute('pockets'), this.getAttribute('columns'), this.getAttribute('page-size')); }
|
|
174
212
|
/** 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. */
|
|
175
|
-
spreadFirst(spread) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
213
|
+
spreadFirst(spread) {
|
|
214
|
+
const per = this.binderLay().per;
|
|
215
|
+
const sides = sideCount(this.data.length, per);
|
|
216
|
+
return Math.min(this.data.length - 1, (2 * spread < sides ? 2 * spread : 2 * spread - 1) * per);
|
|
217
|
+
}
|
|
218
|
+
/** @internal */
|
|
219
|
+
image(c, at) {
|
|
220
|
+
const button = document.createElement("button");
|
|
221
|
+
button.className = "card";
|
|
222
|
+
button.dataset.i = String(at);
|
|
223
|
+
button.setAttribute("aria-label", `Inspect ${c.name}`);
|
|
224
|
+
const img = document.createElement("img");
|
|
225
|
+
img.src = c.image;
|
|
226
|
+
img.alt = c.name;
|
|
227
|
+
img.loading = "lazy";
|
|
228
|
+
img.onerror = () => {
|
|
229
|
+
img.replaceWith(document.createTextNode(`Image unavailable: ${c.name}`));
|
|
230
|
+
};
|
|
231
|
+
button.append(img);
|
|
232
|
+
button.onclick = () => this.open(c);
|
|
233
|
+
return button;
|
|
234
|
+
}
|
|
235
|
+
/** @internal */
|
|
236
|
+
open(c) {
|
|
237
|
+
this.selected = c;
|
|
238
|
+
this.back = false;
|
|
239
|
+
renderDetail(this);
|
|
240
|
+
}
|
|
241
|
+
/** @internal */
|
|
242
|
+
canDraw() {
|
|
243
|
+
const query = this.drawFilter.trim().toLocaleLowerCase();
|
|
244
|
+
return this.data.some((c) => c.name.toLocaleLowerCase().includes(query));
|
|
245
|
+
}
|
|
195
246
|
/** The one length every move takes, in a custom property the stylesheet reads: `animate="off"` and reduced motion make it 0, `speed` stretches it. */
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
shell
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
this.root.innerHTML = STYLE + SHELL;
|
|
206
|
-
const keep = (attr, value) => { if (value === null)
|
|
207
|
-
this.removeAttribute(attr);
|
|
247
|
+
/** @internal */
|
|
248
|
+
timeVars() {
|
|
249
|
+
const t = timing(this, true);
|
|
250
|
+
const shell = this.root.querySelector(".shell");
|
|
251
|
+
if (!shell)
|
|
252
|
+
return t;
|
|
253
|
+
shell.style.setProperty("--t", t.on ? `${t.ms}ms` : "0s");
|
|
254
|
+
if (t.on)
|
|
255
|
+
shell.style.removeProperty("--stag");
|
|
208
256
|
else
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this.q('.displays').append(this.tiles.element);
|
|
212
|
-
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(); } });
|
|
213
|
-
this.fanChoice = createChoice({ label: 'Fan', value: this.fanOpen ? 'open' : 'closed', options: [{ value: 'closed', label: 'Closed' }, { value: 'open', label: 'Open' }], onChange: value => { if (value === 'open')
|
|
214
|
-
this.setAttribute('fan', 'open');
|
|
215
|
-
else
|
|
216
|
-
this.removeAttribute('fan'); this.writeAddress(); } });
|
|
217
|
-
this.animateChoice = createChoice({ label: 'Animate', value: 'on', options: [{ value: 'on', label: 'On' }, { value: 'off', label: 'Off' }], onChange: value => keep('animate', value === 'off' ? 'off' : 'on') });
|
|
218
|
-
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) });
|
|
219
|
-
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; };
|
|
220
|
-
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);
|
|
221
|
-
this.speedChoice.element.classList.add('speed');
|
|
222
|
-
this.q('.prev').onclick = () => this.move(-1);
|
|
223
|
-
this.q('.next').onclick = () => this.move(1);
|
|
224
|
-
const input = this.q('.draw-filter input'), draw = this.q('.draw');
|
|
225
|
-
input.oninput = () => { this.drawFilter = input.value; draw.disabled = !this.canDraw(); };
|
|
226
|
-
draw.onclick = () => { const next = randomDrawIndex(this.data, this.index, this.drawFilter); if (next === null)
|
|
227
|
-
return; this.index = next; this.render(false, { kind: 'move', dir: 1 }); };
|
|
228
|
-
const stage = this.q('.stage');
|
|
229
|
-
this.zoom = zoomView(stage, this.q('.v'), { address: this.hasAttribute('address'), items: '.card,.slot', theme: this.getAttribute('theme') ?? undefined });
|
|
230
|
-
let startX = 0;
|
|
231
|
-
stage.addEventListener('touchstart', e => { if (e.touches.length === 1)
|
|
232
|
-
startX = e.touches[0].clientX; }, { passive: true });
|
|
233
|
-
stage.addEventListener('touchend', e => { if (!this.stacked || this.piled || this.zoom.zoomed() || e.changedTouches.length !== 1)
|
|
234
|
-
return; const dx = e.changedTouches[0].clientX - startX; if (Math.abs(dx) > 45) {
|
|
235
|
-
if (e.cancelable)
|
|
236
|
-
e.preventDefault();
|
|
237
|
-
this.move(dx < 0 ? 1 : -1);
|
|
238
|
-
} }, { passive: false });
|
|
239
|
-
stage.addEventListener('keydown', (e) => { if (!this.stacked || this.piled || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft'))
|
|
240
|
-
return; e.preventDefault(); this.move(e.key === 'ArrowRight' ? 1 : -1); this.q('.stack .card:last-child')?.focus(); });
|
|
257
|
+
shell.style.setProperty("--stag", "0ms");
|
|
258
|
+
return t;
|
|
241
259
|
}
|
|
242
|
-
/**
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
pile.dataset.land = this.land;
|
|
247
|
-
const messy = Math.min(1, Math.max(0, Number(this.getAttribute('deck-messiness') ?? 0.3)));
|
|
248
|
-
const seed = Number(this.getAttribute('deck-seed') ?? 1) || 1;
|
|
249
|
-
const depth = Math.min(positions.length - 1, fan.length ? fan.length - 1 : 9);
|
|
250
|
-
const shown = positions.slice(positions.length - 1 - depth);
|
|
251
|
-
const places = stackLayout(positions.length, { messiness: messy, seed, depth });
|
|
252
|
-
shown.forEach((at, j) => {
|
|
253
|
-
const top = j === shown.length - 1, c = this.data[at], place = places[j];
|
|
254
|
-
const el = document.createElement('div');
|
|
255
|
-
const flat = !isCard(c);
|
|
256
|
-
el.className = `card${top ? ' top' : ''}${flat ? ' flat' : ''}`;
|
|
257
|
-
el.dataset.i = String(at);
|
|
258
|
-
if (place && !top) {
|
|
259
|
-
el.style.setProperty('--x', String(place.x));
|
|
260
|
-
el.style.setProperty('--y', String(place.y));
|
|
261
|
-
el.style.setProperty('--r', String(place.rotate));
|
|
262
|
-
}
|
|
263
|
-
el.style.setProperty('--k', String(j));
|
|
264
|
-
el.style.setProperty('--j', String(shown.length - 1 - j));
|
|
265
|
-
const f = fan[shown.length - 1 - j];
|
|
266
|
-
if (f) {
|
|
267
|
-
el.style.setProperty('--fx', String(f.x));
|
|
268
|
-
el.style.setProperty('--fa', String(f.angle));
|
|
269
|
-
el.style.setProperty('--i', String(shown.length - 1 - j));
|
|
270
|
-
}
|
|
271
|
-
const fly = document.createElement('div');
|
|
272
|
-
fly.className = 'fly';
|
|
273
|
-
const turn = document.createElement('div');
|
|
274
|
-
turn.className = 'turn';
|
|
275
|
-
const front = document.createElement('div');
|
|
276
|
-
front.className = 'face front';
|
|
277
|
-
const img = document.createElement('img');
|
|
278
|
-
img.src = c.image;
|
|
279
|
-
img.alt = top ? c.name : '';
|
|
280
|
-
img.loading = 'lazy';
|
|
281
|
-
img.onerror = () => { img.replaceWith(document.createTextNode(`Image unavailable: ${c.name}`)); };
|
|
282
|
-
front.append(img);
|
|
283
|
-
turn.append(front);
|
|
284
|
-
// An object has no back to show: only a card gets the picture of its back (or the package's own).
|
|
285
|
-
if (!flat) {
|
|
286
|
-
const back = document.createElement('div');
|
|
287
|
-
back.className = 'face back';
|
|
288
|
-
if (c.backImage) {
|
|
289
|
-
const b = document.createElement('img');
|
|
290
|
-
b.src = c.backImage;
|
|
291
|
-
b.alt = '';
|
|
292
|
-
b.loading = 'lazy';
|
|
293
|
-
back.append(b);
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
back.classList.add('generic-back');
|
|
297
|
-
back.textContent = 'FUDA';
|
|
298
|
-
}
|
|
299
|
-
turn.append(back);
|
|
300
|
-
}
|
|
301
|
-
fly.append(turn);
|
|
302
|
-
el.append(fly);
|
|
303
|
-
el.onclick = () => this.open(c);
|
|
304
|
-
if (top) {
|
|
305
|
-
el.setAttribute('role', 'button');
|
|
306
|
-
el.setAttribute('aria-label', `Inspect ${c.name}`);
|
|
307
|
-
el.tabIndex = 0;
|
|
308
|
-
el.onkeydown = e => { if (e.key === 'Enter' || e.key === ' ') {
|
|
309
|
-
e.preventDefault();
|
|
310
|
-
this.open(c);
|
|
311
|
-
} };
|
|
312
|
-
}
|
|
313
|
-
pile.append(el);
|
|
314
|
-
});
|
|
315
|
-
return pile;
|
|
316
|
-
}
|
|
317
|
-
/** 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. */
|
|
318
|
-
fanFor(count) { const narrow = (this.clientWidth || innerWidth) < 520; return fanLayout(count, Number(this.getAttribute('deck-seed') ?? 1) || 1, narrow ? 0.3 : 0.34); }
|
|
319
|
-
/** 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. */
|
|
320
|
-
fanVars(v, open) {
|
|
321
|
-
const b = open && this.fanPlaces.length > 1 ? fanBounds(this.fanPlaces) : { left: 0, right: 0, top: 0, bottom: 0 };
|
|
322
|
-
v.classList.toggle('fan-open', open && this.fanPlaces.length > 1);
|
|
323
|
-
for (const [k, x] of [['--fl', b.left], ['--fr', b.right], ['--ft', b.top], ['--fb', b.bottom]])
|
|
324
|
-
v.style.setProperty(k, String(x));
|
|
260
|
+
/** @internal */
|
|
261
|
+
syncChoices() {
|
|
262
|
+
this.animateChoice?.set(this.getAttribute("animate") === "off" ? "off" : "on");
|
|
263
|
+
this.speedChoice?.set(["slow", "quick"].includes(this.getAttribute("speed") ?? "") ? this.getAttribute("speed") : "normal");
|
|
325
264
|
}
|
|
326
265
|
/** `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. */
|
|
327
266
|
setFan() {
|
|
328
|
-
if (!this.zoom || !(this.piled || this.currentView ===
|
|
267
|
+
if (!this.zoom || !(this.piled || this.currentView === "fan"))
|
|
329
268
|
return false;
|
|
330
|
-
const v = this.q(
|
|
331
|
-
if (!v.classList.contains(
|
|
269
|
+
const v = this.q(".v");
|
|
270
|
+
if (!v.classList.contains("deck") || !this.data.length)
|
|
332
271
|
return false;
|
|
333
272
|
const t = this.timeVars();
|
|
334
|
-
this.zoom.animated(() => {
|
|
273
|
+
this.zoom.animated(() => {
|
|
274
|
+
applyFan(this, v, this.fanOpen);
|
|
275
|
+
this.zoom.refresh();
|
|
276
|
+
}, t.on ? t.ms : 0);
|
|
335
277
|
this.syncChoices();
|
|
336
|
-
this.fanChoice.set(this.fanOpen ?
|
|
337
|
-
|
|
278
|
+
this.fanChoice.set(this.fanOpen ? "open" : "closed");
|
|
279
|
+
writeAddress(this);
|
|
338
280
|
return true;
|
|
339
281
|
}
|
|
340
|
-
|
|
341
|
-
const n = this.data.length, deckPositions = [], discardPositions = [];
|
|
342
|
-
v.classList.add('deck');
|
|
343
|
-
if (fanOnly) {
|
|
344
|
-
const size = Math.min(10, Math.max(2, Math.floor(Number(this.getAttribute('fan-size')) || 10))), count = Math.min(size, n);
|
|
345
|
-
// The fan window: `count` cards from the first one, wrapping round; the top card is the first and lies on the left when open.
|
|
346
|
-
for (let p = count - 1; p >= 0; p--)
|
|
347
|
-
deckPositions.push((this.index + p) % n);
|
|
348
|
-
v.classList.add('fanonly');
|
|
349
|
-
this.fanPlaces = this.fanFor(count);
|
|
350
|
-
v.append(this.pile('deck', deckPositions, this.fanPlaces));
|
|
351
|
-
}
|
|
352
|
-
else {
|
|
353
|
-
// 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.
|
|
354
|
-
for (let p = 0; p < n - this.index; p++)
|
|
355
|
-
deckPositions.push(n - 1 - p);
|
|
356
|
-
for (let p = 0; p < this.index; p++)
|
|
357
|
-
discardPositions.push(p);
|
|
358
|
-
this.fanPlaces = this.fanFor(Math.min(10, deckPositions.length));
|
|
359
|
-
const slot = () => { const s = document.createElement('div'); s.className = 'slot'; return s; };
|
|
360
|
-
// 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.
|
|
361
|
-
v.append(deckPositions.length ? this.pile('deck', deckPositions, this.fanPlaces) : slot(), discardPositions.length ? this.pile('discard', discardPositions) : slot());
|
|
362
|
-
}
|
|
363
|
-
const extent = document.createElement('div');
|
|
364
|
-
extent.className = 'extent';
|
|
365
|
-
v.append(extent);
|
|
366
|
-
this.fanVars(v, this.fanOpen);
|
|
367
|
-
}
|
|
368
|
-
/** 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. */
|
|
369
|
-
playFlip(direction, v, ms) {
|
|
370
|
-
// Either pile may be an empty dashed slot (the last card put back leaves the pile empty): the card still flies the same distance, from where the pile was.
|
|
371
|
-
const deck = v.querySelector('.deck-pile'), discard = v.querySelector('.discard-pile');
|
|
372
|
-
const moved = direction === 'off' ? discard?.querySelector('.card.top') : deck?.querySelector('.card.top');
|
|
373
|
-
if (!moved)
|
|
374
|
-
return;
|
|
375
|
-
const style = getComputedStyle(v), w = parseFloat(style.getPropertyValue('--w')) || 200, gap = parseFloat(style.getPropertyValue('--gap')) || 56, fr = parseFloat(v.style.getPropertyValue('--fr')) || 0;
|
|
376
|
-
const dx = (1 + fr) * w + gap, dy = 0;
|
|
377
|
-
const fly = moved.querySelector('.fly'), turn = moved.querySelector('.turn');
|
|
378
|
-
const lead = this.fanOpen && this.fanPlaces.length > 1 ? this.fanPlaces[0] : null, shift = lead ? fanShift(lead) : { x: 0, y: 0 };
|
|
379
|
-
const away = { x: shift.x * w, y: shift.y * w }, spin = lead ? lead.angle : 0;
|
|
380
|
-
// Taking a card off an open fan starts it where the fan holds it; bringing it back ends there.
|
|
381
|
-
// The piles' cards lie 0.9 px apart in depth (ten at most), so the flying card starts just above the higher of them and ends at its own place.
|
|
382
|
-
const z = 9.6 - (Number.parseFloat(moved.style.getPropertyValue('--k')) || 0) * 0.9;
|
|
383
|
-
const from = direction === 'off' ? { x: -dx + away.x, y: -dy + away.y, z } : { x: dx - away.x, y: dy - away.y, z };
|
|
384
|
-
flight(fly, turn, from, moved.classList.contains('flat') ? 'face-up' : this.land, direction, ms, direction === 'off' ? spin : -spin);
|
|
385
|
-
}
|
|
386
|
-
renderFan(v) { this.renderDeck(v, true); }
|
|
387
|
-
/** Where every card is on screen now, by data index. */
|
|
388
|
-
snapshot(v) { const m = new Map(); v.querySelectorAll('[data-i]:not(.ghost)').forEach(el => m.set(el.dataset.i, el.getBoundingClientRect())); return m; }
|
|
389
|
-
/** 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. */
|
|
390
|
-
enter(els, ms, dir = 0, stagger = 18) { let k = 0; for (const el of els)
|
|
391
|
-
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' }); }
|
|
392
|
-
/** 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. */
|
|
393
|
-
play(how, before, left, view, v, ms) {
|
|
394
|
-
if (how.kind === 'view') {
|
|
395
|
-
this.enter(Array.from(v.querySelectorAll('.card,.slot')), ms * 0.7);
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
if (pages.includes(view)) {
|
|
399
|
-
this.enter(Array.from(v.querySelectorAll('.card')), ms * 0.7, how.dir);
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
if (scrolling.includes(view)) {
|
|
403
|
-
const el = v.querySelector(`[data-i="${this.index}"]`);
|
|
404
|
-
if (el)
|
|
405
|
-
this.zoom.reveal(el, ms);
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
if (!gliding.includes(view) || this.zoom.turned())
|
|
409
|
-
return;
|
|
410
|
-
const scale = v.offsetWidth ? v.getBoundingClientRect().width / v.offsetWidth : 1;
|
|
411
|
-
const kept = new Set();
|
|
412
|
-
for (const el of Array.from(v.querySelectorAll('.card[data-i]'))) {
|
|
413
|
-
const was = before.get(el.dataset.i), now = el.getBoundingClientRect();
|
|
414
|
-
if (!was || !now.width) {
|
|
415
|
-
this.enter([el], ms * 0.7, how.dir);
|
|
416
|
-
continue;
|
|
417
|
-
}
|
|
418
|
-
kept.add(el.dataset.i);
|
|
419
|
-
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;
|
|
420
|
-
el.animate([{ translate: `${dx}px ${dy}px`, scale: was.width / now.width, offset: 0 }], { duration: ms, easing: 'cubic-bezier(.2,.8,.2,1)' });
|
|
421
|
-
}
|
|
422
|
-
const host = v.querySelector('.deck-pile') ?? v;
|
|
423
|
-
for (const old of left) {
|
|
424
|
-
if (kept.has(old.dataset.i))
|
|
425
|
-
continue;
|
|
426
|
-
old.classList.add('ghost');
|
|
427
|
-
old.removeAttribute('role');
|
|
428
|
-
old.tabIndex = -1;
|
|
429
|
-
host.append(old);
|
|
430
|
-
const done = () => old.remove();
|
|
431
|
-
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);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
syncBinder(view) {
|
|
435
|
-
const show = view === 'binder', cur = (attr, dflt, ok) => { const v = this.getAttribute(attr); return v && ok.includes(v) ? v : dflt; };
|
|
436
|
-
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']) };
|
|
437
|
-
for (const [k, h] of Object.entries(this.binderChoices)) {
|
|
438
|
-
h.hidden = !show;
|
|
439
|
-
h.set(vals[k]);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
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}`; }
|
|
443
|
-
/** 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. */
|
|
444
|
-
renderBinder(v, t) {
|
|
445
|
-
const layout = this.binderLay(), n = this.data.length, sides = sideCount(n, layout.per), spread = spreadOf(this.index, layout.per);
|
|
446
|
-
const sheet = this.getAttribute('sheet') === 'black' ? 'black' : 'clear', zip = this.getAttribute('binder') === 'zip', cover = binderCovers.find(c => c.id === this.getAttribute('cover')) ?? binderCovers[0];
|
|
447
|
-
v.classList.add('binder');
|
|
448
|
-
v.style.setProperty('--cover', cover.color);
|
|
449
|
-
const pocket = (index, live) => { const c = this.data[index], el = document.createElement('div'); el.className = 'pocket'; if (live)
|
|
450
|
-
el.append(this.image(c, index));
|
|
451
|
-
else {
|
|
452
|
-
const img = document.createElement('img');
|
|
453
|
-
img.src = c.image;
|
|
454
|
-
img.alt = '';
|
|
455
|
-
img.style.cssText = 'width:86%;height:92%;object-fit:contain;border-radius:3%;box-shadow:0 2px 5px #0007';
|
|
456
|
-
el.append(img);
|
|
457
|
-
} return el; };
|
|
458
|
-
const [L, R] = spreadSides(spread, sides), turn = this.turn;
|
|
459
|
-
this.turn = null;
|
|
460
|
-
const flat = turn && t.on && Math.abs(turn.to - turn.from) === 1 ? turn : null;
|
|
461
|
-
const [oldL, oldR] = flat ? spreadSides(flat.from, sides) : [L, R], [newL, newR] = flat ? spreadSides(flat.to, sides) : [L, R];
|
|
462
|
-
const forward = !!flat && flat.to > flat.from;
|
|
463
|
-
const book = document.createElement('div');
|
|
464
|
-
book.className = `book ${zip ? 'b-zip' : 'b-ring'}`;
|
|
465
|
-
const inside = document.createElement('div');
|
|
466
|
-
inside.className = 'inside';
|
|
467
|
-
const left = document.createElement('div'), right = document.createElement('div');
|
|
468
|
-
left.className = 'half';
|
|
469
|
-
right.className = 'half';
|
|
470
|
-
const put = (half, side, where) => { half.replaceChildren(); if (side >= 0)
|
|
471
|
-
half.append(buildSide(side, where, sheet, layout, n, pocket)); };
|
|
472
|
-
// 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.
|
|
473
|
-
put(left, flat ? (forward ? oldL : newL) : L, 'l');
|
|
474
|
-
put(right, flat ? (forward ? newR : oldR) : R, 'r');
|
|
475
|
-
const spine = document.createElement('div');
|
|
476
|
-
spine.className = 'spine';
|
|
477
|
-
for (const y of [18, 50, 82]) {
|
|
478
|
-
const ring = document.createElement('i');
|
|
479
|
-
ring.className = 'ring';
|
|
480
|
-
ring.style.top = `${y}%`;
|
|
481
|
-
spine.append(ring);
|
|
482
|
-
}
|
|
483
|
-
inside.append(left, right, spine);
|
|
484
|
-
const tab = document.createElement('i');
|
|
485
|
-
tab.className = 'tab';
|
|
486
|
-
book.append(inside, tab);
|
|
487
|
-
v.append(book);
|
|
488
|
-
if (flat) {
|
|
489
|
-
const w = 300, strip = 34, { leaf, slices } = buildLeaf(forward ? oldR : newR, forward ? newL : oldL, sheet, layout, n, pocket, w, strip);
|
|
490
|
-
inside.append(leaf);
|
|
491
|
-
const ms = Math.round(t.ms * 1.4), ease = 'cubic-bezier(.45,.05,.3,1)', a = forward ? [0, -180] : [-180, 0];
|
|
492
|
-
leaf.style.transform = `rotateY(${a[1]}deg)`;
|
|
493
|
-
const swing = leaf.animate([{ transform: `rotateY(${a[0]}deg)` }, { transform: `rotateY(${a[1]}deg)` }], { duration: ms, easing: ease, fill: 'forwards' });
|
|
494
|
-
// Each slice leans on the one before it, so the sheet bends as it swings (the free edge trails) and straightens at the end.
|
|
495
|
-
const bend = forward ? 8 : -8;
|
|
496
|
-
slices.forEach((s, k) => { if (k)
|
|
497
|
-
s.animate([{ transform: 'rotateY(0deg)' }, { transform: `rotateY(${bend}deg)`, offset: .5 }, { transform: 'rotateY(0deg)' }], { duration: ms, easing: ease }); });
|
|
498
|
-
const finish = () => { if (!leaf.isConnected)
|
|
499
|
-
return; put(left, newL, 'l'); put(right, newR, 'r'); leaf.remove(); };
|
|
500
|
-
swing.finished.then(finish, finish);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
282
|
+
/** @internal */
|
|
503
283
|
render(reset = false, how) {
|
|
504
284
|
if (!this.isConnected)
|
|
505
285
|
return;
|
|
506
|
-
this
|
|
507
|
-
|
|
508
|
-
const
|
|
509
|
-
const
|
|
510
|
-
this.
|
|
286
|
+
buildControls(this);
|
|
287
|
+
const view = this.currentView;
|
|
288
|
+
const stage = this.q(".stage");
|
|
289
|
+
const v = this.q(".v");
|
|
290
|
+
const t = this.timeVars();
|
|
291
|
+
const playing = t.on && how && this.data.length > 0;
|
|
292
|
+
const before = playing ? snapshotRects(v) : new Map();
|
|
293
|
+
const left = playing && how.kind === "move" && gliding.includes(view)
|
|
294
|
+
? Array.from(v.querySelectorAll(".card:not(.ghost)"))
|
|
295
|
+
: [];
|
|
296
|
+
syncBinderChoices(this, view);
|
|
511
297
|
this.tiles.set(view);
|
|
512
298
|
this.landing.set(this.land);
|
|
513
|
-
this.fanChoice.set(this.fanOpen ?
|
|
299
|
+
this.fanChoice.set(this.fanOpen ? "open" : "closed");
|
|
514
300
|
this.syncChoices();
|
|
515
301
|
this.landing.hidden = !this.piled || !this.hasCards;
|
|
516
|
-
this.fanChoice.hidden = !(this.piled || view ===
|
|
517
|
-
this.q(
|
|
518
|
-
|
|
302
|
+
this.fanChoice.hidden = !(this.piled || view === "fan");
|
|
303
|
+
this.q(".count").textContent = this.data.length
|
|
304
|
+
? view === "binder"
|
|
305
|
+
? binderPageCount(this)
|
|
306
|
+
: pages.includes(view)
|
|
307
|
+
? `Page ${Math.floor(this.index / this.pageSize) + 1} / ${Math.ceil(this.data.length / this.pageSize)}`
|
|
308
|
+
: `${this.index + 1} / ${this.data.length}`
|
|
309
|
+
: "No cards";
|
|
310
|
+
for (const selector of [".prev", ".next"])
|
|
519
311
|
this.q(selector).disabled = !this.data.length;
|
|
520
|
-
const random = view ===
|
|
521
|
-
this.q(
|
|
522
|
-
this.q(
|
|
523
|
-
this.q(
|
|
524
|
-
this.q(
|
|
312
|
+
const random = view === "random";
|
|
313
|
+
this.q(".draw-filter").hidden = !random;
|
|
314
|
+
this.q(".draw").hidden = !random;
|
|
315
|
+
this.q(".draw-filter input").value = this.drawFilter;
|
|
316
|
+
this.q(".draw").disabled = !this.canDraw();
|
|
525
317
|
stage.className = `stage ${view}`;
|
|
526
|
-
v.className =
|
|
318
|
+
v.className = "v";
|
|
527
319
|
v.replaceChildren();
|
|
528
|
-
v.style.removeProperty(
|
|
529
|
-
for (const k of [
|
|
320
|
+
v.style.removeProperty("--columns");
|
|
321
|
+
for (const k of ["--fl", "--fr", "--ft", "--fb"])
|
|
530
322
|
v.style.removeProperty(k);
|
|
531
|
-
this.zoom.minOpen = scrolling.includes(view) ? .5 : 0;
|
|
323
|
+
this.zoom.minOpen = scrolling.includes(view) ? 0.5 : 0;
|
|
532
324
|
this.zoom.setTurnable(this.turnable && this.data.length > 0, this.data.length > 0 && !this.hasCards);
|
|
533
|
-
this.zoom.items = this.piled || view ===
|
|
325
|
+
this.zoom.items = this.piled || view === "fan" ? ".extent" : view === "binder" ? ".book" : ".card,.slot";
|
|
534
326
|
if (!this.data.length) {
|
|
535
327
|
v.innerHTML = '<p class="empty">No cards in this collection.</p>';
|
|
536
328
|
}
|
|
537
329
|
else if (this.piled)
|
|
538
|
-
|
|
539
|
-
else if (view ===
|
|
540
|
-
this
|
|
541
|
-
else if (view ===
|
|
542
|
-
|
|
330
|
+
renderDeck(this, v);
|
|
331
|
+
else if (view === "fan")
|
|
332
|
+
renderDeck(this, v, true);
|
|
333
|
+
else if (view === "binder")
|
|
334
|
+
renderBinder(this, v, t);
|
|
543
335
|
else if (pages.includes(view)) {
|
|
544
|
-
v.classList.add(
|
|
545
|
-
const columns = Math.min(10, Math.max(1, Math.floor(Number(this.getAttribute(
|
|
546
|
-
v.style.setProperty(
|
|
547
|
-
|
|
548
|
-
this.data.slice(start, start + this.pageSize).forEach((c, k) =>
|
|
336
|
+
v.classList.add("grid", view);
|
|
337
|
+
const columns = Math.min(10, Math.max(1, Math.floor(Number(this.getAttribute("columns")) || 3)));
|
|
338
|
+
v.style.setProperty("--columns", String(columns));
|
|
339
|
+
const start = Math.floor(this.index / this.pageSize) * this.pageSize;
|
|
340
|
+
this.data.slice(start, start + this.pageSize).forEach((c, k) => {
|
|
341
|
+
v.append(this.image(c, start + k));
|
|
342
|
+
});
|
|
549
343
|
}
|
|
550
|
-
else if (view ===
|
|
344
|
+
else if (view === "wall" || view === "story") {
|
|
551
345
|
v.classList.add(view);
|
|
552
|
-
this.data.forEach((c, k) =>
|
|
346
|
+
this.data.forEach((c, k) => {
|
|
347
|
+
v.append(this.image(c, k));
|
|
348
|
+
});
|
|
553
349
|
}
|
|
554
|
-
else if (view ===
|
|
555
|
-
v.classList.add(
|
|
556
|
-
|
|
557
|
-
plane.className =
|
|
558
|
-
this.data.forEach((c, k) =>
|
|
350
|
+
else if (view === "atlas") {
|
|
351
|
+
v.classList.add("atlas");
|
|
352
|
+
const plane = document.createElement("div");
|
|
353
|
+
plane.className = "plane";
|
|
354
|
+
this.data.forEach((c, k) => {
|
|
355
|
+
plane.append(this.image(c, k));
|
|
356
|
+
});
|
|
559
357
|
v.append(plane);
|
|
560
358
|
}
|
|
561
359
|
else {
|
|
562
|
-
v.classList.add(
|
|
563
|
-
|
|
360
|
+
v.classList.add("stack", view);
|
|
361
|
+
const count = Math.min(3, this.data.length);
|
|
564
362
|
for (let d = count - 1; d >= 0; d--) {
|
|
565
363
|
const at = (this.index + d) % this.data.length;
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
el.style.
|
|
364
|
+
const c = this.data[at];
|
|
365
|
+
const el = this.image(c, at);
|
|
366
|
+
const offset = view === "rolodex" ? d * 42 : view === "spotlight" ? d * 70 : d * 14;
|
|
367
|
+
const rotation = view === "rolodex" ? d * 12 : d * 5;
|
|
368
|
+
el.style.transform = `translateX(calc(-50% + ${offset}px)) rotate(${rotation}deg) scale(${1 - d * 0.08})`;
|
|
369
|
+
el.style.opacity = String(1 - d * 0.2);
|
|
571
370
|
v.append(el);
|
|
572
371
|
}
|
|
573
372
|
}
|
|
574
373
|
this.attachLive(v);
|
|
575
374
|
this.zoom.refresh(reset);
|
|
576
375
|
if (this.flip && this.piled && t.on && this.data.length > 1)
|
|
577
|
-
|
|
376
|
+
playFlip(this, this.flip, v, Math.round(t.ms * 1.15));
|
|
578
377
|
this.flip = null;
|
|
579
378
|
if (playing)
|
|
580
|
-
this
|
|
379
|
+
playMove(this, how, before, left, view, v, t.ms);
|
|
581
380
|
}
|
|
582
381
|
}
|
|
583
|
-
if (!customElements.get(
|
|
584
|
-
customElements.define(
|
|
382
|
+
if (!customElements.get("fuda-collection"))
|
|
383
|
+
customElements.define("fuda-collection", FudaCollection);
|