@johnmorrisdotca/fuda-cards 0.7.0 → 0.8.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 +115 -0
- package/dist/collection-element.d.ts +9 -0
- package/dist/collection-element.js +98 -14
- package/dist/collection.d.ts +3 -0
- package/dist/collection.js +6 -3
- package/docs/collection-displays.md +22 -2
- 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? }`. 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`, `
|
|
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? }`. 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;backface-visibility:hidden;-webkit-backface-visibility:hidden;overflow:hidden}.slice>.b{transform:rotateY(180deg)}\n.slice .sf{position:absolute;top:0;height:100%}\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,115 @@
|
|
|
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;backface-visibility:hidden;-webkit-backface-visibility:hidden;overflow:hidden}.slice>.b{transform:rotateY(180deg)}
|
|
51
|
+
.slice .sf{position:absolute;top:0;height:100%}
|
|
52
|
+
`;
|
|
53
|
+
/** The cards a side holds, as indexes into the collection (or -1 for an empty pocket), in reading order. */
|
|
54
|
+
export function sideCards(side, layout, total) {
|
|
55
|
+
return Array.from({ length: layout.per }, (_, k) => (side * layout.per + k < total ? side * layout.per + k : -1));
|
|
56
|
+
}
|
|
57
|
+
/** 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. */
|
|
58
|
+
export function buildSide(side, where, sheet, layout, total, pocket, live = true) {
|
|
59
|
+
const el = document.createElement('div');
|
|
60
|
+
el.className = `side ${where} ${sheet}`;
|
|
61
|
+
el.dataset.side = String(side);
|
|
62
|
+
el.style.setProperty('--cols', String(layout.cols));
|
|
63
|
+
el.style.setProperty('--rows', String(layout.rows));
|
|
64
|
+
const holes = document.createElement('div');
|
|
65
|
+
holes.className = 'holes';
|
|
66
|
+
holes.innerHTML = '<i></i>'.repeat(9);
|
|
67
|
+
el.append(holes);
|
|
68
|
+
for (const index of sideCards(side, layout, total))
|
|
69
|
+
el.append(index < 0 ? Object.assign(document.createElement('div'), { className: 'pocket empty' }) : pocket(index, live));
|
|
70
|
+
return el;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 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
|
|
74
|
+
* 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
|
|
75
|
+
* front and the matching column of the back side on its back. Returns the leaf and its slices.
|
|
76
|
+
*/
|
|
77
|
+
export function buildLeaf(front, back, sheet, layout, total, pocket, widthPx, strip) {
|
|
78
|
+
const leaf = document.createElement('div');
|
|
79
|
+
leaf.className = 'leaf';
|
|
80
|
+
const faces = (side, where) => side < 0 ? null : buildSide(side, where, sheet, layout, total, pocket, false);
|
|
81
|
+
const rightSide = faces(front, 'r'), leftSide = faces(back, 'l');
|
|
82
|
+
const widths = [strip + 6, ...Array.from({ length: layout.cols }, () => (widthPx - strip - 6) / layout.cols)];
|
|
83
|
+
const slices = [];
|
|
84
|
+
let parent = leaf, offset = 0;
|
|
85
|
+
widths.forEach((w, k) => {
|
|
86
|
+
const slice = document.createElement('div');
|
|
87
|
+
slice.className = 'slice';
|
|
88
|
+
slice.style.width = `${w}px`;
|
|
89
|
+
slice.style.left = k === 0 ? '0' : '100%';
|
|
90
|
+
const f = document.createElement('div'), b = document.createElement('div');
|
|
91
|
+
f.className = 'f';
|
|
92
|
+
b.className = 'b';
|
|
93
|
+
// The whole side is placed inside each slice's face and shifted so that this slice shows its own part of it.
|
|
94
|
+
if (rightSide) {
|
|
95
|
+
const copy = rightSide.cloneNode(true);
|
|
96
|
+
copy.classList.add('sf');
|
|
97
|
+
copy.style.width = `${widthPx}px`;
|
|
98
|
+
copy.style.left = `${-offset}px`;
|
|
99
|
+
f.append(copy);
|
|
100
|
+
}
|
|
101
|
+
if (leftSide) {
|
|
102
|
+
const copy = leftSide.cloneNode(true);
|
|
103
|
+
copy.classList.add('sf');
|
|
104
|
+
copy.style.width = `${widthPx}px`;
|
|
105
|
+
copy.style.left = `${-(widthPx - offset - w)}px`;
|
|
106
|
+
b.append(copy);
|
|
107
|
+
}
|
|
108
|
+
slice.append(f, b);
|
|
109
|
+
parent.append(slice);
|
|
110
|
+
parent = slice;
|
|
111
|
+
offset += w;
|
|
112
|
+
slices.push(slice);
|
|
113
|
+
});
|
|
114
|
+
return { leaf, slices };
|
|
115
|
+
}
|
|
@@ -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;
|
|
@@ -36,6 +38,9 @@ export declare class FudaCollection extends HTMLElement {
|
|
|
36
38
|
private readAddress;
|
|
37
39
|
private writeAddress;
|
|
38
40
|
private move;
|
|
41
|
+
private binderLay;
|
|
42
|
+
/** 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. */
|
|
43
|
+
private spreadFirst;
|
|
39
44
|
private image;
|
|
40
45
|
private open;
|
|
41
46
|
private renderDialog;
|
|
@@ -62,5 +67,9 @@ export declare class FudaCollection extends HTMLElement {
|
|
|
62
67
|
private enter;
|
|
63
68
|
/** 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
69
|
private play;
|
|
70
|
+
private syncBinder;
|
|
71
|
+
private binderCount;
|
|
72
|
+
/** 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. */
|
|
73
|
+
private renderBinder;
|
|
65
74
|
private render;
|
|
66
75
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { collectionViews, parseCollection, randomDrawIndex, movePage } from './collection.js';
|
|
1
|
+
import { collectionViewAliases, collectionViews, 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)}
|
|
@@ -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,7 +99,7 @@ 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'; }
|
|
@@ -120,7 +123,7 @@ export class FudaCollection extends HTMLElement {
|
|
|
120
123
|
writeAddress() { if (!this.hasAttribute('address'))
|
|
121
124
|
return; clearTimeout(this.addressTimer); this.addressTimer = window.setTimeout(() => { try {
|
|
122
125
|
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 };
|
|
126
|
+
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
127
|
for (const [k, v] of Object.entries(want)) {
|
|
125
128
|
if (v === null)
|
|
126
129
|
url.searchParams.delete(k);
|
|
@@ -134,7 +137,12 @@ export class FudaCollection extends HTMLElement {
|
|
|
134
137
|
if (!this.data.length)
|
|
135
138
|
return;
|
|
136
139
|
const view = this.currentView;
|
|
137
|
-
if (
|
|
140
|
+
if (view === 'binder') {
|
|
141
|
+
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;
|
|
142
|
+
this.turn = { from, to };
|
|
143
|
+
this.index = this.spreadFirst(to);
|
|
144
|
+
}
|
|
145
|
+
else if (pages.includes(view)) {
|
|
138
146
|
this.index = movePage(this.index, this.data.length, this.pageSize, n);
|
|
139
147
|
}
|
|
140
148
|
else {
|
|
@@ -144,6 +152,9 @@ export class FudaCollection extends HTMLElement {
|
|
|
144
152
|
}
|
|
145
153
|
this.render(false, { kind: 'move', dir: n > 0 ? 1 : -1 });
|
|
146
154
|
}
|
|
155
|
+
binderLay() { return binderLayout(this.getAttribute('pockets'), this.getAttribute('columns'), this.getAttribute('page-size')); }
|
|
156
|
+
/** 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. */
|
|
157
|
+
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
158
|
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
159
|
open(c) { this.selected = c; this.back = false; this.renderDialog(); }
|
|
149
160
|
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 +198,8 @@ export class FudaCollection extends HTMLElement {
|
|
|
187
198
|
this.removeAttribute('fan'); this.writeAddress(); } });
|
|
188
199
|
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
200
|
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
|
-
|
|
201
|
+
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; };
|
|
202
|
+
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
203
|
this.speedChoice.element.classList.add('speed');
|
|
192
204
|
this.q('.prev').onclick = () => this.move(-1);
|
|
193
205
|
this.q('.next').onclick = () => this.move(1);
|
|
@@ -393,6 +405,75 @@ export class FudaCollection extends HTMLElement {
|
|
|
393
405
|
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
406
|
}
|
|
395
407
|
}
|
|
408
|
+
syncBinder(view) {
|
|
409
|
+
const show = view === 'binder', cur = (attr, dflt, ok) => { const v = this.getAttribute(attr); return v && ok.includes(v) ? v : dflt; };
|
|
410
|
+
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']) };
|
|
411
|
+
for (const [k, h] of Object.entries(this.binderChoices)) {
|
|
412
|
+
h.hidden = !show;
|
|
413
|
+
h.set(vals[k]);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
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}`; }
|
|
417
|
+
/** 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. */
|
|
418
|
+
renderBinder(v, t) {
|
|
419
|
+
const layout = this.binderLay(), n = this.data.length, sides = sideCount(n, layout.per), spread = spreadOf(this.index, layout.per);
|
|
420
|
+
const sheet = this.getAttribute('sheet') === 'black' ? 'black' : 'clear', zip = this.getAttribute('binder') === 'zip', cover = binderCovers.find(c => c.id === this.getAttribute('cover')) ?? binderCovers[0];
|
|
421
|
+
v.classList.add('binder');
|
|
422
|
+
v.style.setProperty('--cover', cover.color);
|
|
423
|
+
const pocket = (index, live) => { const c = this.data[index], el = document.createElement('div'); el.className = 'pocket'; if (live)
|
|
424
|
+
el.append(this.image(c, index));
|
|
425
|
+
else {
|
|
426
|
+
const img = document.createElement('img');
|
|
427
|
+
img.src = c.image;
|
|
428
|
+
img.alt = '';
|
|
429
|
+
img.style.cssText = 'width:86%;height:92%;object-fit:contain;border-radius:3%;box-shadow:0 2px 5px #0007';
|
|
430
|
+
el.append(img);
|
|
431
|
+
} return el; };
|
|
432
|
+
const [L, R] = spreadSides(spread, sides), turn = this.turn;
|
|
433
|
+
this.turn = null;
|
|
434
|
+
const flat = turn && t.on && Math.abs(turn.to - turn.from) === 1 ? turn : null;
|
|
435
|
+
const [oldL, oldR] = flat ? spreadSides(flat.from, sides) : [L, R], [newL, newR] = flat ? spreadSides(flat.to, sides) : [L, R];
|
|
436
|
+
const forward = !!flat && flat.to > flat.from;
|
|
437
|
+
const book = document.createElement('div');
|
|
438
|
+
book.className = `book ${zip ? 'b-zip' : 'b-ring'}`;
|
|
439
|
+
const inside = document.createElement('div');
|
|
440
|
+
inside.className = 'inside';
|
|
441
|
+
const left = document.createElement('div'), right = document.createElement('div');
|
|
442
|
+
left.className = 'half';
|
|
443
|
+
right.className = 'half';
|
|
444
|
+
const put = (half, side, where) => { half.replaceChildren(); if (side >= 0)
|
|
445
|
+
half.append(buildSide(side, where, sheet, layout, n, pocket)); };
|
|
446
|
+
// 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.
|
|
447
|
+
put(left, flat ? (forward ? oldL : newL) : L, 'l');
|
|
448
|
+
put(right, flat ? (forward ? newR : oldR) : R, 'r');
|
|
449
|
+
const spine = document.createElement('div');
|
|
450
|
+
spine.className = 'spine';
|
|
451
|
+
for (const y of [18, 50, 82]) {
|
|
452
|
+
const ring = document.createElement('i');
|
|
453
|
+
ring.className = 'ring';
|
|
454
|
+
ring.style.top = `${y}%`;
|
|
455
|
+
spine.append(ring);
|
|
456
|
+
}
|
|
457
|
+
inside.append(left, right, spine);
|
|
458
|
+
const tab = document.createElement('i');
|
|
459
|
+
tab.className = 'tab';
|
|
460
|
+
book.append(inside, tab);
|
|
461
|
+
v.append(book);
|
|
462
|
+
if (flat) {
|
|
463
|
+
const w = 300, strip = 34, { leaf, slices } = buildLeaf(forward ? oldR : newR, forward ? newL : oldL, sheet, layout, n, pocket, w, strip);
|
|
464
|
+
inside.append(leaf);
|
|
465
|
+
const ms = Math.round(t.ms * 1.4), ease = 'cubic-bezier(.45,.05,.3,1)', a = forward ? [0, -180] : [-180, 0];
|
|
466
|
+
leaf.style.transform = `rotateY(${a[1]}deg)`;
|
|
467
|
+
const swing = leaf.animate([{ transform: `rotateY(${a[0]}deg)` }, { transform: `rotateY(${a[1]}deg)` }], { duration: ms, easing: ease, fill: 'forwards' });
|
|
468
|
+
// Each slice leans on the one before it, so the sheet bends as it swings (the free edge trails) and straightens at the end.
|
|
469
|
+
const bend = forward ? 8 : -8;
|
|
470
|
+
slices.forEach((s, k) => { if (k)
|
|
471
|
+
s.animate([{ transform: 'rotateY(0deg)' }, { transform: `rotateY(${bend}deg)`, offset: .5 }, { transform: 'rotateY(0deg)' }], { duration: ms, easing: ease }); });
|
|
472
|
+
const finish = () => { if (!leaf.isConnected)
|
|
473
|
+
return; put(left, newL, 'l'); put(right, newR, 'r'); leaf.remove(); };
|
|
474
|
+
swing.finished.then(finish, finish);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
396
477
|
render(reset = false, how) {
|
|
397
478
|
if (!this.isConnected)
|
|
398
479
|
return;
|
|
@@ -400,13 +481,14 @@ export class FudaCollection extends HTMLElement {
|
|
|
400
481
|
let view = this.currentView, stage = this.q('.stage'), v = this.q('.v');
|
|
401
482
|
const t = this.timeVars(), playing = t.on && how && this.data.length > 0;
|
|
402
483
|
const before = playing ? this.snapshot(v) : new Map(), left = playing && how.kind === 'move' && gliding.includes(view) ? Array.from(v.querySelectorAll('.card:not(.ghost)')) : [];
|
|
484
|
+
this.syncBinder(view);
|
|
403
485
|
this.tiles.set(view);
|
|
404
486
|
this.landing.set(this.land);
|
|
405
487
|
this.fanChoice.set(this.fanOpen ? 'open' : 'closed');
|
|
406
488
|
this.syncChoices();
|
|
407
489
|
this.landing.hidden = !this.piled;
|
|
408
490
|
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';
|
|
491
|
+
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
492
|
for (const selector of ['.prev', '.next'])
|
|
411
493
|
this.q(selector).disabled = !this.data.length;
|
|
412
494
|
const random = view === 'random';
|
|
@@ -422,7 +504,7 @@ export class FudaCollection extends HTMLElement {
|
|
|
422
504
|
v.style.removeProperty(k);
|
|
423
505
|
this.zoom.minOpen = scrolling.includes(view) ? .5 : 0;
|
|
424
506
|
this.zoom.setTurnable(this.turnable && this.data.length > 0);
|
|
425
|
-
this.zoom.items = this.piled || view === 'fan' ? '.extent' : '.card,.slot';
|
|
507
|
+
this.zoom.items = this.piled || view === 'fan' ? '.extent' : view === 'binder' ? '.book' : '.card,.slot';
|
|
426
508
|
if (!this.data.length) {
|
|
427
509
|
v.innerHTML = '<p class="empty">No cards in this collection.</p>';
|
|
428
510
|
}
|
|
@@ -430,6 +512,8 @@ export class FudaCollection extends HTMLElement {
|
|
|
430
512
|
this.renderDeck(v);
|
|
431
513
|
else if (view === 'fan')
|
|
432
514
|
this.renderFan(v);
|
|
515
|
+
else if (view === 'binder')
|
|
516
|
+
this.renderBinder(v, t);
|
|
433
517
|
else if (pages.includes(view)) {
|
|
434
518
|
v.classList.add('grid', view);
|
|
435
519
|
const columns = Math.min(10, Math.max(1, Math.floor(Number(this.getAttribute('columns')) || 3)));
|
package/dist/collection.d.ts
CHANGED
|
@@ -19,10 +19,13 @@ export interface CollectionCard {
|
|
|
19
19
|
backImage?: string;
|
|
20
20
|
metadata?: CollectionMetadata;
|
|
21
21
|
}
|
|
22
|
+
/** 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
23
|
export declare const collectionViews: ReadonlyArray<{
|
|
23
24
|
id: CollectionView;
|
|
24
25
|
label: string;
|
|
25
26
|
}>;
|
|
27
|
+
/** Display names that earlier versions accepted and that now open another display, so a page that sets them keeps working. */
|
|
28
|
+
export declare const collectionViewAliases: Readonly<Record<string, CollectionView>>;
|
|
26
29
|
export declare function parseCollection(value: unknown): CollectionCard[];
|
|
27
30
|
/** Choose a matching card, avoiding the current card when another match exists. */
|
|
28
31
|
export declare function randomDrawIndex(cards: CollectionCard[], current: number, filter: string, random?: () => number): number | null;
|
package/dist/collection.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export { fanLayout, deckLandings, normalizeLanding } from './pile.js';
|
|
2
|
+
/** 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
3
|
export const collectionViews = [
|
|
3
4
|
{ 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: '
|
|
5
|
+
{ id: 'case', label: 'Convention Display Case' }, { id: 'random', label: 'Random Draw' },
|
|
6
|
+
{ id: 'story', label: 'Vertical Story Scroll' }, { id: 'wall', label: 'Sliding Gallery Wall' },
|
|
7
|
+
{ id: 'spotlight', label: 'Spotlight Carousel' }, { id: 'atlas', label: 'Card Table' }, { id: 'fan', label: 'Fan of Cards' }
|
|
7
8
|
];
|
|
9
|
+
/** Display names that earlier versions accepted and that now open another display, so a page that sets them keeps working. */
|
|
10
|
+
export const collectionViewAliases = { jukebox: 'deck', tower: 'deck' };
|
|
8
11
|
export function parseCollection(value) {
|
|
9
12
|
if (value && typeof value === 'object' && !Array.isArray(value) && 'cards' in value)
|
|
10
13
|
value = value.cards;
|
|
@@ -20,10 +20,30 @@ Every view has the shared view controls (`@johnmorrisdotca/kazoku-ui`) on the vi
|
|
|
20
20
|
- 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
21
|
- 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
22
|
|
|
23
|
+
## Real-life audit (0.8.0)
|
|
24
|
+
|
|
25
|
+
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).
|
|
26
|
+
|
|
27
|
+
Displays
|
|
28
|
+
- 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.
|
|
29
|
+
- 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.
|
|
30
|
+
- 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.
|
|
31
|
+
- Rolodex: a real rotary card file, but ours is three cards leaning like a hand, not a wheel. Fine as a demo idea; kept.
|
|
32
|
+
- 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.
|
|
33
|
+
- 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).
|
|
34
|
+
- 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`).
|
|
35
|
+
|
|
36
|
+
Options
|
|
37
|
+
- 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**.
|
|
38
|
+
- "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.
|
|
39
|
+
- 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**.
|
|
40
|
+
- 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**.
|
|
41
|
+
- Card style (classic, silver sport, cosmic violet): fine as frames, not a real product.
|
|
42
|
+
|
|
23
43
|
## Binder and booklet
|
|
24
44
|
|
|
25
|
-
-
|
|
26
|
-
-
|
|
45
|
+
- 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.
|
|
46
|
+
- Not done: booklet and album (side-loading) pages, a binder with more than one section.
|
|
27
47
|
- Multiple named collections or binders, with their own cards, ordering, and optional titles and covers.
|
|
28
48
|
- Page controls that work with keyboard and touch, with a reduced-motion alternative.
|
|
29
49
|
- 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.
|