@johnmorrisdotca/fuda-cards 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/collection-element.d.ts +2 -1
- package/dist/collection-element.js +8 -10
- package/dist/collection.d.ts +2 -16
- package/dist/collection.js +1 -22
- package/dist/pile.d.ts +30 -0
- package/dist/pile.js +47 -0
- package/docs/collection-displays.md +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ Run `pnpm dev` and open `/demo/collections-component.html`. Import `@johnmorrisd
|
|
|
116
116
|
|
|
117
117
|
**Choosing a display.** The twelve displays are a row of buttons across the top, each with a small picture of its layout and its name, at least 48 px high, one chosen, wrapping on a phone (4 to a row, 6 on a desk). It is a radio group: one tab stop, the arrow keys move the choice. There is no drop-down. The colours follow the reader's light or dark setting; set `theme="light"` or `theme="dark"` to choose for them.
|
|
118
118
|
|
|
119
|
-
**The deck.** `view="deck"` draws a deck of up to ten cards (with a seeded, slightly messy lie: `deck-messiness` 0 to 1, default 0.3, and `deck-seed`) and, beside it, a pile. **Next** flips the top card off the deck: it lifts, flies across and lands on the pile at the deck's other side; **Previous** brings it back. Where it lands is a choice: `deck-land="face-up"` (still facing up, the default)
|
|
119
|
+
**The deck.** `view="deck"` draws a deck of up to ten cards (with a seeded, slightly messy lie: `deck-messiness` 0 to 1, default 0.3, and `deck-seed`) and, beside it, a pile. **Next** flips the top card off the deck: it lifts, flies across and lands on the pile at the deck's other side; **Previous** brings it back. Where it lands is a choice: `deck-land="face-up"` (still facing up, the default) or `face-down` ("Turned over": it turns over sideways about its vertical axis, like turning a page, so the pile shows the card's `backImage`, or the package's own navy back when it has none). A card never lands with its picture on its head. The 0.6.0 value `upside-down` is still accepted and means `face-down`. The same card element flies, so a card is never drawn twice; with reduced motion it moves without flying. **Rotate the deck**: the deck's view controls have the angle, tilt and Auto-turn (the other displays are flat), and the whole table, both piles, turns in 3D: seen from behind you see the backs of the deck and the faces of a face-down pile.
|
|
120
120
|
|
|
121
121
|
**The fan.** `view="fan"` fans the cards out like a hand of playing cards: `fan="open"` spreads up to ten (`fan-size`, 2 to 20) in an arc so that about half of each card shows, and without it the same cards are squared up into the deck they started as. Opening and closing animate every card in turn (none with reduced motion), and closing puts each card back exactly where it started. The Open fan and Closed deck buttons under the view, or the attribute, do it.
|
|
122
122
|
|
|
@@ -22,6 +22,7 @@ export declare class FudaCollection extends HTMLElement {
|
|
|
22
22
|
disconnectedCallback(): void;
|
|
23
23
|
attributeChangedCallback(name: string): void;
|
|
24
24
|
private get currentView();
|
|
25
|
+
/** How a card taken off lands: still facing up, or turned over sideways. The 0.6.0 value `upside-down` is still accepted and means turned over. */
|
|
25
26
|
private get land();
|
|
26
27
|
private get fanOpen();
|
|
27
28
|
private get stacked();
|
|
@@ -38,7 +39,7 @@ export declare class FudaCollection extends HTMLElement {
|
|
|
38
39
|
/** One pile of the deck. `positions` are data indexes from the bottom of the pile to its top; the cards under the top one lie nudged and turned from the seed and the top one lies square. */
|
|
39
40
|
private pile;
|
|
40
41
|
private renderDeck;
|
|
41
|
-
/** The card that just moved flies between the two piles, turning over on the way if it lands face down
|
|
42
|
+
/** The card that just moved flies between the two piles, turning over sideways on the way if it lands face down. The same element, so the card is never drawn twice. */
|
|
42
43
|
private playFlip;
|
|
43
44
|
private renderFan;
|
|
44
45
|
private render;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { collectionViews,
|
|
1
|
+
import { collectionViews, parseCollection, randomDrawIndex, movePage } from './collection.js';
|
|
2
|
+
import { deckLandings, fanLayout, flight, normalizeLanding } from './pile.js';
|
|
2
3
|
import { zoomView } from './zoom.js';
|
|
3
4
|
import { createChoice, CHOICE_CSS, CHOICE_VARS } from './choice.js';
|
|
4
5
|
import { stackLayout } from './stack.js';
|
|
@@ -21,7 +22,7 @@ button:focus-visible,input:focus-visible,.card:focus-visible{outline:3px solid v
|
|
|
21
22
|
.pile .card{position:absolute;inset:0;display:block;transform-style:preserve-3d;transform:translate3d(calc(var(--x,0) * var(--w)),calc(var(--y,0) * var(--w)),calc(var(--k,0) * .9px)) rotate(calc(var(--r,0) * 1deg))}.pile .card:not(.top){pointer-events:none}.pile .card.top{cursor:pointer}
|
|
22
23
|
.fly,.turn{position:absolute;inset:0;transform-style:preserve-3d}.face{position:absolute;inset:0;backface-visibility:hidden;-webkit-backface-visibility:hidden;border-radius:5%;overflow:hidden}.face img{display:block;width:100%;height:100%;object-fit:contain;border-radius:3%;box-shadow:0 4px 10px #0008}.face.back{transform:rotateY(180deg)}
|
|
23
24
|
.generic-back{display:grid;place-items:center;background:radial-gradient(ellipse at center,#b78745 0 12%,#152d46 13% 27%,#386988 28% 31%,#10233b 32% 62%,#d2b074 63% 66%,#182c45 67%);border:6px solid #b39158;color:#f7e9bf;font:bold 18px Georgia;letter-spacing:.12em;box-shadow:0 4px 10px #0008}
|
|
24
|
-
.pile.discard[data-land=face-down] .card .turn{transform:rotateY(180deg)}
|
|
25
|
+
.pile.discard[data-land=face-down] .card .turn{transform:rotateY(180deg)}
|
|
25
26
|
.v.fan{--w:190px;display:grid;place-items:end center;padding-bottom:1rem}.fan .card{grid-area:1/1;position:relative;width:var(--w);aspect-ratio:2.5/3.5;height:auto;transform-origin:50% 165%;z-index:var(--z);transform:translate(calc(var(--cx) * var(--w)),calc(var(--cy) * var(--w))) rotate(calc(var(--cr) * 1deg));transition:transform .7s cubic-bezier(.2,.8,.2,1);transition-delay:calc((var(--n) - var(--i)) * 22ms)}.fan.open .card{transform:translate(calc(var(--x) * var(--w)),0) rotate(calc(var(--a) * 1deg));transition-delay:calc(var(--i) * 28ms)}.fan.open .card:hover,.fan.open .card:focus-visible{translate:0 -14px}.fan .card img{border-radius:6%}
|
|
26
27
|
dialog{color:var(--fc-text);background:var(--fc-dialog);border:1px solid var(--fc-btn-border);border-radius:1rem;text-align:center;max-width:95vw;max-height:95vh}dialog::backdrop{background:#000c}.detail{display:block;height:min(70vh,600px);max-width:80vw;object-fit:contain;margin:1rem auto}.empty{text-align:center;padding:3rem}
|
|
27
28
|
@media(max-width:600px){.stage{height:var(--fuda-stage-height,clamp(220px,calc(100svh - 570px),620px))}}@media(max-width:500px){.grid{grid-template-columns:repeat(min(2,var(--columns,3)),minmax(0,1fr))}.shell{padding:.7rem}.v.deck{--w:150px;gap:28px}.v.fan{--w:150px}}@media(prefers-reduced-motion:reduce){*{transition:none!important}}
|
|
@@ -74,7 +75,8 @@ export class FudaCollection extends HTMLElement {
|
|
|
74
75
|
this.flip = null;
|
|
75
76
|
} this.render(name === 'view'); }
|
|
76
77
|
get currentView() { let v = this.getAttribute('view'); return collectionViews.some(x => x.id === v) ? v : 'deck'; }
|
|
77
|
-
|
|
78
|
+
/** How a card taken off lands: still facing up, or turned over sideways. The 0.6.0 value `upside-down` is still accepted and means turned over. */
|
|
79
|
+
get land() { return normalizeLanding(this.getAttribute('deck-land')); }
|
|
78
80
|
get fanOpen() { return this.getAttribute('fan') === 'open'; }
|
|
79
81
|
get stacked() { return ![...pages, ...scrolling].includes(this.currentView); }
|
|
80
82
|
q(selector) { return this.root.querySelector(selector); }
|
|
@@ -143,7 +145,7 @@ export class FudaCollection extends HTMLElement {
|
|
|
143
145
|
this.root.innerHTML = STYLE + SHELL;
|
|
144
146
|
this.tiles = createChoice({ label: 'Display', layout: 'tiles', value: this.currentView, options: collectionViews.map(v => ({ value: v.id, label: v.label, icon: icon(v.id) })), onChange: value => { this.setAttribute('view', value); this.writeAddress(); } });
|
|
145
147
|
this.q('.displays').append(this.tiles.element);
|
|
146
|
-
this.landing = createChoice({ label: 'A card
|
|
148
|
+
this.landing = createChoice({ label: 'A card taken off lands', value: this.land, options: deckLandings.map(l => ({ value: l.id, label: l.label })), onChange: value => { this.setAttribute('deck-land', value); this.writeAddress(); } });
|
|
147
149
|
this.fanChoice = createChoice({ label: 'Fan', value: this.fanOpen ? 'open' : 'closed', options: [{ value: 'closed', label: 'Closed deck' }, { value: 'open', label: 'Open fan' }], onChange: value => { if (value === 'open')
|
|
148
150
|
this.setAttribute('fan', 'open');
|
|
149
151
|
else
|
|
@@ -247,7 +249,7 @@ export class FudaCollection extends HTMLElement {
|
|
|
247
249
|
this.playFlip(this.flip, v);
|
|
248
250
|
this.flip = null;
|
|
249
251
|
}
|
|
250
|
-
/** The card that just moved flies between the two piles, turning over on the way if it lands face down
|
|
252
|
+
/** The card that just moved flies between the two piles, turning over sideways on the way if it lands face down. The same element, so the card is never drawn twice. */
|
|
251
253
|
playFlip(direction, v) {
|
|
252
254
|
const deck = v.querySelector('.deck-pile'), discard = v.querySelector('.discard-pile');
|
|
253
255
|
const moved = direction === 'off' ? discard?.querySelector('.card.top') : deck?.querySelector('.card.top');
|
|
@@ -256,11 +258,7 @@ export class FudaCollection extends HTMLElement {
|
|
|
256
258
|
const dx = discard.offsetLeft - deck.offsetLeft, dy = discard.offsetTop - deck.offsetTop;
|
|
257
259
|
const fly = moved.querySelector('.fly'), turn = moved.querySelector('.turn');
|
|
258
260
|
const from = direction === 'off' ? { x: -dx, y: -dy } : { x: dx, y: dy };
|
|
259
|
-
|
|
260
|
-
fly.animate([{ transform: `translate3d(${from.x}px,${from.y}px,0)` }, { transform: `translate3d(${from.x / 2}px,${from.y / 2 - 34}px,80px) scale(1.07)`, offset: .5 }, { transform: 'translate3d(0,0,0)' }], options);
|
|
261
|
-
const land = this.land, final = land === 'face-down' ? 'rotateY(180deg)' : land === 'upside-down' ? 'rotate(180deg)' : 'none';
|
|
262
|
-
if (final !== 'none')
|
|
263
|
-
turn.animate(direction === 'off' ? [{ transform: 'none' }, { transform: final }] : [{ transform: final }, { transform: 'none' }], options);
|
|
261
|
+
flight(fly, turn, from, this.land, direction, 700);
|
|
264
262
|
}
|
|
265
263
|
renderFan(v) {
|
|
266
264
|
v.classList.add('fan');
|
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/pile.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a card taken off a pile lands on the pile at its side: still facing up, or turned over sideways (as a person turns a card, like a
|
|
3
|
+
* page) to show its back. `upside-down` was a 0.6.0 value that spun the picture half way round in its plane; it is still accepted and
|
|
4
|
+
* means `face-down`, so nothing breaks. A card never ends with its picture on its head.
|
|
5
|
+
*/
|
|
6
|
+
export type DeckLanding = 'face-up' | 'face-down' | 'upside-down';
|
|
7
|
+
export declare const deckLandings: ReadonlyArray<{
|
|
8
|
+
id: 'face-up' | 'face-down';
|
|
9
|
+
label: string;
|
|
10
|
+
}>;
|
|
11
|
+
/** The landing a value means: `face-down` (also `upside-down` and `turned-over`) is turned over; anything else is still facing up. */
|
|
12
|
+
export declare function normalizeLanding(value: string | null | undefined): 'face-up' | 'face-down';
|
|
13
|
+
/** Where the cards of a fan lie, first card on the left when open and on top when closed. `open` is the fan spread like a hand of playing cards; `closed` is the squared-up deck it starts from and closes back to. */
|
|
14
|
+
export interface FanPlace {
|
|
15
|
+
angle: number;
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
closedAngle: number;
|
|
19
|
+
closedX: number;
|
|
20
|
+
closedY: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function fanLayout(count: number, seed?: number): FanPlace[];
|
|
23
|
+
/**
|
|
24
|
+
* A card taken off a pile flies to the pile at its side, and turns over sideways on the way if it lands face down; coming back it
|
|
25
|
+
* does the same in reverse. `fly` carries the card across, `turn` carries the turn. `from` is how far the card is from where it ends.
|
|
26
|
+
*/
|
|
27
|
+
export declare function flight(fly: HTMLElement, turn: HTMLElement, from: {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
}, land: 'face-up' | 'face-down', direction: 'off' | 'back', ms: number): Animation[];
|
package/dist/pile.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every pile of cards shares: how a card taken off lands, how a fan lies, and how long things take.
|
|
3
|
+
*
|
|
4
|
+
* `<fuda-collection>` (the Overlapping Deck and the other displays that draw a pile) and `<fuda-card stack>` both use this one
|
|
5
|
+
* piece, so a pile fans open and closed, and a card comes off it and goes back, the same way everywhere.
|
|
6
|
+
*/
|
|
7
|
+
import { stackLayout } from './stack.js';
|
|
8
|
+
export const deckLandings = [
|
|
9
|
+
{ id: 'face-up', label: 'Still facing up' }, { id: 'face-down', label: 'Turned over' }
|
|
10
|
+
];
|
|
11
|
+
/** The landing a value means: `face-down` (also `upside-down` and `turned-over`) is turned over; anything else is still facing up. */
|
|
12
|
+
export function normalizeLanding(value) {
|
|
13
|
+
return value === 'face-down' || value === 'upside-down' || value === 'turned-over' ? 'face-down' : 'face-up';
|
|
14
|
+
}
|
|
15
|
+
export function fanLayout(count, seed = 1) {
|
|
16
|
+
const n = Math.max(0, Math.floor(count));
|
|
17
|
+
if (!n)
|
|
18
|
+
return [];
|
|
19
|
+
const spread = Math.min(110, 11 * (n - 1)), step = n > 1 ? spread / (n - 1) : 0;
|
|
20
|
+
const nudge = stackLayout(n, { messiness: 0.25, seed, depth: n });
|
|
21
|
+
return Array.from({ length: n }, (_, i) => {
|
|
22
|
+
const under = i >= 1 ? nudge[i - 1] : undefined;
|
|
23
|
+
return {
|
|
24
|
+
angle: Math.round((-spread / 2 + i * step) * 100) / 100,
|
|
25
|
+
x: Math.round((i - (n - 1) / 2) * 0.34 * 1000) / 1000,
|
|
26
|
+
y: 0,
|
|
27
|
+
closedAngle: under ? under.rotate / 3 : 0,
|
|
28
|
+
closedX: under ? under.x : 0,
|
|
29
|
+
closedY: under ? under.y : 0
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A card taken off a pile flies to the pile at its side, and turns over sideways on the way if it lands face down; coming back it
|
|
35
|
+
* does the same in reverse. `fly` carries the card across, `turn` carries the turn. `from` is how far the card is from where it ends.
|
|
36
|
+
*/
|
|
37
|
+
export function flight(fly, turn, from, land, direction, ms) {
|
|
38
|
+
const options = { duration: ms, easing: 'cubic-bezier(.3,.1,.2,1)' };
|
|
39
|
+
const out = [fly.animate([
|
|
40
|
+
{ transform: `translate3d(${from.x}px,${from.y}px,0)` },
|
|
41
|
+
{ transform: `translate3d(${from.x / 2}px,${from.y / 2 - 34}px,80px) scale(1.07)`, offset: 0.5 },
|
|
42
|
+
{ transform: 'translate3d(0,0,0)' }
|
|
43
|
+
], options)];
|
|
44
|
+
if (land === 'face-down')
|
|
45
|
+
out.push(turn.animate(direction === 'off' ? [{ transform: 'none' }, { transform: 'rotateY(180deg)' }] : [{ transform: 'rotateY(180deg)' }, { transform: 'none' }], options));
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
@@ -5,7 +5,7 @@ Fuda supplies reusable frames for a caller's cards and reusable ways to display
|
|
|
5
5
|
## Choosing a display, the deck and the fan (0.6.0)
|
|
6
6
|
|
|
7
7
|
- **Display buttons.** All twelve displays are buttons on screen at once, in a row that spans the width, each with a small picture of its layout. No drop-down. At least 48 px high; 4 to a row on a phone, 6 on a desk; arrow keys move the choice; light and dark follow the reader.
|
|
8
|
-
- **Deck.** A deck and a pile. Next flips the top card off to the pile on the deck's other side, Previous brings it back. The landing is a choice: still facing up,
|
|
8
|
+
- **Deck.** A deck and a pile. Next flips the top card off to the pile on the deck's other side, Previous brings it back. The landing is a choice: still facing up, or turned over (a sideways turn about the card's vertical axis, like turning a page, showing the back image or the package's own back). A card never lands with its picture on its head; the 0.6.0 value `upside-down` still works and means turned over. One element flies, so a card is never drawn twice. The deck turns in 3D with the angle, tilt and Auto-turn controls.
|
|
9
9
|
- **Fan.** `view="fan"`: the cards of the deck spread in an arc like a hand of playing cards (about half of each card shows) and close back to the squared-up deck, each card back where it started. The state is in the address (`?fan=open`).
|
|
10
10
|
- Not done: a fan or a pile inside `<fuda-card stack>` (those cards all carry the same picture), dealing more than one card at a time, a pile that fills up with the whole discard history (the pile shows the last ten).
|
|
11
11
|
|