@johnmorrisdotca/fuda-cards 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/binder.d.ts +52 -0
- package/dist/binder.js +117 -0
- package/dist/collection-element.d.ts +11 -0
- package/dist/collection-element.js +127 -34
- package/dist/collection.d.ts +14 -0
- package/dist/collection.js +12 -4
- package/dist/pile.d.ts +5 -0
- package/dist/pile.js +20 -7
- package/dist/zoom.d.ts +2 -2
- package/dist/zoom.js +9 -2
- package/docs/collection-displays.md +33 -7
- package/docs/collection-input.md +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,10 @@ The card has thickness, drawn to scale at the 63 mm wide card size: set `thickne
|
|
|
62
62
|
|
|
63
63
|
The top card is the live card. The block under it is one piece, and with `stack-messiness` above 0 (0 neat to 1 very messy, default 0.3) the `stack-depth` cards under the top one (default 10, at most 52) are drawn as flat stills, nudged and turned from `stack-seed`: the same seed gives the same stack, and a card put on top moves none of those under it. A stack is one 3D scene whatever its count, and it draws nothing while it is at rest: a test checks that a 52-card stack requests no frames at rest. The idea of a pile from neat to messy and its parameters come from [toranpu](https://github.com/johnmorrisdotca/toranpu)'s `<toranpu-pile>`. In script, `card.stackCount` and `card.stackHeight` (mm) are read-only, and the package exports `cardMaterials`, `stackPresets`, `stackHeightMm` and `stackLayout`.
|
|
64
64
|
|
|
65
|
+
### Binder Pages
|
|
66
|
+
|
|
67
|
+
`view="binder"` is a binder open on two facing sheets, as one is kept: each sheet is a page of clear plastic pockets (nine, three by three) with a slight sheen, one card sitting inside each pocket, on a clear or a black sheet, with a strip of punched holes down the edge that lies against the rings. Next and Previous turn the page: a leaf swings about the spine, bends as it goes and shows the pockets on its back, forwards and backwards (`animate="off"` changes the page at once, ending in exactly the same place; reduced motion likewise). Options, each a row of buttons under the view and in the address: `binder="ring|zip"` (a ring binder, or a zip binder with its zipper and pull), `cover="green|black|teal|navy|red"` (a plain cover), `sheet="clear|black"` and `pockets="4|9|12"` (two by two, three by three, four across by three down). The older `page-size` and `columns` still work and set the pockets of a sheet. Clicking a card opens it as before.
|
|
68
|
+
|
|
65
69
|
### Fan a stack, take a card off it
|
|
66
70
|
|
|
67
71
|
A stack of more than one card is a pile like the collection's deck, with the same fan and the same landing. `fan="open"` spreads up to ten cards in an arc (every card drawn with its face and the picture) and closes back exactly where they began. `taken-off="3"` puts the top three cards on a pile at the stack's side, as thick as the cards in it: `card.takeOff()` flies the top card across and `card.putBack()` brings it back, and `deck-land="face-up"` (the default) or `"face-down"` (turned over sideways, showing the back) says how it lands. `pile-controls` draws three buttons (Fan, Take a card off, Put it back; each at least 48 px) under the card; leave about 70 px of room below it. `animate="off"` and `speed="slow|quick"` are the same as in the collection. The card turns with the pile (the angle, tilt and Auto-turn work as before) and an open fan or a pile at the side is part of what turns: `card.pileBounds` says how far they reach beyond the card, in card widths, and `fuda-pile` is sent when it changes, so a page can fit its view.
|
|
@@ -122,11 +126,11 @@ Open `demo/tcgdex.html` through the local server to browse the Pokémon Base Set
|
|
|
122
126
|
|
|
123
127
|
## Collection viewer
|
|
124
128
|
|
|
125
|
-
Run `pnpm dev` and open `/demo/collections-component.html`. Import `@johnmorrisdotca/fuda-cards/collection-element` to register the element, then set its `cards` property to an array of `{ id, name, image, backImage? }
|
|
129
|
+
Run `pnpm dev` and open `/demo/collections-component.html`. Import `@johnmorrisdotca/fuda-cards/collection-element` to register the element, then set its `cards` property to an array of `{ id, name, image, backImage?, kind? }` (`kind` is `"card"`, the default, or `"object"`: a picture of a thing that is not a card, such as a games console, which has no back and no thickness and so never turns over; see `docs/collection-input.md`). Image URLs are loaded by the viewer's browser. `id` is optional on input (the position is used if omitted); IDs must be unique. Set `view` to `deck`, `rolodex`, `binder`, `case`, `random`, `story`, `wall`, `spotlight`, `atlas` or `fan` (`jukebox` and `tower`, dropped in 0.8.0, still open the deck). Set `page-size` for the binder and case (1–100 cards) and `columns` (1–10) for their grid; small screens use at most two columns. In random view, filter card names to limit the draw; the draw button is disabled when no cards match.
|
|
126
130
|
|
|
127
|
-
**Choosing a display.** The
|
|
131
|
+
**Choosing a display.** The ten 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.
|
|
128
132
|
|
|
129
|
-
**The deck, and the other piles.**
|
|
133
|
+
**The deck, and the other piles.** Two displays draw a pile of cards, and each does everything a pile does: it turns in 3D, it fans open and closed, and a card comes off it onto a pile at its side. They are the Overlapping Deck (`view="deck"`) and Random Draw; the Fan of Cards is the same pile with only its fan. (Jukebox Carousel and Flip Tower drew the same pile of three cards, had no real counterpart for cards, and were dropped in 0.8.0.) Rolodex and Spotlight Carousel spread their cards out instead of piling them, so they are carousels and stay as they were. `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 a pile**: a pile'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.
|
|
130
134
|
|
|
131
135
|
**The fan.** Every pile fans open and closes with the **Fan** buttons right under the view (or `fan="open"`): up to ten cards spread in an arc like a hand of playing cards so that most of each card shows, and closing puts each card back exactly where it started. The pile beside the deck moves out of the way and the view fits the open fan (a phone included). A card can still be taken off an open fan, and off a pile that was fanned and closed. `view="fan"` is the same pile with only its fan: `fan-size` (2 to 10) cards from the current one, Next moves the window on. The fan is in the address (`?fan=open`).
|
|
132
136
|
|
package/dist/binder.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Binder Pages display: a ring or zip binder opened on two facing sheets, each sheet a page of clear plastic pockets (nine, three by
|
|
3
|
+
* three, unless asked otherwise) with one card inside each pocket, on a clear or black backing with a strip of punched holes down the edge
|
|
4
|
+
* that lies against the rings. A page turn swings one leaf about the spine; the leaf bends as it turns and shows the pockets on its back.
|
|
5
|
+
*
|
|
6
|
+
* A leaf has two sides, as a real one does: leaf k holds sides 2k (the right-hand page) and 2k+1 (the left-hand page of the next opening).
|
|
7
|
+
* An opening (spread) j shows side 2j-1 on the left (none at the start) and side 2j on the right.
|
|
8
|
+
*/
|
|
9
|
+
export type BinderStyle = 'ring' | 'zip';
|
|
10
|
+
export type BinderSheet = 'clear' | 'black';
|
|
11
|
+
export declare const binderCovers: ReadonlyArray<{
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
color: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** The sheets a binder takes: how many pockets and how they lie (across by down). 9 is the usual page; 4 and 12 are the other common ones. */
|
|
17
|
+
export declare const binderPockets: ReadonlyArray<{
|
|
18
|
+
count: number;
|
|
19
|
+
cols: number;
|
|
20
|
+
rows: number;
|
|
21
|
+
}>;
|
|
22
|
+
export interface BinderLayout {
|
|
23
|
+
cols: number;
|
|
24
|
+
rows: number;
|
|
25
|
+
per: number;
|
|
26
|
+
}
|
|
27
|
+
/** The pockets of a sheet: `pockets` (4, 9 or 12) if the page asks, else the older `columns` and `page-size`, else nine in three columns. */
|
|
28
|
+
export declare function binderLayout(pockets: string | null, columns: string | null, pageSize: string | null): BinderLayout;
|
|
29
|
+
/** How many sides a collection of `cards` fills, and how many openings that makes. */
|
|
30
|
+
export declare const sideCount: (cards: number, per: number) => number;
|
|
31
|
+
export declare const spreadCount: (sides: number) => number;
|
|
32
|
+
/** The opening a card is on: its side's number, halved and rounded up. */
|
|
33
|
+
export declare const spreadOf: (index: number, per: number) => number;
|
|
34
|
+
/** The sides an opening shows (-1 where there is none), left then right, for `sides` sides in all. */
|
|
35
|
+
export declare function spreadSides(spread: number, sides: number): [number, number];
|
|
36
|
+
export declare const BINDER_CSS = "\n.stage.binder{perspective:2400px;background:radial-gradient(ellipse,var(--fc-stage-1),var(--fc-stage-2) 68%)}\n.v.binder{--sw:300px;--sh:384px;--strip:34px;--cover:#1f7a4a;display:flex;align-items:center;justify-content:center;transform-style:preserve-3d}\n.book{position:relative;display:flex;padding:18px 16px;border-radius:16px;background:var(--cover);box-shadow:0 12px 28px #0008,inset 0 0 0 2px #fff2,inset 0 0 24px #0005;transform-style:preserve-3d}\n.book::before{content:'';position:absolute;inset:6px;border-radius:12px;box-shadow:inset 0 0 0 2px #0004;pointer-events:none}\n.book.b-zip::after{content:'';position:absolute;inset:5px;border-radius:13px;border:3px dotted #cfd2d8;opacity:.7;pointer-events:none}\n.book .tab{display:none}.book.b-zip .tab{display:block;position:absolute;right:30px;bottom:-4px;width:34px;height:14px;border-radius:5px;background:linear-gradient(#e4e6ea,#8d9098);box-shadow:0 2px 4px #0006}\n.inside{position:relative;display:flex;transform-style:preserve-3d;background:var(--lining,#f1eee6);border-radius:6px;box-shadow:inset 0 0 18px #0003}\n.half{position:relative;width:var(--sw);height:var(--sh);flex:none}\n.half:empty::after{content:'';position:absolute;inset:0;background:linear-gradient(90deg,#0002,transparent 14%)}\n.spine{position:absolute;left:50%;top:0;bottom:0;width:0;transform-style:preserve-3d;pointer-events:none;z-index:3}\n.ring{position:absolute;left:-9px;width:18px;height:46px;margin-top:-23px;border-radius:9px;border:4px solid #c3c6cd;border-color:#f1f2f5 #8d9098 #8d9098 #f1f2f5;box-shadow:0 2px 3px #0005;transform:translateZ(2px)}\n.side{position:absolute;inset:0;display:grid;padding:12px 10px;grid-template-columns:repeat(var(--cols,3),minmax(0,1fr));grid-template-rows:repeat(var(--rows,3),minmax(0,1fr));gap:5px;background:var(--sheetbg);box-sizing:border-box;border:1px solid var(--sheetedge)}\n.side.clear{--sheetbg:#ffffff2e;--sheetedge:#ffffff55;--pocketbg:#ffffff26;--pocketedge:#ffffffa0}.side.black{--sheetbg:#17171b;--sheetedge:#000;--pocketbg:#ffffff12;--pocketedge:#ffffff55}\n.side.r{padding-left:calc(var(--strip) + 6px)}.side.l{padding-right:calc(var(--strip) + 6px)}\n.holes{position:absolute;top:0;bottom:0;width:var(--strip);display:flex;flex-direction:column;justify-content:space-evenly;align-items:center;padding:14px 0}.side.r .holes{left:0}.side.l .holes{right:0}.holes i{width:9px;height:9px;border-radius:50%;background:var(--lining,#f1eee6);box-shadow:inset 0 1px 2px #0007,0 0 0 1px #0002}\n.pocket{position:relative;display:grid;place-items:center;border-radius:4px;background:var(--pocketbg);border:1px solid var(--pocketedge);box-shadow:inset 0 0 0 1px #0000000d,0 1px 2px #0003;overflow:hidden;min-width:0;min-height:0}\n.pocket::after{content:'';position:absolute;inset:0;pointer-events:none;background:linear-gradient(118deg,#ffffff55 0,#ffffff00 32%,#ffffff12 55%,#ffffff00 70%,#ffffff33 100%)}\n.pocket .card{position:relative;z-index:0;width:86%;height:92%;padding:0;border:0;background:transparent;line-height:0;display:grid;place-items:center}.pocket .card img{width:100%;height:100%;object-fit:contain;border-radius:3%;box-shadow:0 2px 5px #0007}\n.pocket.empty{opacity:.55}\n.leaf{position:absolute;left:50%;top:0;width:var(--sw);height:var(--sh);transform-origin:0 50%;transform-style:preserve-3d;pointer-events:none;z-index:2}\n.slice{position:absolute;top:0;height:100%;transform-origin:0 50%;transform-style:preserve-3d}\n.slice>.f,.slice>.b{position:absolute;inset:0 -1.5px;backface-visibility:hidden;-webkit-backface-visibility:hidden;overflow:hidden}.slice>.b{transform:rotateY(180deg)}\n.slice .sf{position:absolute;top:0;height:100%}\n/* The slices overlap their neighbours by a pixel and a half, so no seam between them lets the page behind show; the outer edges of the leaf stay where they are. */\n.slice.first>.f,.slice.last>.b{left:0}.slice.first>.b,.slice.last>.f{right:0}\n";
|
|
37
|
+
/** The cards a side holds, as indexes into the collection (or -1 for an empty pocket), in reading order. */
|
|
38
|
+
export declare function sideCards(side: number, layout: BinderLayout, total: number): number[];
|
|
39
|
+
export interface PocketMaker {
|
|
40
|
+
(index: number, live: boolean): HTMLElement;
|
|
41
|
+
}
|
|
42
|
+
/** One side as it lies in the book: `left` or `right` of the spine, with its hole strip against the spine. `live` pockets hold the page's real card buttons; the rest hold pictures only. */
|
|
43
|
+
export declare function buildSide(side: number, where: 'l' | 'r', sheet: BinderSheet, layout: BinderLayout, total: number, pocket: PocketMaker, live?: boolean): HTMLElement;
|
|
44
|
+
/**
|
|
45
|
+
* A leaf of the book, built to swing: a chain of slices hinged one on the next (the hole strip, then a slice for each column of
|
|
46
|
+
* pockets), so that each can lean a little more than the one before it and the sheet bends. Each slice has the pockets of the front side on its
|
|
47
|
+
* front and the matching column of the back side on its back. Returns the leaf and its slices.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildLeaf(front: number, back: number, sheet: BinderSheet, layout: BinderLayout, total: number, pocket: PocketMaker, widthPx: number, strip: number): {
|
|
50
|
+
leaf: HTMLElement;
|
|
51
|
+
slices: HTMLElement[];
|
|
52
|
+
};
|
package/dist/binder.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export const binderCovers = [
|
|
2
|
+
{ id: 'green', label: 'Green', color: '#1f7a4a' }, { id: 'black', label: 'Black', color: '#1d1d22' }, { id: 'teal', label: 'Teal', color: '#1a9d93' },
|
|
3
|
+
{ id: 'navy', label: 'Navy', color: '#1f3a70' }, { id: 'red', label: 'Red', color: '#b0262d' }
|
|
4
|
+
];
|
|
5
|
+
/** The sheets a binder takes: how many pockets and how they lie (across by down). 9 is the usual page; 4 and 12 are the other common ones. */
|
|
6
|
+
export const binderPockets = [
|
|
7
|
+
{ count: 4, cols: 2, rows: 2 }, { count: 9, cols: 3, rows: 3 }, { count: 12, cols: 4, rows: 3 }
|
|
8
|
+
];
|
|
9
|
+
/** The pockets of a sheet: `pockets` (4, 9 or 12) if the page asks, else the older `columns` and `page-size`, else nine in three columns. */
|
|
10
|
+
export function binderLayout(pockets, columns, pageSize) {
|
|
11
|
+
const known = binderPockets.find((p) => String(p.count) === pockets);
|
|
12
|
+
if (known)
|
|
13
|
+
return { cols: known.cols, rows: known.rows, per: known.count };
|
|
14
|
+
const size = Math.min(100, Math.max(1, Math.floor(Number(pageSize)) || 9));
|
|
15
|
+
const cols = Math.min(10, Math.max(1, Math.floor(Number(columns)) || 3), size);
|
|
16
|
+
return { cols, rows: Math.ceil(size / cols), per: size };
|
|
17
|
+
}
|
|
18
|
+
/** How many sides a collection of `cards` fills, and how many openings that makes. */
|
|
19
|
+
export const sideCount = (cards, per) => Math.max(1, Math.ceil(cards / per));
|
|
20
|
+
export const spreadCount = (sides) => Math.ceil((sides + 1) / 2);
|
|
21
|
+
/** The opening a card is on: its side's number, halved and rounded up. */
|
|
22
|
+
export const spreadOf = (index, per) => Math.ceil(Math.floor(index / per) / 2);
|
|
23
|
+
/** The sides an opening shows (-1 where there is none), left then right, for `sides` sides in all. */
|
|
24
|
+
export function spreadSides(spread, sides) {
|
|
25
|
+
const left = 2 * spread - 1, right = 2 * spread;
|
|
26
|
+
return [left >= 0 && left < sides ? left : -1, right < sides ? right : -1];
|
|
27
|
+
}
|
|
28
|
+
export const BINDER_CSS = `
|
|
29
|
+
.stage.binder{perspective:2400px;background:radial-gradient(ellipse,var(--fc-stage-1),var(--fc-stage-2) 68%)}
|
|
30
|
+
.v.binder{--sw:300px;--sh:384px;--strip:34px;--cover:#1f7a4a;display:flex;align-items:center;justify-content:center;transform-style:preserve-3d}
|
|
31
|
+
.book{position:relative;display:flex;padding:18px 16px;border-radius:16px;background:var(--cover);box-shadow:0 12px 28px #0008,inset 0 0 0 2px #fff2,inset 0 0 24px #0005;transform-style:preserve-3d}
|
|
32
|
+
.book::before{content:'';position:absolute;inset:6px;border-radius:12px;box-shadow:inset 0 0 0 2px #0004;pointer-events:none}
|
|
33
|
+
.book.b-zip::after{content:'';position:absolute;inset:5px;border-radius:13px;border:3px dotted #cfd2d8;opacity:.7;pointer-events:none}
|
|
34
|
+
.book .tab{display:none}.book.b-zip .tab{display:block;position:absolute;right:30px;bottom:-4px;width:34px;height:14px;border-radius:5px;background:linear-gradient(#e4e6ea,#8d9098);box-shadow:0 2px 4px #0006}
|
|
35
|
+
.inside{position:relative;display:flex;transform-style:preserve-3d;background:var(--lining,#f1eee6);border-radius:6px;box-shadow:inset 0 0 18px #0003}
|
|
36
|
+
.half{position:relative;width:var(--sw);height:var(--sh);flex:none}
|
|
37
|
+
.half:empty::after{content:'';position:absolute;inset:0;background:linear-gradient(90deg,#0002,transparent 14%)}
|
|
38
|
+
.spine{position:absolute;left:50%;top:0;bottom:0;width:0;transform-style:preserve-3d;pointer-events:none;z-index:3}
|
|
39
|
+
.ring{position:absolute;left:-9px;width:18px;height:46px;margin-top:-23px;border-radius:9px;border:4px solid #c3c6cd;border-color:#f1f2f5 #8d9098 #8d9098 #f1f2f5;box-shadow:0 2px 3px #0005;transform:translateZ(2px)}
|
|
40
|
+
.side{position:absolute;inset:0;display:grid;padding:12px 10px;grid-template-columns:repeat(var(--cols,3),minmax(0,1fr));grid-template-rows:repeat(var(--rows,3),minmax(0,1fr));gap:5px;background:var(--sheetbg);box-sizing:border-box;border:1px solid var(--sheetedge)}
|
|
41
|
+
.side.clear{--sheetbg:#ffffff2e;--sheetedge:#ffffff55;--pocketbg:#ffffff26;--pocketedge:#ffffffa0}.side.black{--sheetbg:#17171b;--sheetedge:#000;--pocketbg:#ffffff12;--pocketedge:#ffffff55}
|
|
42
|
+
.side.r{padding-left:calc(var(--strip) + 6px)}.side.l{padding-right:calc(var(--strip) + 6px)}
|
|
43
|
+
.holes{position:absolute;top:0;bottom:0;width:var(--strip);display:flex;flex-direction:column;justify-content:space-evenly;align-items:center;padding:14px 0}.side.r .holes{left:0}.side.l .holes{right:0}.holes i{width:9px;height:9px;border-radius:50%;background:var(--lining,#f1eee6);box-shadow:inset 0 1px 2px #0007,0 0 0 1px #0002}
|
|
44
|
+
.pocket{position:relative;display:grid;place-items:center;border-radius:4px;background:var(--pocketbg);border:1px solid var(--pocketedge);box-shadow:inset 0 0 0 1px #0000000d,0 1px 2px #0003;overflow:hidden;min-width:0;min-height:0}
|
|
45
|
+
.pocket::after{content:'';position:absolute;inset:0;pointer-events:none;background:linear-gradient(118deg,#ffffff55 0,#ffffff00 32%,#ffffff12 55%,#ffffff00 70%,#ffffff33 100%)}
|
|
46
|
+
.pocket .card{position:relative;z-index:0;width:86%;height:92%;padding:0;border:0;background:transparent;line-height:0;display:grid;place-items:center}.pocket .card img{width:100%;height:100%;object-fit:contain;border-radius:3%;box-shadow:0 2px 5px #0007}
|
|
47
|
+
.pocket.empty{opacity:.55}
|
|
48
|
+
.leaf{position:absolute;left:50%;top:0;width:var(--sw);height:var(--sh);transform-origin:0 50%;transform-style:preserve-3d;pointer-events:none;z-index:2}
|
|
49
|
+
.slice{position:absolute;top:0;height:100%;transform-origin:0 50%;transform-style:preserve-3d}
|
|
50
|
+
.slice>.f,.slice>.b{position:absolute;inset:0 -1.5px;backface-visibility:hidden;-webkit-backface-visibility:hidden;overflow:hidden}.slice>.b{transform:rotateY(180deg)}
|
|
51
|
+
.slice .sf{position:absolute;top:0;height:100%}
|
|
52
|
+
/* The slices overlap their neighbours by a pixel and a half, so no seam between them lets the page behind show; the outer edges of the leaf stay where they are. */
|
|
53
|
+
.slice.first>.f,.slice.last>.b{left:0}.slice.first>.b,.slice.last>.f{right:0}
|
|
54
|
+
`;
|
|
55
|
+
/** The cards a side holds, as indexes into the collection (or -1 for an empty pocket), in reading order. */
|
|
56
|
+
export function sideCards(side, layout, total) {
|
|
57
|
+
return Array.from({ length: layout.per }, (_, k) => (side * layout.per + k < total ? side * layout.per + k : -1));
|
|
58
|
+
}
|
|
59
|
+
/** One side as it lies in the book: `left` or `right` of the spine, with its hole strip against the spine. `live` pockets hold the page's real card buttons; the rest hold pictures only. */
|
|
60
|
+
export function buildSide(side, where, sheet, layout, total, pocket, live = true) {
|
|
61
|
+
const el = document.createElement('div');
|
|
62
|
+
el.className = `side ${where} ${sheet}`;
|
|
63
|
+
el.dataset.side = String(side);
|
|
64
|
+
el.style.setProperty('--cols', String(layout.cols));
|
|
65
|
+
el.style.setProperty('--rows', String(layout.rows));
|
|
66
|
+
const holes = document.createElement('div');
|
|
67
|
+
holes.className = 'holes';
|
|
68
|
+
holes.innerHTML = '<i></i>'.repeat(9);
|
|
69
|
+
el.append(holes);
|
|
70
|
+
for (const index of sideCards(side, layout, total))
|
|
71
|
+
el.append(index < 0 ? Object.assign(document.createElement('div'), { className: 'pocket empty' }) : pocket(index, live));
|
|
72
|
+
return el;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A leaf of the book, built to swing: a chain of slices hinged one on the next (the hole strip, then a slice for each column of
|
|
76
|
+
* pockets), so that each can lean a little more than the one before it and the sheet bends. Each slice has the pockets of the front side on its
|
|
77
|
+
* front and the matching column of the back side on its back. Returns the leaf and its slices.
|
|
78
|
+
*/
|
|
79
|
+
export function buildLeaf(front, back, sheet, layout, total, pocket, widthPx, strip) {
|
|
80
|
+
const leaf = document.createElement('div');
|
|
81
|
+
leaf.className = 'leaf';
|
|
82
|
+
const faces = (side, where) => side < 0 ? null : buildSide(side, where, sheet, layout, total, pocket, false);
|
|
83
|
+
const rightSide = faces(front, 'r'), leftSide = faces(back, 'l');
|
|
84
|
+
const widths = [strip + 6, ...Array.from({ length: layout.cols }, () => (widthPx - strip - 6) / layout.cols)];
|
|
85
|
+
const slices = [];
|
|
86
|
+
let parent = leaf, offset = 0;
|
|
87
|
+
widths.forEach((w, k) => {
|
|
88
|
+
const slice = document.createElement('div');
|
|
89
|
+
slice.className = k === 0 ? 'slice first' : k === widths.length - 1 ? 'slice last' : 'slice';
|
|
90
|
+
slice.style.width = `${w}px`;
|
|
91
|
+
slice.style.left = k === 0 ? '0' : '100%';
|
|
92
|
+
const f = document.createElement('div'), b = document.createElement('div');
|
|
93
|
+
f.className = 'f';
|
|
94
|
+
b.className = 'b';
|
|
95
|
+
// The whole side is placed inside each slice's face and shifted so that this slice shows its own part of it.
|
|
96
|
+
if (rightSide) {
|
|
97
|
+
const copy = rightSide.cloneNode(true);
|
|
98
|
+
copy.classList.add('sf');
|
|
99
|
+
copy.style.width = `${widthPx}px`;
|
|
100
|
+
copy.style.left = `${-offset}px`;
|
|
101
|
+
f.append(copy);
|
|
102
|
+
}
|
|
103
|
+
if (leftSide) {
|
|
104
|
+
const copy = leftSide.cloneNode(true);
|
|
105
|
+
copy.classList.add('sf');
|
|
106
|
+
copy.style.width = `${widthPx}px`;
|
|
107
|
+
copy.style.left = `${-(widthPx - offset - w)}px`;
|
|
108
|
+
b.append(copy);
|
|
109
|
+
}
|
|
110
|
+
slice.append(f, b);
|
|
111
|
+
parent.append(slice);
|
|
112
|
+
parent = slice;
|
|
113
|
+
offset += w;
|
|
114
|
+
slices.push(slice);
|
|
115
|
+
});
|
|
116
|
+
return { leaf, slices };
|
|
117
|
+
}
|
|
@@ -13,6 +13,8 @@ export declare class FudaCollection extends HTMLElement {
|
|
|
13
13
|
private fanChoice?;
|
|
14
14
|
private animateChoice?;
|
|
15
15
|
private speedChoice?;
|
|
16
|
+
private binderChoices;
|
|
17
|
+
private turn;
|
|
16
18
|
private flip;
|
|
17
19
|
private addressTimer;
|
|
18
20
|
private fanPlaces;
|
|
@@ -30,12 +32,17 @@ export declare class FudaCollection extends HTMLElement {
|
|
|
30
32
|
private get fanOpen();
|
|
31
33
|
private get stacked();
|
|
32
34
|
private get piled();
|
|
35
|
+
/** 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. */
|
|
36
|
+
private get hasCards();
|
|
33
37
|
private get turnable();
|
|
34
38
|
private q;
|
|
35
39
|
/** 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. */
|
|
36
40
|
private readAddress;
|
|
37
41
|
private writeAddress;
|
|
38
42
|
private move;
|
|
43
|
+
private binderLay;
|
|
44
|
+
/** 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. */
|
|
45
|
+
private spreadFirst;
|
|
39
46
|
private image;
|
|
40
47
|
private open;
|
|
41
48
|
private renderDialog;
|
|
@@ -62,5 +69,9 @@ export declare class FudaCollection extends HTMLElement {
|
|
|
62
69
|
private enter;
|
|
63
70
|
/** 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. */
|
|
64
71
|
private play;
|
|
72
|
+
private syncBinder;
|
|
73
|
+
private binderCount;
|
|
74
|
+
/** 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. */
|
|
75
|
+
private renderBinder;
|
|
65
76
|
private render;
|
|
66
77
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { collectionViews, parseCollection, randomDrawIndex, movePage } from './collection.js';
|
|
1
|
+
import { collectionViewAliases, collectionViews, isCard, parseCollection, randomDrawIndex, movePage } from './collection.js';
|
|
2
|
+
import { BINDER_CSS, binderCovers, binderLayout, buildLeaf, buildSide, sideCount, spreadCount, spreadOf, spreadSides } from './binder.js';
|
|
2
3
|
import { deckLandings, fanBounds, fanLayout, fanShift, flight, normalizeLanding, timing } from './pile.js';
|
|
3
4
|
import { zoomView } from './zoom.js';
|
|
4
5
|
import { createChoice, CHOICE_CSS, CHOICE_VARS } from './choice.js';
|
|
@@ -7,18 +8,18 @@ const STYLE = `<style>
|
|
|
7
8
|
:host{display:block;${CHOICE_VARS.dark};color:var(--fc-text);font:16px system-ui}@media(prefers-color-scheme:light){:host(:not([theme="dark"])){${CHOICE_VARS.light}}}:host([theme="light"]){${CHOICE_VARS.light}}:host([theme="dark"]){${CHOICE_VARS.dark}}
|
|
8
9
|
*{box-sizing:border-box}.shell{background:var(--fc-surface);padding:1rem;border-radius:1rem;display:grid;gap:.9rem}.nav{display:flex;gap:.6rem;align-items:center;justify-content:center;flex-wrap:wrap}.opts{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,13.5rem),1fr));gap:.9rem}.opts:not(:has(.choice:not([hidden]))){display:none}.opts .choice{--choice-min:4.6rem}
|
|
9
10
|
button,input{font:inherit;color:inherit}.nav button,dialog button{min-height:48px;min-width:48px;background:var(--fc-btn);border:2px solid var(--fc-btn-border);border-radius:.7rem;padding:.5rem 1rem;cursor:pointer}.nav button:disabled{opacity:.45;cursor:default}.nav input{min-height:48px;background:var(--fc-btn);border:2px solid var(--fc-btn-border);border-radius:.7rem;padding:.5rem .8rem}
|
|
10
|
-
button:focus-visible,input:focus-visible,.card:focus-visible{outline:3px solid var(--fc-focus);outline-offset:3px}${CHOICE_CSS}
|
|
11
|
+
button:focus-visible,input:focus-visible,.card:focus-visible{outline:3px solid var(--fc-focus);outline-offset:3px}${CHOICE_CSS}${BINDER_CSS}
|
|
11
12
|
.displays .choice-list{grid-template-columns:repeat(3,minmax(0,1fr))}@media(min-width:340px){.displays .choice-list{grid-template-columns:repeat(4,minmax(0,1fr))}.displays .choice-list button{min-height:50px;padding:.3rem .25rem;font-size:.7rem}.displays .choice-list svg{width:28px;height:18px}}@media(min-width:800px){.displays .choice-list{grid-template-columns:repeat(6,minmax(0,1fr))}.displays .choice-list button{min-height:56px;padding:.45rem .7rem;font-size:.8rem}.displays .choice-list svg{width:34px;height:22px}}
|
|
12
13
|
.stage{position:relative;height:var(--fuda-stage-height,clamp(300px,calc(100svh - 440px),620px));overflow:hidden;border-radius:1rem;background:radial-gradient(ellipse,var(--fc-stage-1),var(--fc-stage-2) 68%)}.stage:focus-visible{outline:3px solid var(--fc-focus);outline-offset:2px}.v{position:absolute;inset:0}kazoku-view-controls{display:block}
|
|
13
14
|
.card{padding:0;border:0;background:transparent;line-height:0}.card img{width:100%;height:100%;object-fit:contain;border-radius:5%;box-shadow:0 6px 16px #0009}
|
|
14
15
|
.stack .card{position:absolute;width:min(64vw,300px);height:86%;top:7%;left:50%;transition:transform .25s}
|
|
15
16
|
.grid{display:grid;grid-template-columns:repeat(var(--columns,3),minmax(0,1fr));gap:1rem;padding:1rem;align-content:start}.grid .card{height:clamp(130px,24vw,220px)}
|
|
16
|
-
.v.case{perspective:800px}.stage.case{background:linear-gradient(#
|
|
17
|
+
.v.case{perspective:800px}.stage.case{background:linear-gradient(#4a3f33,#1d1914);border:10px solid #6b5436;box-shadow:inset 0 0 26px #000a}.stage.case::after{content:'';position:absolute;inset:0;pointer-events:none;z-index:2;background:linear-gradient(115deg,#ffffff30 0,#ffffff00 28%,#ffffff12 55%,#ffffff00 78%,#ffffff22 100%)}.case .card{transform:perspective(600px) rotateX(-15deg);box-shadow:0 12px 0 -3px #2c251d,0 18px 8px -4px #000a}.case .card img{box-shadow:0 4px 10px #0009}
|
|
17
18
|
.wall{display:flex;gap:1rem;align-items:center;padding:1rem}.wall .card{height:90%;flex:0 0 190px}
|
|
18
19
|
.story{display:flex;flex-direction:column;align-items:center;gap:1rem;padding:1rem}.story .card{width:min(75%,300px);flex:0 0 90%}
|
|
19
20
|
.plane{position:absolute;left:0;top:0;display:grid;gap:18px;grid-template-columns:repeat(var(--atlas-cols,5),140px);padding:30px}.plane .card{height:195px}
|
|
20
|
-
.stage.
|
|
21
|
-
.stage:is(.deck,.random,.
|
|
21
|
+
.stage.spotlight{background:radial-gradient(ellipse at center,#e5ce99,#454054 40%,#171822 78%)}
|
|
22
|
+
.stage:is(.deck,.random,.fan){perspective:1800px}.v.deck{--w:200px;--gap:56px;--fl:0;--fr:0;--ft:0;--fb:0;--ease:cubic-bezier(.2,.8,.2,1);transform-style:preserve-3d}
|
|
22
23
|
.v.deck .pile,.v.deck .slot{position:absolute;left:50%;top:50%;width:var(--w);aspect-ratio:2.5/3.5;margin:calc(var(--w) * -.7) 0 0 calc(var(--w) * -.5);transform-style:preserve-3d}.slot{border:2px dashed var(--fc-btn-border);border-radius:5%;opacity:.55}
|
|
23
24
|
.v.deck .deck-pile{translate:calc(((var(--fl) - var(--fr) - 1) * var(--w) - var(--gap)) / 2) 0}.v.deck .discard-pile,.v.deck .slot{translate:calc(((var(--fl) + var(--fr) + 1) * var(--w) + var(--gap)) / 2) 0}.v.deck.fanonly .deck-pile{translate:calc((var(--fl) - var(--fr)) * var(--w) / 2) 0}
|
|
24
25
|
.v.deck .deck-pile,.v.deck .discard-pile,.v.deck .slot{transition:translate var(--t,0s) var(--ease)}
|
|
@@ -27,7 +28,7 @@ button:focus-visible,input:focus-visible,.card:focus-visible{outline:3px solid v
|
|
|
27
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}
|
|
28
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)}
|
|
29
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}
|
|
30
|
-
.pile.discard[data-land=face-down] .card .turn{transform:rotateY(180deg)}.ghost{pointer-events:none}
|
|
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}
|
|
31
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}
|
|
32
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}}
|
|
33
34
|
</style>`;
|
|
@@ -35,7 +36,7 @@ const SHELL = `<section class="shell"><div class="displays"></div><div class="st
|
|
|
35
36
|
const pages = ['binder', 'case'];
|
|
36
37
|
const scrolling = ['wall', 'story', 'atlas'];
|
|
37
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. */
|
|
38
|
-
const pileViews = ['deck', 'random'
|
|
39
|
+
const pileViews = ['deck', 'random'];
|
|
39
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. */
|
|
40
41
|
const gliding = ['rolodex', 'spotlight', 'fan'];
|
|
41
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('');
|
|
@@ -54,7 +55,7 @@ const ICONS = {
|
|
|
54
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('')
|
|
55
56
|
};
|
|
56
57
|
const icon = (view) => `<svg viewBox="0 0 34 22" aria-hidden="true">${ICONS[view]}</svg>`;
|
|
57
|
-
const ADDRESS_KEYS = ['view', 'fan', 'land', 'animate', 'speed'];
|
|
58
|
+
const ADDRESS_KEYS = ['view', 'fan', 'land', 'animate', 'speed', 'binder', 'cover', 'sheet', 'pockets'];
|
|
58
59
|
const NAMES = { land: 'deck-land' };
|
|
59
60
|
export class FudaCollection extends HTMLElement {
|
|
60
61
|
root = this.attachShadow({ mode: 'open' });
|
|
@@ -70,10 +71,12 @@ export class FudaCollection extends HTMLElement {
|
|
|
70
71
|
fanChoice;
|
|
71
72
|
animateChoice;
|
|
72
73
|
speedChoice;
|
|
74
|
+
binderChoices = {};
|
|
75
|
+
turn = null;
|
|
73
76
|
flip = null;
|
|
74
77
|
addressTimer = 0;
|
|
75
78
|
fanPlaces = [];
|
|
76
|
-
static get observedAttributes() { return ['view', 'page-size', 'columns', 'fan', 'fan-size', 'deck-land', 'deck-messiness', 'deck-seed', 'theme', 'animate', 'speed']; }
|
|
79
|
+
static get observedAttributes() { return ['view', 'page-size', 'columns', 'fan', 'fan-size', 'deck-land', 'deck-messiness', 'deck-seed', 'theme', 'animate', 'speed', 'binder', 'cover', 'sheet', 'pockets']; }
|
|
77
80
|
set cards(value) { this.data = parseCollection(value); this.index = Math.min(this.index, Math.max(0, this.data.length - 1)); this.flip = null; this.render(); }
|
|
78
81
|
get cards() { return this.data.map(c => ({ ...c, ...(c.metadata ? { metadata: { ...c.metadata } } : {}) })); }
|
|
79
82
|
/** The card on top of the deck, or the first card of the page or fan (counting from 0). */
|
|
@@ -96,13 +99,15 @@ export class FudaCollection extends HTMLElement {
|
|
|
96
99
|
}
|
|
97
100
|
this.render(name === 'view', name === 'view' ? { kind: 'view', dir: 1 } : undefined);
|
|
98
101
|
}
|
|
99
|
-
get currentView() { let v = this.getAttribute('view'); return collectionViews.some(x => x.id === v) ? v : 'deck'; }
|
|
102
|
+
get currentView() { let v = this.getAttribute('view') ?? ''; v = collectionViewAliases[v] ?? v; return collectionViews.some(x => x.id === v) ? v : 'deck'; }
|
|
100
103
|
/** How a card taken off lands: still facing up, or turned over sideways. The 0.6.0 value `upside-down` is still accepted and means turned over. */
|
|
101
104
|
get land() { return normalizeLanding(this.getAttribute('deck-land')); }
|
|
102
105
|
get fanOpen() { return this.getAttribute('fan') === 'open'; }
|
|
103
106
|
get stacked() { return ![...pages, ...scrolling].includes(this.currentView); }
|
|
104
107
|
get piled() { return pileViews.includes(this.currentView); }
|
|
105
|
-
|
|
108
|
+
/** 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. */
|
|
109
|
+
get hasCards() { return this.data.some(isCard); }
|
|
110
|
+
get turnable() { return (this.piled || this.currentView === 'fan') && this.hasCards; }
|
|
106
111
|
q(selector) { return this.root.querySelector(selector); }
|
|
107
112
|
/** 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. */
|
|
108
113
|
readAddress() { try {
|
|
@@ -120,7 +125,7 @@ export class FudaCollection extends HTMLElement {
|
|
|
120
125
|
writeAddress() { if (!this.hasAttribute('address'))
|
|
121
126
|
return; clearTimeout(this.addressTimer); this.addressTimer = window.setTimeout(() => { try {
|
|
122
127
|
const url = new URL(location.href);
|
|
123
|
-
const want = { view: this.currentView === 'deck' ? null : this.currentView, fan: this.fanOpen ? 'open' : null, land: this.land === 'face-up' ? null : this.land, animate: this.getAttribute('animate') === 'off' ? 'off' : null, speed: ['slow', 'quick'].includes(this.getAttribute('speed') ?? '') ? this.getAttribute('speed') : null };
|
|
128
|
+
const want = { view: this.currentView === 'deck' ? null : this.currentView, fan: this.fanOpen ? 'open' : null, land: this.land === 'face-up' ? null : this.land, animate: this.getAttribute('animate') === 'off' ? 'off' : null, speed: ['slow', 'quick'].includes(this.getAttribute('speed') ?? '') ? this.getAttribute('speed') : null, binder: this.getAttribute('binder') === 'zip' ? 'zip' : null, cover: binderCovers.some(c => c.id === this.getAttribute('cover')) && this.getAttribute('cover') !== 'green' ? this.getAttribute('cover') : null, sheet: this.getAttribute('sheet') === 'black' ? 'black' : null, pockets: ['4', '12'].includes(this.getAttribute('pockets') ?? '') ? this.getAttribute('pockets') : null };
|
|
124
129
|
for (const [k, v] of Object.entries(want)) {
|
|
125
130
|
if (v === null)
|
|
126
131
|
url.searchParams.delete(k);
|
|
@@ -134,7 +139,12 @@ export class FudaCollection extends HTMLElement {
|
|
|
134
139
|
if (!this.data.length)
|
|
135
140
|
return;
|
|
136
141
|
const view = this.currentView;
|
|
137
|
-
if (
|
|
142
|
+
if (view === 'binder') {
|
|
143
|
+
const per = this.binderLay().per, spreads = spreadCount(sideCount(this.data.length, per)), from = spreadOf(this.index, per), to = (from + n + spreads * Math.abs(n)) % spreads;
|
|
144
|
+
this.turn = { from, to };
|
|
145
|
+
this.index = this.spreadFirst(to);
|
|
146
|
+
}
|
|
147
|
+
else if (pages.includes(view)) {
|
|
138
148
|
this.index = movePage(this.index, this.data.length, this.pageSize, n);
|
|
139
149
|
}
|
|
140
150
|
else {
|
|
@@ -144,6 +154,9 @@ export class FudaCollection extends HTMLElement {
|
|
|
144
154
|
}
|
|
145
155
|
this.render(false, { kind: 'move', dir: n > 0 ? 1 : -1 });
|
|
146
156
|
}
|
|
157
|
+
binderLay() { return binderLayout(this.getAttribute('pockets'), this.getAttribute('columns'), this.getAttribute('page-size')); }
|
|
158
|
+
/** 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. */
|
|
159
|
+
spreadFirst(spread) { const per = this.binderLay().per, sides = sideCount(this.data.length, per); return Math.min(this.data.length - 1, (2 * spread < sides ? 2 * spread : 2 * spread - 1) * per); }
|
|
147
160
|
image(c, at) { let button = document.createElement('button'); button.className = 'card'; button.dataset.i = String(at); button.setAttribute('aria-label', `Inspect ${c.name}`); let img = document.createElement('img'); img.src = c.image; img.alt = c.name; img.loading = 'lazy'; img.onerror = () => { img.replaceWith(document.createTextNode(`Image unavailable: ${c.name}`)); }; button.append(img); button.onclick = () => this.open(c); return button; }
|
|
148
161
|
open(c) { this.selected = c; this.back = false; this.renderDialog(); }
|
|
149
162
|
renderDialog() { let dlg = this.q('dialog'); dlg.replaceChildren(); let close = document.createElement('button'); close.textContent = 'Close'; close.onclick = () => dlg.close(); dlg.append(close); if (this.selected) {
|
|
@@ -187,7 +200,8 @@ export class FudaCollection extends HTMLElement {
|
|
|
187
200
|
this.removeAttribute('fan'); this.writeAddress(); } });
|
|
188
201
|
this.animateChoice = createChoice({ label: 'Animate', value: 'on', options: [{ value: 'on', label: 'On' }, { value: 'off', label: 'Off' }], onChange: value => keep('animate', value === 'off' ? 'off' : 'on') });
|
|
189
202
|
this.speedChoice = createChoice({ label: 'Speed', value: 'normal', options: [{ value: 'slow', label: 'Slow' }, { value: 'normal', label: 'Normal' }, { value: 'quick', label: 'Quick' }], onChange: value => keep('speed', value) });
|
|
190
|
-
|
|
203
|
+
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; };
|
|
204
|
+
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);
|
|
191
205
|
this.speedChoice.element.classList.add('speed');
|
|
192
206
|
this.q('.prev').onclick = () => this.move(-1);
|
|
193
207
|
this.q('.next').onclick = () => this.move(1);
|
|
@@ -222,7 +236,8 @@ export class FudaCollection extends HTMLElement {
|
|
|
222
236
|
shown.forEach((at, j) => {
|
|
223
237
|
const top = j === shown.length - 1, c = this.data[at], place = places[j];
|
|
224
238
|
const el = document.createElement('div');
|
|
225
|
-
|
|
239
|
+
const flat = !isCard(c);
|
|
240
|
+
el.className = `card${top ? ' top' : ''}${flat ? ' flat' : ''}`;
|
|
226
241
|
el.dataset.i = String(at);
|
|
227
242
|
if (place && !top) {
|
|
228
243
|
el.style.setProperty('--x', String(place.x));
|
|
@@ -249,20 +264,24 @@ export class FudaCollection extends HTMLElement {
|
|
|
249
264
|
img.loading = 'lazy';
|
|
250
265
|
img.onerror = () => { img.replaceWith(document.createTextNode(`Image unavailable: ${c.name}`)); };
|
|
251
266
|
front.append(img);
|
|
252
|
-
|
|
253
|
-
back
|
|
254
|
-
if (
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
267
|
+
turn.append(front);
|
|
268
|
+
// An object has no back to show: only a card gets the picture of its back (or the package's own).
|
|
269
|
+
if (!flat) {
|
|
270
|
+
const back = document.createElement('div');
|
|
271
|
+
back.className = 'face back';
|
|
272
|
+
if (c.backImage) {
|
|
273
|
+
const b = document.createElement('img');
|
|
274
|
+
b.src = c.backImage;
|
|
275
|
+
b.alt = '';
|
|
276
|
+
b.loading = 'lazy';
|
|
277
|
+
back.append(b);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
back.classList.add('generic-back');
|
|
281
|
+
back.textContent = 'FUDA';
|
|
282
|
+
}
|
|
283
|
+
turn.append(back);
|
|
260
284
|
}
|
|
261
|
-
else {
|
|
262
|
-
back.classList.add('generic-back');
|
|
263
|
-
back.textContent = 'FUDA';
|
|
264
|
-
}
|
|
265
|
-
turn.append(front, back);
|
|
266
285
|
fly.append(turn);
|
|
267
286
|
el.append(fly);
|
|
268
287
|
el.onclick = () => this.open(c);
|
|
@@ -342,8 +361,10 @@ export class FudaCollection extends HTMLElement {
|
|
|
342
361
|
const lead = this.fanOpen && this.fanPlaces.length > 1 ? this.fanPlaces[0] : null, shift = lead ? fanShift(lead) : { x: 0, y: 0 };
|
|
343
362
|
const away = { x: shift.x * w, y: shift.y * w }, spin = lead ? lead.angle : 0;
|
|
344
363
|
// Taking a card off an open fan starts it where the fan holds it; bringing it back ends there.
|
|
345
|
-
|
|
346
|
-
|
|
364
|
+
// 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.
|
|
365
|
+
const z = 9.6 - (Number.parseFloat(moved.style.getPropertyValue('--k')) || 0) * 0.9;
|
|
366
|
+
const from = direction === 'off' ? { x: -dx + away.x, y: -dy + away.y, z } : { x: dx - away.x, y: dy - away.y, z };
|
|
367
|
+
flight(fly, turn, from, moved.classList.contains('flat') ? 'face-up' : this.land, direction, ms, direction === 'off' ? spin : -spin);
|
|
347
368
|
}
|
|
348
369
|
renderFan(v) { this.renderDeck(v, true); }
|
|
349
370
|
/** Where every card is on screen now, by data index. */
|
|
@@ -393,6 +414,75 @@ export class FudaCollection extends HTMLElement {
|
|
|
393
414
|
old.animate([{ opacity: 1, translate: '0 0', offset: 0 }, { opacity: 0, translate: `${-how.dir * 60}px 0`, offset: 1 }], { duration: ms * 0.8, easing: 'ease-in' }).finished.then(done, done);
|
|
394
415
|
}
|
|
395
416
|
}
|
|
417
|
+
syncBinder(view) {
|
|
418
|
+
const show = view === 'binder', cur = (attr, dflt, ok) => { const v = this.getAttribute(attr); return v && ok.includes(v) ? v : dflt; };
|
|
419
|
+
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']) };
|
|
420
|
+
for (const [k, h] of Object.entries(this.binderChoices)) {
|
|
421
|
+
h.hidden = !show;
|
|
422
|
+
h.set(vals[k]);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
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}`; }
|
|
426
|
+
/** 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. */
|
|
427
|
+
renderBinder(v, t) {
|
|
428
|
+
const layout = this.binderLay(), n = this.data.length, sides = sideCount(n, layout.per), spread = spreadOf(this.index, layout.per);
|
|
429
|
+
const sheet = this.getAttribute('sheet') === 'black' ? 'black' : 'clear', zip = this.getAttribute('binder') === 'zip', cover = binderCovers.find(c => c.id === this.getAttribute('cover')) ?? binderCovers[0];
|
|
430
|
+
v.classList.add('binder');
|
|
431
|
+
v.style.setProperty('--cover', cover.color);
|
|
432
|
+
const pocket = (index, live) => { const c = this.data[index], el = document.createElement('div'); el.className = 'pocket'; if (live)
|
|
433
|
+
el.append(this.image(c, index));
|
|
434
|
+
else {
|
|
435
|
+
const img = document.createElement('img');
|
|
436
|
+
img.src = c.image;
|
|
437
|
+
img.alt = '';
|
|
438
|
+
img.style.cssText = 'width:86%;height:92%;object-fit:contain;border-radius:3%;box-shadow:0 2px 5px #0007';
|
|
439
|
+
el.append(img);
|
|
440
|
+
} return el; };
|
|
441
|
+
const [L, R] = spreadSides(spread, sides), turn = this.turn;
|
|
442
|
+
this.turn = null;
|
|
443
|
+
const flat = turn && t.on && Math.abs(turn.to - turn.from) === 1 ? turn : null;
|
|
444
|
+
const [oldL, oldR] = flat ? spreadSides(flat.from, sides) : [L, R], [newL, newR] = flat ? spreadSides(flat.to, sides) : [L, R];
|
|
445
|
+
const forward = !!flat && flat.to > flat.from;
|
|
446
|
+
const book = document.createElement('div');
|
|
447
|
+
book.className = `book ${zip ? 'b-zip' : 'b-ring'}`;
|
|
448
|
+
const inside = document.createElement('div');
|
|
449
|
+
inside.className = 'inside';
|
|
450
|
+
const left = document.createElement('div'), right = document.createElement('div');
|
|
451
|
+
left.className = 'half';
|
|
452
|
+
right.className = 'half';
|
|
453
|
+
const put = (half, side, where) => { half.replaceChildren(); if (side >= 0)
|
|
454
|
+
half.append(buildSide(side, where, sheet, layout, n, pocket)); };
|
|
455
|
+
// 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.
|
|
456
|
+
put(left, flat ? (forward ? oldL : newL) : L, 'l');
|
|
457
|
+
put(right, flat ? (forward ? newR : oldR) : R, 'r');
|
|
458
|
+
const spine = document.createElement('div');
|
|
459
|
+
spine.className = 'spine';
|
|
460
|
+
for (const y of [18, 50, 82]) {
|
|
461
|
+
const ring = document.createElement('i');
|
|
462
|
+
ring.className = 'ring';
|
|
463
|
+
ring.style.top = `${y}%`;
|
|
464
|
+
spine.append(ring);
|
|
465
|
+
}
|
|
466
|
+
inside.append(left, right, spine);
|
|
467
|
+
const tab = document.createElement('i');
|
|
468
|
+
tab.className = 'tab';
|
|
469
|
+
book.append(inside, tab);
|
|
470
|
+
v.append(book);
|
|
471
|
+
if (flat) {
|
|
472
|
+
const w = 300, strip = 34, { leaf, slices } = buildLeaf(forward ? oldR : newR, forward ? newL : oldL, sheet, layout, n, pocket, w, strip);
|
|
473
|
+
inside.append(leaf);
|
|
474
|
+
const ms = Math.round(t.ms * 1.4), ease = 'cubic-bezier(.45,.05,.3,1)', a = forward ? [0, -180] : [-180, 0];
|
|
475
|
+
leaf.style.transform = `rotateY(${a[1]}deg)`;
|
|
476
|
+
const swing = leaf.animate([{ transform: `rotateY(${a[0]}deg)` }, { transform: `rotateY(${a[1]}deg)` }], { duration: ms, easing: ease, fill: 'forwards' });
|
|
477
|
+
// Each slice leans on the one before it, so the sheet bends as it swings (the free edge trails) and straightens at the end.
|
|
478
|
+
const bend = forward ? 8 : -8;
|
|
479
|
+
slices.forEach((s, k) => { if (k)
|
|
480
|
+
s.animate([{ transform: 'rotateY(0deg)' }, { transform: `rotateY(${bend}deg)`, offset: .5 }, { transform: 'rotateY(0deg)' }], { duration: ms, easing: ease }); });
|
|
481
|
+
const finish = () => { if (!leaf.isConnected)
|
|
482
|
+
return; put(left, newL, 'l'); put(right, newR, 'r'); leaf.remove(); };
|
|
483
|
+
swing.finished.then(finish, finish);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
396
486
|
render(reset = false, how) {
|
|
397
487
|
if (!this.isConnected)
|
|
398
488
|
return;
|
|
@@ -400,13 +490,14 @@ export class FudaCollection extends HTMLElement {
|
|
|
400
490
|
let view = this.currentView, stage = this.q('.stage'), v = this.q('.v');
|
|
401
491
|
const t = this.timeVars(), playing = t.on && how && this.data.length > 0;
|
|
402
492
|
const before = playing ? this.snapshot(v) : new Map(), left = playing && how.kind === 'move' && gliding.includes(view) ? Array.from(v.querySelectorAll('.card:not(.ghost)')) : [];
|
|
493
|
+
this.syncBinder(view);
|
|
403
494
|
this.tiles.set(view);
|
|
404
495
|
this.landing.set(this.land);
|
|
405
496
|
this.fanChoice.set(this.fanOpen ? 'open' : 'closed');
|
|
406
497
|
this.syncChoices();
|
|
407
|
-
this.landing.hidden = !this.piled;
|
|
498
|
+
this.landing.hidden = !this.piled || !this.hasCards;
|
|
408
499
|
this.fanChoice.hidden = !(this.piled || view === 'fan');
|
|
409
|
-
this.q('.count').textContent = this.data.length ? (pages.includes(view) ? `Page ${Math.floor(this.index / this.pageSize) + 1} / ${Math.ceil(this.data.length / this.pageSize)}` : `${this.index + 1} / ${this.data.length}`) : 'No cards';
|
|
500
|
+
this.q('.count').textContent = this.data.length ? (view === 'binder' ? this.binderCount() : pages.includes(view) ? `Page ${Math.floor(this.index / this.pageSize) + 1} / ${Math.ceil(this.data.length / this.pageSize)}` : `${this.index + 1} / ${this.data.length}`) : 'No cards';
|
|
410
501
|
for (const selector of ['.prev', '.next'])
|
|
411
502
|
this.q(selector).disabled = !this.data.length;
|
|
412
503
|
const random = view === 'random';
|
|
@@ -421,8 +512,8 @@ export class FudaCollection extends HTMLElement {
|
|
|
421
512
|
for (const k of ['--fl', '--fr', '--ft', '--fb'])
|
|
422
513
|
v.style.removeProperty(k);
|
|
423
514
|
this.zoom.minOpen = scrolling.includes(view) ? .5 : 0;
|
|
424
|
-
this.zoom.setTurnable(this.turnable && this.data.length > 0);
|
|
425
|
-
this.zoom.items = this.piled || view === 'fan' ? '.extent' : '.card,.slot';
|
|
515
|
+
this.zoom.setTurnable(this.turnable && this.data.length > 0, this.data.length > 0 && !this.hasCards);
|
|
516
|
+
this.zoom.items = this.piled || view === 'fan' ? '.extent' : view === 'binder' ? '.book' : '.card,.slot';
|
|
426
517
|
if (!this.data.length) {
|
|
427
518
|
v.innerHTML = '<p class="empty">No cards in this collection.</p>';
|
|
428
519
|
}
|
|
@@ -430,6 +521,8 @@ export class FudaCollection extends HTMLElement {
|
|
|
430
521
|
this.renderDeck(v);
|
|
431
522
|
else if (view === 'fan')
|
|
432
523
|
this.renderFan(v);
|
|
524
|
+
else if (view === 'binder')
|
|
525
|
+
this.renderBinder(v, t);
|
|
433
526
|
else if (pages.includes(view)) {
|
|
434
527
|
v.classList.add('grid', view);
|
|
435
528
|
const columns = Math.min(10, Math.max(1, Math.floor(Number(this.getAttribute('columns')) || 3)));
|
package/dist/collection.d.ts
CHANGED
|
@@ -12,17 +12,31 @@ export interface CollectionMetadata {
|
|
|
12
12
|
quantity?: number;
|
|
13
13
|
notes?: string;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* What an item is. A `card` (the default, so every collection written before this field existed is still cards) is a flat, thin card with a back: it
|
|
17
|
+
* 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
|
+
* 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
|
+
* object would be a third kind; none can be given as an image yet.)
|
|
20
|
+
*/
|
|
21
|
+
export type CollectionKind = 'card' | 'object';
|
|
22
|
+
export declare const collectionKinds: ReadonlyArray<CollectionKind>;
|
|
15
23
|
export interface CollectionCard {
|
|
16
24
|
id: string;
|
|
17
25
|
name: string;
|
|
18
26
|
image: string;
|
|
19
27
|
backImage?: string;
|
|
28
|
+
kind?: CollectionKind;
|
|
20
29
|
metadata?: CollectionMetadata;
|
|
21
30
|
}
|
|
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. */
|
|
32
|
+
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`. */
|
|
22
34
|
export declare const collectionViews: ReadonlyArray<{
|
|
23
35
|
id: CollectionView;
|
|
24
36
|
label: string;
|
|
25
37
|
}>;
|
|
38
|
+
/** Display names that earlier versions accepted and that now open another display, so a page that sets them keeps working. */
|
|
39
|
+
export declare const collectionViewAliases: Readonly<Record<string, CollectionView>>;
|
|
26
40
|
export declare function parseCollection(value: unknown): CollectionCard[];
|
|
27
41
|
/** Choose a matching card, avoiding the current card when another match exists. */
|
|
28
42
|
export declare function randomDrawIndex(cards: CollectionCard[], current: number, filter: string, random?: () => number): number | null;
|
package/dist/collection.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
export { fanLayout, deckLandings, normalizeLanding } from './pile.js';
|
|
2
|
+
export const collectionKinds = ['card', 'object'];
|
|
3
|
+
/** 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. */
|
|
4
|
+
export const isCard = (card) => card.kind !== 'object';
|
|
5
|
+
/** 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`. */
|
|
2
6
|
export const collectionViews = [
|
|
3
7
|
{ id: 'deck', label: 'Overlapping Deck' }, { id: 'rolodex', label: 'Rolodex' }, { id: 'binder', label: 'Binder Pages' },
|
|
4
|
-
{ id: 'case', label: 'Convention Display Case' }, { id: '
|
|
5
|
-
{ id: 'story', label: 'Vertical Story Scroll' }, { id: 'wall', label: 'Sliding Gallery Wall' },
|
|
6
|
-
{ id: 'spotlight', label: 'Spotlight Carousel' }, { id: 'atlas', label: '
|
|
8
|
+
{ id: 'case', label: 'Convention Display Case' }, { id: 'random', label: 'Random Draw' },
|
|
9
|
+
{ id: 'story', label: 'Vertical Story Scroll' }, { id: 'wall', label: 'Sliding Gallery Wall' },
|
|
10
|
+
{ id: 'spotlight', label: 'Spotlight Carousel' }, { id: 'atlas', label: 'Card Table' }, { id: 'fan', label: 'Fan of Cards' }
|
|
7
11
|
];
|
|
12
|
+
/** Display names that earlier versions accepted and that now open another display, so a page that sets them keeps working. */
|
|
13
|
+
export const collectionViewAliases = { jukebox: 'deck', tower: 'deck' };
|
|
8
14
|
export function parseCollection(value) {
|
|
9
15
|
if (value && typeof value === 'object' && !Array.isArray(value) && 'cards' in value)
|
|
10
16
|
value = value.cards;
|
|
@@ -23,6 +29,8 @@ export function parseCollection(value) {
|
|
|
23
29
|
ids.add(id);
|
|
24
30
|
if (c.backImage !== undefined && typeof c.backImage !== 'string')
|
|
25
31
|
throw new Error(`Card ${i + 1} backImage must be a URL.`);
|
|
32
|
+
if (c.kind !== undefined && !collectionKinds.includes(c.kind))
|
|
33
|
+
throw new Error(`Card ${i + 1} kind must be "card" or "object".`);
|
|
26
34
|
let metadata;
|
|
27
35
|
if (c.metadata !== undefined) {
|
|
28
36
|
if (!c.metadata || typeof c.metadata !== 'object' || Array.isArray(c.metadata))
|
|
@@ -42,7 +50,7 @@ export function parseCollection(value) {
|
|
|
42
50
|
if (typeof m[key] === 'number')
|
|
43
51
|
metadata[key] = m[key];
|
|
44
52
|
}
|
|
45
|
-
return { id, name: c.name, image: c.image, ...(c.backImage ? { backImage: c.backImage } : {}), ...(metadata ? { metadata } : {}) };
|
|
53
|
+
return { id, name: c.name, image: c.image, ...(c.backImage ? { backImage: c.backImage } : {}), ...(c.kind === 'object' ? { kind: 'object' } : {}), ...(metadata ? { metadata } : {}) };
|
|
46
54
|
});
|
|
47
55
|
}
|
|
48
56
|
/** Choose a matching card, avoiding the current card when another match exists. */
|
package/dist/pile.d.ts
CHANGED
|
@@ -65,6 +65,11 @@ export declare function timing(host: Element, dflt: boolean): Timing;
|
|
|
65
65
|
/**
|
|
66
66
|
* 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
|
|
67
67
|
* 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.
|
|
68
|
+
*
|
|
69
|
+
* The card must never pass through another card: every card of a 3D scene is drawn by its depth, so a card that turns while it is level
|
|
70
|
+
* with the piles is cut by them and shows the cards behind it. So the card starts above the pile it leaves (`from.z`, in pixels, is how
|
|
71
|
+
* much higher than its landing place that is), stays above both piles all the way, and while it turns it is lifted by half its width times the
|
|
72
|
+
* sine of the turn, which is exactly what keeps its lowest corner above the cards it passes. It is level again, and down on the pile, at the end.
|
|
68
73
|
*/
|
|
69
74
|
export declare function flight(fly: HTMLElement, turn: HTMLElement, from: {
|
|
70
75
|
x: number;
|
package/dist/pile.js
CHANGED
|
@@ -93,15 +93,28 @@ export function timing(host, dflt) {
|
|
|
93
93
|
/**
|
|
94
94
|
* 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
|
|
95
95
|
* 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.
|
|
96
|
+
*
|
|
97
|
+
* The card must never pass through another card: every card of a 3D scene is drawn by its depth, so a card that turns while it is level
|
|
98
|
+
* with the piles is cut by them and shows the cards behind it. So the card starts above the pile it leaves (`from.z`, in pixels, is how
|
|
99
|
+
* much higher than its landing place that is), stays above both piles all the way, and while it turns it is lifted by half its width times the
|
|
100
|
+
* sine of the turn, which is exactly what keeps its lowest corner above the cards it passes. It is level again, and down on the pile, at the end.
|
|
96
101
|
*/
|
|
97
102
|
export function flight(fly, turn, from, land, direction, ms, spin = 0) {
|
|
98
103
|
const options = { duration: ms, easing: 'cubic-bezier(.3,.1,.2,1)' };
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const turns = land === 'face-down', half = (fly.offsetWidth || 200) / 2, z0 = from.z ?? 0, STEPS = 16, MARGIN = 1.5;
|
|
105
|
+
const fly3d = [], turn3d = [];
|
|
106
|
+
for (let k = 0; k <= STEPS; k++) {
|
|
107
|
+
const p = k / STEPS, q = 1 - p, arc = Math.sin(Math.PI * p);
|
|
108
|
+
// Over the pile it leaves the card stays as high as that pile until half way, then comes down to where it lands.
|
|
109
|
+
const base = Math.max(0, z0 * Math.min(1, 2 * q)) + MARGIN * arc;
|
|
110
|
+
const lift = (turns ? half + 6 : 80) * arc;
|
|
111
|
+
const z = k === STEPS ? 0 : base + lift;
|
|
112
|
+
fly3d.push({ offset: p, transform: `translate3d(${from.x * q}px,${from.y * q - 136 * p * q}px,${z}px) rotate(${spin * q}deg) scale(${1 + 0.07 * arc})` });
|
|
113
|
+
if (turns)
|
|
114
|
+
turn3d.push({ offset: p, transform: `rotateY(${(direction === 'off' ? p : q) * 180}deg)` });
|
|
115
|
+
}
|
|
116
|
+
const out = [fly.animate(fly3d, options)];
|
|
117
|
+
if (turns)
|
|
118
|
+
out.push(turn.animate(turn3d, options));
|
|
106
119
|
return out;
|
|
107
120
|
}
|
package/dist/zoom.d.ts
CHANGED
|
@@ -35,8 +35,8 @@ export interface ZoomView {
|
|
|
35
35
|
/** Go back to the opening view. */
|
|
36
36
|
reset(): void;
|
|
37
37
|
zoomed(): boolean;
|
|
38
|
-
/** Let the reader turn the view in 3D (angle, tilt, Auto-turn) or only zoom and move it. Off by default. */
|
|
39
|
-
setTurnable(on: boolean): void;
|
|
38
|
+
/** Let the reader turn the view in 3D (angle, tilt, Auto-turn) or only zoom and move it. Off by default. `never` says nothing in the view can turn, so an angle in the address is dropped too. */
|
|
39
|
+
setTurnable(on: boolean, never?: boolean): void;
|
|
40
40
|
/** The selector of the items that must be visible at Fit. It can change with the display. */
|
|
41
41
|
items: string;
|
|
42
42
|
/** Run a change that moves the view (a refit, a pan) so that the view glides to its new place over `ms` instead of jumping; 0 jumps. */
|
package/dist/zoom.js
CHANGED
|
@@ -59,11 +59,18 @@ export function zoomView(stage, view, options = {}) {
|
|
|
59
59
|
const scale = fit * state.zoom;
|
|
60
60
|
view.style.transformOrigin = `${box.cx}px ${box.cy}px`;
|
|
61
61
|
const turn = turnable ? ` rotateX(${state.tilt ?? 0}deg) rotateY(${state.yaw ?? 0}deg)` : '';
|
|
62
|
+
// The turn, for the items that must stay square to the reader (they turn the other way by this much).
|
|
63
|
+
view.style.setProperty('--fuda-yaw', turnable ? String(state.yaw ?? 0) : '0');
|
|
64
|
+
view.style.setProperty('--fuda-tilt', turnable ? String(state.tilt ?? 0) : '0');
|
|
62
65
|
view.style.transform = `translate(${box.w / 2 - box.cx + state.panX}px,${box.h / 2 - box.cy + state.panY}px) scale(${scale})${turn}`;
|
|
63
66
|
}
|
|
64
|
-
function setTurnable(on) {
|
|
65
|
-
|
|
67
|
+
function setTurnable(on, never = false) {
|
|
68
|
+
// A view whose items can never turn (`never`) keeps no angle either, whatever the address says.
|
|
69
|
+
if (on === turnable) {
|
|
70
|
+
if (never && !on && (controls.state.yaw || controls.state.tilt))
|
|
71
|
+
controls.set({ yaw: 0, tilt: 0 });
|
|
66
72
|
return;
|
|
73
|
+
}
|
|
67
74
|
turnable = on;
|
|
68
75
|
if (!on)
|
|
69
76
|
controls.set({ yaw: 0, tilt: 0 });
|
|
@@ -11,6 +11,15 @@ Fuda supplies reusable frames for a caller's cards and reusable ways to display
|
|
|
11
11
|
- **Animate (0.7.0).** `animate="off"` and `speed` for every move: the fan, a card taken off, Next in the carousels, a binder page turn, a switch of display, a pan to the card in the wall, story and atlas. On when the attribute is missing; reduced motion always wins. One shared timing, CSS transforms and one-shot animations, nothing running when idle. Moves with it on and off end in exactly the same place.
|
|
12
12
|
- Not done: dealing more than one card at a time, a pile that fills up with the whole discard history (the pile shows the last ten), wear on the cards of a fan.
|
|
13
13
|
|
|
14
|
+
## Items that are not cards (0.9.0)
|
|
15
|
+
|
|
16
|
+
An item says what it is with `kind` (`"card"`, the default, or `"object"`; see `docs/collection-input.md`). A card is flat and thin with a back, so everything that turns it, shows its back or lands it turned over applies to it, exactly as before. An object (a picture of a games console, say) has no back and no thickness, so none of that applies:
|
|
17
|
+
|
|
18
|
+
- a collection with no card in it offers no Angle, Tilt, Auto-turn or Front, ignores `yaw` and `tilt` in the address and in the controls, and does not offer the "turned over" landing;
|
|
19
|
+
- in a mixed collection the controls are there for the cards; each object stays square to the reader (it turns the other way by as much as the view turns) and lands facing up whatever `deck-land` says;
|
|
20
|
+
- a flight never turns an object over, and no card back is drawn for it;
|
|
21
|
+
- fanning open and taking one off a pile are kept for objects: a fan is a flat layout (each item leans in the plane of the page, nothing turns over) and taking one off only moves it across, so both stay true to a console on a table.
|
|
22
|
+
|
|
14
23
|
## Zoom, Fit and move (every view)
|
|
15
24
|
|
|
16
25
|
Every view has the shared view controls (`@johnmorrisdotca/kazoku-ui`) on the view: zoom out, 2×, zoom in, **Fit**, and, zoomed in, an arrow pad. Ctrl or Command with the wheel, a trackpad pinch and a two-finger pinch zoom about the pointer; zoomed in, a drag or the wheel moves the view. The views are flat, so none turns in 3D and the angle, tilt and auto-turn controls are hidden.
|
|
@@ -20,10 +29,30 @@ Every view has the shared view controls (`@johnmorrisdotca/kazoku-ui`) on the vi
|
|
|
20
29
|
- Changing the card, the page or the view type is separate from zoom: paging keeps the zoom and the position, zooming keeps the page, and choosing another view type starts that view at its opening size.
|
|
21
30
|
- The controls sit under the view. Keep what is above the viewer short so they are on the first screen; `--fuda-stage-height` sets the view's height.
|
|
22
31
|
|
|
32
|
+
## Real-life audit (0.8.0)
|
|
33
|
+
|
|
34
|
+
Every display and option against how real cards are kept and handled: **real**, **fine as a demo idea** (no real counterpart, but it helps a reader see or reach cards on a screen) or **wrong** (fixed or removed).
|
|
35
|
+
|
|
36
|
+
Displays
|
|
37
|
+
- Overlapping Deck: real (a deck on a table; a card comes off it). Kept; Random Draw: real (draw a card from a shuffled deck). Kept. Fan of Cards: real (a hand). Kept.
|
|
38
|
+
- Binder Pages: real (nine-pocket sheets in a ring or zip binder), the old drawing was **wrong** (a flat tilted grid with no pockets, holes or binder). Rebuilt in 0.8.0.
|
|
39
|
+
- Convention Display Case: real (cards on risers behind glass), the old drawing was weak (tilted pictures on a gradient). Kept, with a wooden frame, a glass lid and a ledge under each card; still a demo, not a full riser model.
|
|
40
|
+
- Rolodex: a real rotary card file, but ours is three cards leaning like a hand, not a wheel. Fine as a demo idea; kept.
|
|
41
|
+
- Sliding Gallery Wall: real (cards hung in a row on a wall). Spotlight Carousel: a lit stand with neighbours, fine as a demo idea. Vertical Story Scroll: no physical counterpart (a phone feed of cards), fine as a demo idea and useful on a phone.
|
|
42
|
+
- Infinite Card Atlas: "infinite" was **wrong** (the collection is finite); the real thing is all the cards laid out on a table. Kept and renamed **Card Table** (`view="atlas"` unchanged).
|
|
43
|
+
- Jukebox Carousel and Flip Tower: **wrong**. A jukebox plays records, not cards; nothing real is a "flip tower"; both drew exactly the deck's pile of three cards. Removed from the demo and the buttons; `view="jukebox"` and `view="tower"` still open the deck (`collectionViewAliases`).
|
|
44
|
+
|
|
45
|
+
Options
|
|
46
|
+
- Fan open and closed, a card taken off still facing up or turned over (sideways), deck messiness and seed, binder ring or zip, plain covers, clear or black sheets, 4, 9 or 12 pockets, material, thickness, stack counts, wear, foil or matt finish: **real**.
|
|
47
|
+
- "Upside down" landing: **wrong** (nobody turns a card half way round in its plane); removed in 0.6.1, the value `upside-down` still means turned over.
|
|
48
|
+
- Animate, Speed, zoom, Fit, move, the address, Image motion (a slow pan over a tall picture) and Autoplay: no real counterpart, **fine as demo ideas**.
|
|
49
|
+
- Card rotation (a turntable) and its speed and direction: real for a display stand; spin around the bottom corner: no real counterpart, kept because John asked for it, **fine as a demo idea**.
|
|
50
|
+
- Card style (classic, silver sport, cosmic violet): fine as frames, not a real product.
|
|
51
|
+
|
|
23
52
|
## Binder and booklet
|
|
24
53
|
|
|
25
|
-
-
|
|
26
|
-
-
|
|
54
|
+
- Done in 0.8.0: `view="binder"` is a ring or zip binder open on two facing sheets of 4, 9 (the default, three by three) or 12 clear plastic pockets, on a clear or black sheet with a punched-hole strip against the rings, a plain cover colour, and a sideways page turn about the spine that bends the leaf and shows its back pockets. The older `page-size` and `columns` still set the grid.
|
|
55
|
+
- Not done: booklet and album (side-loading) pages, a binder with more than one section.
|
|
27
56
|
- Multiple named collections or binders, with their own cards, ordering, and optional titles and covers.
|
|
28
57
|
- Page controls that work with keyboard and touch, with a reduced-motion alternative.
|
|
29
58
|
- Present each card's front and back, and preserve interaction with any 3D viewer in the card window. Page turning, card flipping, and rotating an object must be distinct actions.
|
|
@@ -42,12 +71,9 @@ Every view has the shared view controls (`@johnmorrisdotca/kazoku-ui`) on the vi
|
|
|
42
71
|
- Support a responsive alternative for small displays and large collections; avoid rendering a separate active 3D viewer per card at once. The host controls the collection and card content.
|
|
43
72
|
- Research: [angled modular display risers](https://boxboy.co/products/modular-display-risers), [staggered rear rows](https://dhoptcg.com/?product=glass-display-shelves), and [a 13-column, 7-row cabinet](https://www.jz-shop.com.tw/en/graded-card-display-case-slim). These examples show different capacities, so dimensions and overlap should remain adjustable.
|
|
44
73
|
|
|
45
|
-
## Jukebox-style display
|
|
74
|
+
## Jukebox-style display (dropped in 0.8.0)
|
|
46
75
|
|
|
47
|
-
|
|
48
|
-
- Provide a clear way back to browsing and preserve the selected card and collection position.
|
|
49
|
-
- Keep card flip and interactive content controls separate from the device navigation; make browse and selection usable by keyboard, touch, and pointer.
|
|
50
|
-
- Allow the host to configure device styling and the cards supplied. Support a reduced-motion alternative to mechanical animations.
|
|
76
|
+
A jukebox plays records, not cards, and the display drew the deck's pile of three cards, so it was removed (see the real-life audit above). `view="jukebox"` still opens the deck.
|
|
51
77
|
|
|
52
78
|
## Feeling lucky
|
|
53
79
|
|
package/docs/collection-input.md
CHANGED
|
@@ -22,12 +22,14 @@ An example supported collection format:
|
|
|
22
22
|
"name": "Starship Block 3",
|
|
23
23
|
"image": "https://example.com/starship-front.jpg",
|
|
24
24
|
"backImage": "https://example.com/starship-back.jpg",
|
|
25
|
+
"kind": "card",
|
|
25
26
|
"metadata": { "year": 2026, "number": "001" }
|
|
26
27
|
}
|
|
27
28
|
]
|
|
28
29
|
}
|
|
29
30
|
```
|
|
30
31
|
|
|
32
|
+
- **What an item is.** `kind` is `"card"` (the default: a collection written without it is all cards, as before) or `"object"`. A card is flat and thin with a back, so it 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 (a games console, a trophy): it has no back and no thickness, so it never turns over, is never seen edge-on or from behind, and always lands facing up. No angle, tilt, Auto-turn or "turned over" landing is offered for a collection with no card in it, and an angle in the address is dropped. In a mixed collection the controls are there for the cards, and the objects stay square to the reader. Objects can still be fanned open (a flat layout) and taken off a pile (they fly across and land facing up). A real 3D object would be a third kind, once an item can carry one.
|
|
31
33
|
- Represent photographed or scanned cards as full-card front and back images, so collectors can display what they already own. Alternatively, use a Fuda frame with a separate image or host-provided interactive artwork in its window.
|
|
32
34
|
- Keep collector details optional: set, year, card number, edition, condition, grade, quantity, notes, and other metadata. Do not assume every item has a market price or grade.
|
|
33
35
|
- Provide stable IDs for selection and navigation; validate malformed input and report errors without discarding valid cards.
|