@johnmorrisdotca/fuda-cards 0.10.1 → 0.11.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.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +14 -0
  3. package/README.md +89 -7
  4. package/dist/binder.d.ts +4 -6
  5. package/dist/binder.js +32 -23
  6. package/dist/card-markup.d.ts +2 -0
  7. package/dist/card-markup.js +59 -0
  8. package/dist/card-options.d.ts +131 -0
  9. package/dist/card-options.js +48 -0
  10. package/dist/card-styles.d.ts +2 -0
  11. package/dist/card-styles.js +314 -0
  12. package/dist/choice.d.ts +1 -1
  13. package/dist/choice.js +27 -23
  14. package/dist/collection-address.d.ts +8 -0
  15. package/dist/collection-address.js +52 -0
  16. package/dist/collection-binder-view.d.ts +9 -0
  17. package/dist/collection-binder-view.js +123 -0
  18. package/dist/collection-controls.d.ts +2 -0
  19. package/dist/collection-controls.js +143 -0
  20. package/dist/collection-deck.d.ts +11 -0
  21. package/dist/collection-deck.js +165 -0
  22. package/dist/collection-dialog.d.ts +2 -0
  23. package/dist/collection-dialog.js +28 -0
  24. package/dist/collection-element.d.ts +30 -65
  25. package/dist/collection-element.js +283 -484
  26. package/dist/collection-host.d.ts +5 -0
  27. package/dist/collection-host.js +1 -0
  28. package/dist/collection-icons.d.ts +3 -0
  29. package/dist/collection-icons.js +19 -0
  30. package/dist/collection-motion.d.ts +11 -0
  31. package/dist/collection-motion.js +72 -0
  32. package/dist/collection-styles.d.ts +4 -0
  33. package/dist/collection-styles.js +336 -0
  34. package/dist/collection-views.d.ts +8 -0
  35. package/dist/collection-views.js +8 -0
  36. package/dist/collection.d.ts +140 -11
  37. package/dist/collection.js +139 -33
  38. package/dist/element-define.d.ts +2 -0
  39. package/dist/element-define.js +3 -0
  40. package/dist/element.d.ts +20 -1
  41. package/dist/element.js +289 -98
  42. package/dist/index.d.ts +9 -52
  43. package/dist/index.js +5 -5
  44. package/dist/live-3d.d.ts +87 -4
  45. package/dist/live-3d.js +120 -52
  46. package/dist/materials.d.ts +117 -6
  47. package/dist/materials.js +191 -28
  48. package/dist/motion.d.ts +2 -0
  49. package/dist/motion.js +4 -0
  50. package/dist/pile-card.js +138 -91
  51. package/dist/pile.d.ts +61 -8
  52. package/dist/pile.js +89 -29
  53. package/dist/stack.d.ts +42 -6
  54. package/dist/stack.js +28 -3
  55. package/dist/version.d.ts +11 -0
  56. package/dist/version.js +11 -0
  57. package/dist/wear.d.ts +147 -9
  58. package/dist/wear.js +273 -89
  59. package/dist/zoom.d.ts +1 -1
  60. package/dist/zoom.js +73 -42
  61. package/docs/API.md +121 -131
  62. package/docs/guides/bundlers.md +60 -0
  63. package/docs/guides/card-element.md +2 -2
  64. package/docs/guides/embed-in-an-iframe.md +39 -0
  65. package/docs/guides/frameworks.md +93 -66
  66. package/docs/guides/getting-started.md +3 -1
  67. package/docs/guides/html-and-cdn.md +69 -0
  68. package/docs/guides/ja/bundlers.md +60 -0
  69. package/docs/guides/ja/card-element.md +2 -2
  70. package/docs/guides/ja/embed-in-an-iframe.md +39 -0
  71. package/docs/guides/ja/frameworks.md +93 -66
  72. package/docs/guides/ja/getting-started.md +3 -1
  73. package/docs/guides/ja/html-and-cdn.md +69 -0
  74. package/docs/guides/ja/materials-and-stacks.md +3 -3
  75. package/docs/guides/ja/troubleshooting.md +2 -2
  76. package/docs/guides/ja/typescript-and-node.md +45 -0
  77. package/docs/guides/ja/upgrading.md +1 -1
  78. package/docs/guides/materials-and-stacks.md +3 -3
  79. package/docs/guides/troubleshooting.md +2 -2
  80. package/docs/guides/typescript-and-node.md +45 -0
  81. package/docs/guides/upgrading.md +1 -1
  82. package/package.json +57 -10
@@ -0,0 +1,5 @@
1
+ /** How a move or a change of display plays: which kind, and which way the reader is heading (1 forward, -1 back). */
2
+ export interface MoveStyle {
3
+ kind: "move" | "view";
4
+ dir: number;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { CollectionView } from "./collection.js";
2
+ export declare const ICONS: Record<CollectionView, string>;
3
+ export declare const icon: (view: CollectionView) => string;
@@ -0,0 +1,19 @@
1
+ /** A small picture for each display, for its tile: a grid of rectangles or a few shapes, drawn in `currentColor` on a 34 by 22 view box. */
2
+ 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("");
3
+ export const ICONS = {
4
+ 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"/>',
5
+ 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"/>',
6
+ binder: rects(3, 2, 9, 9, 11, 10, 2, 1),
7
+ case: '<path d="M3 4h28l-3 6H6z" opacity=".5"/><path d="M6 12h22l-3 8H9z"/>',
8
+ 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"/>',
9
+ 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"/>',
10
+ 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"/>',
11
+ 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"/>',
12
+ 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"/>',
13
+ 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"/>',
14
+ atlas: rects(4, 3, 6, 5.5, 8, 7, 2, 1),
15
+ fan: [-30, -15, 0, 15, 30]
16
+ .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}"/>`)
17
+ .join(""),
18
+ };
19
+ export const icon = (view) => `<svg viewBox="0 0 34 22" aria-hidden="true">${ICONS[view]}</svg>`;
@@ -0,0 +1,11 @@
1
+ import type { CollectionView } from "./collection.js";
2
+ import type { CollectionHost } from "./collection-host.js";
3
+ /** Where every card is on screen now, by data index. */
4
+ export declare function snapshotRects(v: HTMLElement): Map<string, DOMRect>;
5
+ /** 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. */
6
+ export declare function enterCards(els: Iterable<Element>, ms: number, dir?: number, stagger?: number): void;
7
+ /** 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. */
8
+ export declare function playMove(host: CollectionHost, how: {
9
+ kind: "move" | "view";
10
+ dir: number;
11
+ }, before: Map<string, DOMRect>, left: HTMLElement[], view: CollectionView, v: HTMLElement, ms: number): void;
@@ -0,0 +1,72 @@
1
+ // How a move or a change of display plays: the cards that stay glide, the ones that leave fade out, the ones that arrive grow in.
2
+ import { gliding, pages, scrolling } from "./collection-views.js";
3
+ /** Where every card is on screen now, by data index. */
4
+ export function snapshotRects(v) {
5
+ const m = new Map();
6
+ for (const el of v.querySelectorAll("[data-i]:not(.ghost)"))
7
+ m.set(el.dataset.i, el.getBoundingClientRect());
8
+ return m;
9
+ }
10
+ /** 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. */
11
+ export function enterCards(els, ms, dir = 0, stagger = 18) {
12
+ let k = 0;
13
+ for (const el of els)
14
+ el.animate([{ opacity: 0, translate: `${dir * 36}px 0`, scale: 0.94, offset: 0 }], {
15
+ duration: ms,
16
+ delay: Math.min(k++, 12) * stagger,
17
+ easing: "cubic-bezier(.2,.8,.2,1)",
18
+ fill: "backwards",
19
+ });
20
+ }
21
+ /** 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. */
22
+ export function playMove(host, how, before, left, view, v, ms) {
23
+ if (how.kind === "view") {
24
+ enterCards(Array.from(v.querySelectorAll(".card,.slot")), ms * 0.7);
25
+ return;
26
+ }
27
+ if (pages.includes(view)) {
28
+ enterCards(Array.from(v.querySelectorAll(".card")), ms * 0.7, how.dir);
29
+ return;
30
+ }
31
+ if (scrolling.includes(view)) {
32
+ const el = v.querySelector(`[data-i="${host.index}"]`);
33
+ if (el)
34
+ host.zoom.reveal(el, ms);
35
+ return;
36
+ }
37
+ if (!gliding.includes(view) || host.zoom.turned())
38
+ return;
39
+ const scale = v.offsetWidth ? v.getBoundingClientRect().width / v.offsetWidth : 1;
40
+ const kept = new Set();
41
+ for (const el of Array.from(v.querySelectorAll(".card[data-i]"))) {
42
+ const was = before.get(el.dataset.i);
43
+ const now = el.getBoundingClientRect();
44
+ if (!was || !now.width) {
45
+ enterCards([el], ms * 0.7, how.dir);
46
+ continue;
47
+ }
48
+ kept.add(el.dataset.i);
49
+ const dx = (was.left + was.width / 2 - now.left - now.width / 2) / scale;
50
+ const dy = (was.top + was.height / 2 - now.top - now.height / 2) / scale;
51
+ el.animate([{ translate: `${dx}px ${dy}px`, scale: was.width / now.width, offset: 0 }], {
52
+ duration: ms,
53
+ easing: "cubic-bezier(.2,.8,.2,1)",
54
+ });
55
+ }
56
+ const leaving = v.querySelector(".deck-pile") ?? v;
57
+ for (const old of left) {
58
+ if (kept.has(old.dataset.i))
59
+ continue;
60
+ old.classList.add("ghost");
61
+ old.removeAttribute("role");
62
+ old.tabIndex = -1;
63
+ leaving.append(old);
64
+ const done = () => old.remove();
65
+ old
66
+ .animate([
67
+ { opacity: 1, translate: "0 0", offset: 0 },
68
+ { opacity: 0, translate: `${-how.dir * 60}px 0`, offset: 1 },
69
+ ], { duration: ms * 0.8, easing: "ease-in" })
70
+ .finished.then(done, done);
71
+ }
72
+ }
@@ -0,0 +1,4 @@
1
+ /** The stylesheet of \`<fuda-collection>\`'s shadow root. */
2
+ export declare const COLLECTION_CSS: string;
3
+ /** The markup of the shell that the element draws once; the display and the options are filled in by the element. */
4
+ export declare const COLLECTION_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\">\u2190 Previous</button><span class=\"count\" aria-live=\"polite\"></span><button class=\"next\">Next \u2192</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>";
@@ -0,0 +1,336 @@
1
+ import { BINDER_CSS } from "./binder.js";
2
+ import { CHOICE_CSS, CHOICE_VARS } from "./choice.js";
3
+ // The collection's stylesheet, one rule to a line (or one declaration to a line), in the order it cascades: the shell and its
4
+ // buttons, the row of display choices, the stage and the flat displays, the deck's piles and fan, then the dialog and the small screens.
5
+ /** The shell, the navigation row, the option rows and the buttons, in both colour themes. */
6
+ const SHELL_CSS = `
7
+ :host {
8
+ display: block;
9
+ ${CHOICE_VARS.dark};
10
+ color: var(--fc-text);
11
+ font: 16px system-ui;
12
+ }
13
+ @media (prefers-color-scheme:light) {
14
+ :host(:not([theme="dark"])) { ${CHOICE_VARS.light}; }
15
+ }
16
+ :host([theme="light"]) { ${CHOICE_VARS.light}; }
17
+ :host([theme="dark"]) { ${CHOICE_VARS.dark}; }
18
+ * { box-sizing: border-box; }
19
+ .shell {
20
+ background: var(--fc-surface);
21
+ padding: 1rem;
22
+ border-radius: 1rem;
23
+ display: grid;
24
+ gap: .9rem;
25
+ }
26
+ .nav {
27
+ display: flex;
28
+ gap: .6rem;
29
+ align-items: center;
30
+ justify-content: center;
31
+ flex-wrap: wrap;
32
+ }
33
+ .opts {
34
+ display: grid;
35
+ grid-template-columns: repeat(auto-fit,minmax(min(100%,13.5rem),1fr));
36
+ gap: .9rem;
37
+ }
38
+ .opts:not(:has(.choice:not([hidden]))) { display: none; }
39
+ .opts .choice { --choice-min: 4.6rem; }
40
+ button, input {
41
+ font: inherit;
42
+ color: inherit;
43
+ }
44
+ .nav button, dialog button {
45
+ min-height: 48px;
46
+ min-width: 48px;
47
+ background: var(--fc-btn);
48
+ border: 2px solid var(--fc-btn-border);
49
+ border-radius: .7rem;
50
+ padding: .5rem 1rem;
51
+ cursor: pointer;
52
+ }
53
+ .nav button:disabled {
54
+ opacity: .45;
55
+ cursor: default;
56
+ }
57
+ .nav input {
58
+ min-height: 48px;
59
+ background: var(--fc-btn);
60
+ border: 2px solid var(--fc-btn-border);
61
+ border-radius: .7rem;
62
+ padding: .5rem .8rem;
63
+ }
64
+ button:focus-visible, input:focus-visible, .card:focus-visible {
65
+ outline: 3px solid var(--fc-focus);
66
+ outline-offset: 3px;
67
+ }
68
+ `;
69
+ /** The row of display tiles: three across on a phone, four from 340 px, six from 800 px. */
70
+ const PICKER_CSS = `
71
+ .displays .choice-list { grid-template-columns: repeat(3,minmax(0,1fr)); }
72
+ @media (min-width:340px) {
73
+ .displays .choice-list { grid-template-columns: repeat(4,minmax(0,1fr)); }
74
+ .displays .choice-list button {
75
+ min-height: 50px;
76
+ padding: .3rem .25rem;
77
+ font-size: .7rem;
78
+ }
79
+ .displays .choice-list svg {
80
+ width: 28px;
81
+ height: 18px;
82
+ }
83
+ }
84
+ @media (min-width:800px) {
85
+ .displays .choice-list { grid-template-columns: repeat(6,minmax(0,1fr)); }
86
+ .displays .choice-list button {
87
+ min-height: 56px;
88
+ padding: .45rem .7rem;
89
+ font-size: .8rem;
90
+ }
91
+ .displays .choice-list svg {
92
+ width: 34px;
93
+ height: 22px;
94
+ }
95
+ }
96
+ `;
97
+ /** The stage and the flat displays: the grid, the case, the wall, the story, the atlas and the spotlight. */
98
+ const DISPLAYS_CSS = `
99
+ .stage {
100
+ position: relative;
101
+ height: var(--fuda-stage-height,clamp(300px,calc(100svh - 440px),620px));
102
+ overflow: hidden;
103
+ border-radius: 1rem;
104
+ background: radial-gradient(ellipse,var(--fc-stage-1),var(--fc-stage-2) 68%);
105
+ }
106
+ .stage:focus-visible {
107
+ outline: 3px solid var(--fc-focus);
108
+ outline-offset: 2px;
109
+ }
110
+ .v {
111
+ position: absolute;
112
+ inset: 0;
113
+ }
114
+ kazoku-view-controls { display: block; }
115
+ .card {
116
+ padding: 0;
117
+ border: 0;
118
+ background: transparent;
119
+ line-height: 0;
120
+ }
121
+ .card img {
122
+ width: 100%;
123
+ height: 100%;
124
+ object-fit: contain;
125
+ border-radius: 5%;
126
+ box-shadow: 0 6px 16px #0009;
127
+ }
128
+ .stack .card {
129
+ position: absolute;
130
+ width: min(64vw,300px);
131
+ height: 86%;
132
+ top: 7%;
133
+ left: 50%;
134
+ transition: transform .25s;
135
+ }
136
+ .grid {
137
+ display: grid;
138
+ grid-template-columns: repeat(var(--columns,3),minmax(0,1fr));
139
+ gap: 1rem;
140
+ padding: 1rem;
141
+ align-content: start;
142
+ }
143
+ .grid .card { height: clamp(130px,24vw,220px); }
144
+ .v.case { perspective: 800px; }
145
+ .stage.case {
146
+ background: linear-gradient(#4a3f33,#1d1914);
147
+ border: 10px solid #6b5436;
148
+ box-shadow: inset 0 0 26px #000a;
149
+ }
150
+ .stage.case::after {
151
+ content: '';
152
+ position: absolute;
153
+ inset: 0;
154
+ pointer-events: none;
155
+ z-index: 2;
156
+ background: linear-gradient(115deg,#ffffff30 0,#ffffff00 28%,#ffffff12 55%,#ffffff00 78%,#ffffff22 100%);
157
+ }
158
+ .case .card {
159
+ transform: perspective(600px) rotateX(-15deg);
160
+ box-shadow: 0 12px 0 -3px #2c251d,0 18px 8px -4px #000a;
161
+ }
162
+ .case .card img { box-shadow: 0 4px 10px #0009; }
163
+ .wall {
164
+ display: flex;
165
+ gap: 1rem;
166
+ align-items: center;
167
+ padding: 1rem;
168
+ }
169
+ .wall .card {
170
+ height: 90%;
171
+ flex: 0 0 190px;
172
+ }
173
+ .story {
174
+ display: flex;
175
+ flex-direction: column;
176
+ align-items: center;
177
+ gap: 1rem;
178
+ padding: 1rem;
179
+ }
180
+ .story .card {
181
+ width: min(75%,300px);
182
+ flex: 0 0 90%;
183
+ min-height: 0;
184
+ }
185
+ .plane {
186
+ position: absolute;
187
+ left: 0;
188
+ top: 0;
189
+ display: grid;
190
+ gap: 18px;
191
+ grid-template-columns: repeat(var(--atlas-cols,5),140px);
192
+ padding: 30px;
193
+ }
194
+ .plane .card { height: 195px; }
195
+ .stage.spotlight { background: radial-gradient(ellipse at center,#e5ce99,#454054 40%,#171822 78%); }
196
+ `;
197
+ /** The deck: its piles, the fan, the faces of a card and the card back. */
198
+ const DECK_CSS = `
199
+ .stage:is(.deck, .random, .fan) { perspective: 1800px; }
200
+ .v.deck {
201
+ --w: 200px;
202
+ --gap: 56px;
203
+ --fl: 0;
204
+ --fr: 0;
205
+ --ft: 0;
206
+ --fb: 0;
207
+ --ease: cubic-bezier(.2,.8,.2,1);
208
+ transform-style: preserve-3d;
209
+ }
210
+ .v.deck .pile, .v.deck .slot {
211
+ position: absolute;
212
+ left: 50%;
213
+ top: 50%;
214
+ width: var(--w);
215
+ aspect-ratio: 2.5/3.5;
216
+ margin: calc(var(--w) * -.7) 0 0 calc(var(--w) * -.5);
217
+ transform-style: preserve-3d;
218
+ }
219
+ .slot {
220
+ border: 2px dashed var(--fc-btn-border);
221
+ border-radius: 5%;
222
+ opacity: .55;
223
+ }
224
+ .v.deck .deck-pile { translate: calc(((var(--fl) - var(--fr) - 1) * var(--w) - var(--gap)) / 2) 0; }
225
+ .v.deck .discard-pile, .v.deck .slot { translate: calc(((var(--fl) + var(--fr) + 1) * var(--w) + var(--gap)) / 2) 0; }
226
+ .v.deck.fanonly .deck-pile { translate: calc((var(--fl) - var(--fr)) * var(--w) / 2) 0; }
227
+ .v.deck .deck-pile, .v.deck .discard-pile, .v.deck .slot { transition: translate var(--t,0s) var(--ease); }
228
+ .extent {
229
+ position: absolute;
230
+ left: 50%;
231
+ top: 50%;
232
+ width: calc((var(--fl) + var(--fr) + 2) * var(--w) + var(--gap));
233
+ height: calc((1.4 + var(--ft) + var(--fb)) * var(--w));
234
+ translate: -50% calc(-50% + (var(--fb) - var(--ft)) * var(--w) / 2);
235
+ visibility: hidden;
236
+ pointer-events: none;
237
+ }
238
+ .fanonly .extent { width: calc((var(--fl) + var(--fr) + 1) * var(--w)); }
239
+ .pile .card {
240
+ position: absolute;
241
+ inset: 0;
242
+ display: block;
243
+ transform-style: preserve-3d;
244
+ transform-origin: 50% 50%;
245
+ 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));
246
+ transition: transform var(--t,0s) var(--ease),transform-origin var(--t,0s) var(--ease);
247
+ transition-delay: calc(var(--j,0) * var(--stag,22ms));
248
+ }
249
+ .pile .card:not(.top) { pointer-events: none; }
250
+ .pile .card.top { cursor: pointer; }
251
+ .fan-open .deck-pile .card {
252
+ transform-origin: 50% 165%;
253
+ transform: translate3d(calc(var(--fx,0) * var(--w)),0,calc(var(--k,0) * .9px)) rotate(calc(var(--fa,0) * 1deg));
254
+ transition-delay: calc(var(--i,0) * var(--stag,28ms));
255
+ pointer-events: auto;
256
+ cursor: pointer;
257
+ }
258
+ .fan-open .deck-pile .card:hover, .fan-open .deck-pile .card:focus-visible { translate: 0 -14px; }
259
+ .fly, .turn {
260
+ position: absolute;
261
+ inset: 0;
262
+ transform-style: preserve-3d;
263
+ }
264
+ .face {
265
+ position: absolute;
266
+ inset: 0;
267
+ backface-visibility: hidden;
268
+ -webkit-backface-visibility: hidden;
269
+ border-radius: 5%;
270
+ overflow: hidden;
271
+ }
272
+ .face img {
273
+ display: block;
274
+ width: 100%;
275
+ height: 100%;
276
+ object-fit: contain;
277
+ border-radius: 3%;
278
+ box-shadow: 0 4px 10px #0008;
279
+ }
280
+ .face.back { transform: rotateY(180deg); }
281
+ .generic-back {
282
+ display: grid;
283
+ place-items: center;
284
+ background: radial-gradient(ellipse at center,#b78745 0 12%,#152d46 13% 27%,#386988 28% 31%,#10233b 32% 62%,#d2b074 63% 66%,#182c45 67%);
285
+ border: 6px solid #b39158;
286
+ color: #f7e9bf;
287
+ font: bold 18px Georgia;
288
+ letter-spacing: .12em;
289
+ box-shadow: 0 4px 10px #0008;
290
+ }
291
+ .pile.discard[data-land=face-down] .card:not(.flat) .turn { transform: rotateY(180deg); }
292
+ .card.flat .turn { transform: rotateY(calc(var(--fuda-yaw,0) * -1deg)) rotateX(calc(var(--fuda-tilt,0) * -1deg)); }
293
+ .ghost { pointer-events: none; }
294
+ `;
295
+ /** The card detail dialog, the empty state and the small-screen and reduced-motion rules. */
296
+ const DIALOG_CSS = `
297
+ dialog {
298
+ color: var(--fc-text);
299
+ background: var(--fc-dialog);
300
+ border: 1px solid var(--fc-btn-border);
301
+ border-radius: 1rem;
302
+ text-align: center;
303
+ max-width: 95vw;
304
+ max-height: 95vh;
305
+ }
306
+ dialog::backdrop { background: #000c; }
307
+ .detail {
308
+ display: block;
309
+ height: min(70vh,600px);
310
+ max-width: 80vw;
311
+ object-fit: contain;
312
+ margin: 1rem auto;
313
+ }
314
+ .empty {
315
+ text-align: center;
316
+ padding: 3rem;
317
+ }
318
+ @media (max-width:600px) {
319
+ .stage { height: var(--fuda-stage-height,clamp(220px,calc(100svh - 570px),620px)); }
320
+ }
321
+ @media (max-width:500px) {
322
+ .opts { grid-template-columns: repeat(2,minmax(0,1fr)); }
323
+ .opts .speed { grid-column: 1/-1; }
324
+ .v.deck { --gap: 28px; }
325
+ .grid { grid-template-columns: repeat(min(2,var(--columns,3)),minmax(0,1fr)); }
326
+ .shell { padding: .7rem; }
327
+ .v.deck { --w: 150px; }
328
+ }
329
+ @media (prefers-reduced-motion:reduce) {
330
+ * { transition: none!important; }
331
+ }
332
+ `;
333
+ /** The stylesheet of \`<fuda-collection>\`'s shadow root. */
334
+ export const COLLECTION_CSS = [SHELL_CSS, CHOICE_CSS, BINDER_CSS, PICKER_CSS, DISPLAYS_CSS, DECK_CSS, DIALOG_CSS].join("\n");
335
+ /** The markup of the shell that the element draws once; the display and the options are filled in by the element. */
336
+ export const COLLECTION_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>`;
@@ -0,0 +1,8 @@
1
+ import type { CollectionView } from "./collection.js";
2
+ /** The displays that turn pages: the binder and the case. */
3
+ export declare const pages: CollectionView[];
4
+ export declare const scrolling: CollectionView[];
5
+ /** 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. */
6
+ export declare const pileViews: CollectionView[];
7
+ /** 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. */
8
+ export declare const gliding: CollectionView[];
@@ -0,0 +1,8 @@
1
+ // Which displays work alike.
2
+ /** The displays that turn pages: the binder and the case. */
3
+ export const pages = ["binder", "case"];
4
+ export const scrolling = ["wall", "story", "atlas"];
5
+ /** 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. */
6
+ export const pileViews = ["deck", "random"];
7
+ /** 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. */
8
+ export const gliding = ["rolodex", "spotlight", "fan"];
@@ -1,7 +1,30 @@
1
- export { fanLayout, deckLandings, normalizeLanding } from './pile.js';
2
- export type { DeckLanding, FanPlace } from './pile.js';
3
- /** Browser-native collection viewer. Import this module to register <fuda-collection>. */
4
- export type CollectionView = 'deck' | 'rolodex' | 'binder' | 'case' | 'jukebox' | 'random' | 'story' | 'wall' | 'tower' | 'spotlight' | 'atlas' | 'fan';
1
+ export type { DeckLanding, FanPlace } from "./pile.js";
2
+ export { deckLandings, fanLayout, normalizeLanding } from "./pile.js";
3
+ /**
4
+ * The name of a display of `<fuda-collection>`: the `view` attribute's values. `jukebox` and `tower` are older names that open the deck (see
5
+ * {@link collectionViewAliases}).
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { collectionViews, type CollectionView } from "@johnmorrisdotca/fuda-cards/collection";
10
+ *
11
+ * const view: CollectionView = "binder";
12
+ * console.log(collectionViews.some((one) => one.id === view)); // true
13
+ * ```
14
+ */
15
+ export type CollectionView = "deck" | "rolodex" | "binder" | "case" | "jukebox" | "random" | "story" | "wall" | "tower" | "spotlight" | "atlas" | "fan";
16
+ /**
17
+ * What a collector writes about a card: its set, year, number, edition, condition, grade, quantity and notes. All optional; `year` and `quantity` are whole numbers.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { parseCollection, type CollectionMetadata } from "@johnmorrisdotca/fuda-cards/collection";
22
+ *
23
+ * const metadata: CollectionMetadata = { set: "Base", year: 1999, quantity: 2 };
24
+ * console.log(parseCollection([{ name: "Card", image: "c.jpg", metadata }])[0].metadata);
25
+ * // { set: 'Base', year: 1999, quantity: 2 }
26
+ * ```
27
+ */
5
28
  export interface CollectionMetadata {
6
29
  set?: string;
7
30
  year?: number;
@@ -17,9 +40,38 @@ export interface CollectionMetadata {
17
40
  * turns in 3D, can be seen from behind and lands turned over when taken off a pile. An `object` is a picture of a thing that is not a card, such as a
18
41
  * games console: it has no back and no thickness, so it never turns over, is never seen from behind or edge-on, and always lands facing up. (A real 3D
19
42
  * object would be a third kind; none can be given as an image yet.)
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import { collectionKinds, type CollectionKind } from "@johnmorrisdotca/fuda-cards/collection";
47
+ *
48
+ * const kind: CollectionKind = "object";
49
+ * console.log(collectionKinds.includes(kind)); // true
50
+ * ```
51
+ */
52
+ export type CollectionKind = "card" | "object";
53
+ /**
54
+ * The two kinds of item, `card` and `object`.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { collectionKinds } from "@johnmorrisdotca/fuda-cards/collection";
59
+ *
60
+ * console.log(collectionKinds); // [ 'card', 'object' ]
61
+ * ```
20
62
  */
21
- export type CollectionKind = 'card' | 'object';
22
63
  export declare const collectionKinds: ReadonlyArray<CollectionKind>;
64
+ /**
65
+ * One item of a collection: an id, a name, the front's picture, optionally the back's, its kind and its metadata.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import { type CollectionCard } from "@johnmorrisdotca/fuda-cards/collection";
70
+ *
71
+ * const card: CollectionCard = { id: "1", name: "Explorer One", image: "front.jpg", backImage: "back.jpg" };
72
+ * console.log(card.name); // Explorer One
73
+ * ```
74
+ */
23
75
  export interface CollectionCard {
24
76
  id: string;
25
77
  name: string;
@@ -28,17 +80,94 @@ export interface CollectionCard {
28
80
  kind?: CollectionKind;
29
81
  metadata?: CollectionMetadata;
30
82
  }
31
- /** True for an item that is a card: anything that does not say it is an object. Only a card turns, has a back and lands turned over. */
83
+ /**
84
+ * Whether an item is a card: anything that does not say it is an object. Only a card turns, has a back and lands turned over.
85
+ *
86
+ * @param card - The item, or anything with its `kind`.
87
+ * @returns `true` for a card, `false` for an object.
88
+ * @example
89
+ * ```ts
90
+ * import { isCard } from "@johnmorrisdotca/fuda-cards/collection";
91
+ *
92
+ * console.log(isCard({}), isCard({ kind: "object" })); // true false
93
+ * ```
94
+ */
32
95
  export declare const isCard: (card: Pick<CollectionCard, "kind">) => boolean;
33
- /** The displays, in the order the buttons show them. `jukebox` and `tower` were two more names for the deck's pile of cards (no real counterpart for cards, and the same drawing), so they are no longer offered; see `collectionViewAliases`. */
96
+ /**
97
+ * The ten displays, in the order the buttons show them, each with the label on its button. `jukebox` and `tower` were two more names for the deck's pile of cards (no real counterpart for cards, and the same drawing), so they are no longer offered; see {@link collectionViewAliases}.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * import { collectionViews } from "@johnmorrisdotca/fuda-cards/collection";
102
+ *
103
+ * console.log(collectionViews.length, collectionViews[0].label); // 10 Overlapping Deck
104
+ * ```
105
+ */
34
106
  export declare const collectionViews: ReadonlyArray<{
35
107
  id: CollectionView;
36
108
  label: string;
37
109
  }>;
38
- /** Display names that earlier versions accepted and that now open another display, so a page that sets them keeps working. */
110
+ /**
111
+ * Display names that earlier versions accepted and that now open another display, so a page that sets them keeps working.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * import { collectionViewAliases } from "@johnmorrisdotca/fuda-cards/collection";
116
+ *
117
+ * console.log(collectionViewAliases.jukebox); // deck
118
+ * ```
119
+ */
39
120
  export declare const collectionViewAliases: Readonly<Record<string, CollectionView>>;
40
- export declare function parseCollection(value: unknown): CollectionCard[];
41
- /** Choose a matching card, avoiding the current card when another match exists. */
121
+ /**
122
+ * Check a collection and make it the shape the element draws: an array of cards, or an object with a `cards` array. A card without an id is numbered by its place.
123
+ *
124
+ * @param input - An array of items, or `{ cards: [...] }` as an exported collection has it.
125
+ * @returns A new array of cards; the input is not changed.
126
+ * @throws Error saying which card is wrong (its number, and what is wrong with it) for an input that is not an array, a card that is not an object, a missing name or image, a repeated id, a back or kind of the wrong type, or invalid metadata.
127
+ * @example
128
+ * ```ts
129
+ * import { parseCollection } from "@johnmorrisdotca/fuda-cards/collection";
130
+ *
131
+ * console.log(parseCollection([{ name: "Card", image: "front.jpg" }])); // [ { id: '0', name: 'Card', image: 'front.jpg' } ]
132
+ * try {
133
+ * parseCollection([{ name: "Card" }]);
134
+ * } catch (error) {
135
+ * console.log((error as Error).message); // Card 1 needs a name and image URL.
136
+ * }
137
+ * ```
138
+ */
139
+ export declare function parseCollection(input: unknown): CollectionCard[];
140
+ /**
141
+ * Choose a card whose name contains the filter, avoiding the current card when another match exists.
142
+ *
143
+ * @param cards - The collection.
144
+ * @param current - The index of the card now on top.
145
+ * @param filter - Text the name must contain, whatever its case; spaces round it are ignored. Empty matches every card.
146
+ * @param random - A source of numbers from 0 up to but not including 1. Unless said, `Math.random`.
147
+ * @returns The index of the card to draw, or `null` when no card matches.
148
+ * @example
149
+ * ```ts
150
+ * import { randomDrawIndex } from "@johnmorrisdotca/fuda-cards/collection";
151
+ *
152
+ * const cards = ["Alpha", "Beta", "Gamma"].map((name, i) => ({ id: String(i), name, image: `${i}.jpg` }));
153
+ * console.log(randomDrawIndex(cards, 0, "", () => 0)); // 1
154
+ * console.log(randomDrawIndex(cards, 0, "zzz")); // null
155
+ * ```
156
+ */
42
157
  export declare function randomDrawIndex(cards: CollectionCard[], current: number, filter: string, random?: () => number): number | null;
43
- /** Return the first card index of a wrapped page. */
158
+ /**
159
+ * The first card of the page that is `delta` pages away, wrapping round at either end.
160
+ *
161
+ * @param index - The index of any card on the page now.
162
+ * @param length - How many cards the collection holds.
163
+ * @param pageSize - How many cards a page holds.
164
+ * @param delta - How many pages to move: 1 forward, -1 back.
165
+ * @returns The index of the first card of that page; 0 for an empty collection.
166
+ * @example
167
+ * ```ts
168
+ * import { movePage } from "@johnmorrisdotca/fuda-cards/collection";
169
+ *
170
+ * console.log(movePage(6, 7, 3, 1), movePage(0, 7, 3, -1)); // 0 6
171
+ * ```
172
+ */
44
173
  export declare function movePage(index: number, length: number, pageSize: number, delta: number): number;