@johnmorrisdotca/fuda-cards 0.6.1 → 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 +21 -5
- package/dist/binder.d.ts +52 -0
- package/dist/binder.js +115 -0
- package/dist/collection-element.d.ts +32 -3
- package/dist/collection-element.js +294 -83
- package/dist/collection.d.ts +3 -0
- package/dist/collection.js +6 -3
- package/dist/element.d.ts +19 -0
- package/dist/element.js +35 -6
- package/dist/pile-card.d.ts +17 -0
- package/dist/pile-card.js +223 -0
- package/dist/pile.d.ts +45 -2
- package/dist/pile.js +68 -8
- package/dist/zoom.d.ts +8 -0
- package/dist/zoom.js +34 -3
- package/docs/collection-displays.md +28 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,20 @@ 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
|
+
|
|
69
|
+
### Fan a stack, take a card off it
|
|
70
|
+
|
|
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.
|
|
72
|
+
|
|
73
|
+
```html
|
|
74
|
+
<fuda-card title="Deck" stack="52" pile-controls></fuda-card>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The pile code is a separate module (`dist/pile-card.js`) that `<fuda-card>` loads only when a stack asks for `fan`, `taken-off` or `pile-controls`; a card without them is drawn exactly as before and never requests it.
|
|
78
|
+
|
|
65
79
|
### Wear: cards that are not perfect
|
|
66
80
|
|
|
67
81
|
`wear="lightly-played"` draws the card after use: corners that are soft, rounded, chipped or folded (a dog-ear), whitening on the edges, creases, scratches, specks, staining, yellowing and a print that sits off centre. The presets are the plain grading terms: `mint`, `near-mint`, `lightly-played`, `moderately-played`, `heavily-played` and `damaged`; `perfect`, no attribute at all, or an unknown name draws nothing. `wear-seed` fixes where the marks lie, so a card looks the same every time it is drawn. `wear-corners`, `wear-edges`, `wear-surface` and `wear-creases` (0 to 1) change one kind on its own, and `wear="0.5"` sets them all at once.
|
|
@@ -112,15 +126,17 @@ Open `demo/tcgdex.html` through the local server to browse the Pokémon Base Set
|
|
|
112
126
|
|
|
113
127
|
## Collection viewer
|
|
114
128
|
|
|
115
|
-
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.
|
|
130
|
+
|
|
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.
|
|
116
132
|
|
|
117
|
-
**
|
|
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.
|
|
118
134
|
|
|
119
|
-
**The
|
|
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`).
|
|
120
136
|
|
|
121
|
-
**
|
|
137
|
+
**Animate.** Opening and closing the fan, taking a card off, moving to the next card (Rolodex, Spotlight, the fan), changing a binder page and switching display all move; the wall, story and atlas pan to the card you move to. `animate="off"` turns all of it off (every move then ends at once, in exactly the same place), and `speed="slow"` or `"quick"` makes every move longer or shorter. `animate` is **on** when the attribute is missing, as the flight of a card taken off already was in 0.6.0; set `animate="off"` for the jump you had before. The reader's reduced-motion setting always wins. Moves are CSS transforms and one-shot animations that end by themselves: nothing runs while the view is idle. The Animate and Speed buttons are under the view and in the address (`?animate=off&speed=quick`).
|
|
122
138
|
|
|
123
|
-
**Zoom, Fit and move in every view.** Under each view sit the `@johnmorrisdotca/kazoku-ui` view controls: **−**, **2×**, **+** and **Fit**, and, once zoomed in, four arrows to move the view. Ctrl or Command with the wheel (or a trackpad pinch) and a two-finger pinch zoom about the pointer; zoomed in, a drag or the wheel moves the view, even when the drag starts on a card; the keys `+`, `−` and `0` work with the view focused. **Fit** shows every card the view draws (the whole binder or case page, every card of the wall, the story and the atlas). The wall, story and atlas open at half size or larger so a card can be read, and the others open at Fit. A tap or click on a card still opens it, and zooming, moving or paging never resets the other: turning to the next card or page keeps your zoom, and zooming keeps the card or page you are on. The
|
|
139
|
+
**Zoom, Fit and move in every view.** Under each view sit the `@johnmorrisdotca/kazoku-ui` view controls: **−**, **2×**, **+** and **Fit**, and, once zoomed in, four arrows to move the view. Ctrl or Command with the wheel (or a trackpad pinch) and a two-finger pinch zoom about the pointer; zoomed in, a drag or the wheel moves the view, even when the drag starts on a card; the keys `+`, `−` and `0` work with the view focused. **Fit** shows every card the view draws (the whole binder or case page, every card of the wall, the story and the atlas). The wall, story and atlas open at half size or larger so a card can be read, and the others open at Fit. A tap or click on a card still opens it, and zooming, moving or paging never resets the other: turning to the next card or page keeps your zoom, and zooming keeps the card or page you are on. The piles (see above) also turn in 3D; the other displays use zoom and move only. Zoom itself is not animated. Add the boolean `address` attribute to keep the zoom, the display, the fan, the landing, Animate and Speed in the page address (`?view=fan&fan=open&land=face-down&zoom=2`); a link to it opens the same view. Set `--fuda-stage-height` on the element to change the height of the view (default: the window height less 440 px, between 300 and 620 px) so the controls stay on screen.
|
|
124
140
|
|
|
125
141
|
`@johnmorrisdotca/kazoku-ui` is a runtime dependency of the package (it was a development dependency until 0.2.0). Choice buttons, the light and dark colours and the address are written in the package, because kazoku-ui has no shared part for them yet. A bundler resolves it. On a plain HTML page without a bundler, add an import map next to the module script, with the package served from `node_modules` or a copy of its `dist`:
|
|
126
142
|
|
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
|
+
}
|
|
@@ -11,8 +11,13 @@ export declare class FudaCollection extends HTMLElement {
|
|
|
11
11
|
private tiles?;
|
|
12
12
|
private landing?;
|
|
13
13
|
private fanChoice?;
|
|
14
|
+
private animateChoice?;
|
|
15
|
+
private speedChoice?;
|
|
16
|
+
private binderChoices;
|
|
17
|
+
private turn;
|
|
14
18
|
private flip;
|
|
15
19
|
private addressTimer;
|
|
20
|
+
private fanPlaces;
|
|
16
21
|
static get observedAttributes(): string[];
|
|
17
22
|
set cards(value: CollectionCard[]);
|
|
18
23
|
get cards(): CollectionCard[];
|
|
@@ -26,21 +31,45 @@ export declare class FudaCollection extends HTMLElement {
|
|
|
26
31
|
private get land();
|
|
27
32
|
private get fanOpen();
|
|
28
33
|
private get stacked();
|
|
34
|
+
private get piled();
|
|
35
|
+
private get turnable();
|
|
29
36
|
private q;
|
|
30
|
-
/** With `address`, the display, the fan
|
|
37
|
+
/** 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. */
|
|
31
38
|
private readAddress;
|
|
32
39
|
private writeAddress;
|
|
33
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;
|
|
34
44
|
private image;
|
|
35
45
|
private open;
|
|
36
46
|
private renderDialog;
|
|
37
47
|
private canDraw;
|
|
48
|
+
/** The one length every move takes, in a custom property the stylesheet reads: `animate="off"` and reduced motion make it 0, `speed` stretches it. */
|
|
49
|
+
private timeVars;
|
|
50
|
+
private syncChoices;
|
|
38
51
|
private build;
|
|
39
|
-
/** One pile of the deck. `positions` are data indexes from the bottom of the pile to its top; the cards under the top one lie nudged and turned from the seed and the top one lies square. */
|
|
52
|
+
/** One pile of the deck. `positions` are data indexes from the bottom of the pile to its top; the cards under the top one lie nudged and turned from the seed and the top one lies square. A deck's cards also carry where they lie when the fan is open. */
|
|
40
53
|
private pile;
|
|
54
|
+
/** Where the fan's cards lie for a pile of this many cards. A phone's fan lies closer across and leans on its angle. */
|
|
55
|
+
private fanFor;
|
|
56
|
+
/** Open the fan (or close it) on the pile that is on screen, without drawing it again, so every card glides: the open fan's reach is put in custom properties that move the piles apart and the Fit box. */
|
|
57
|
+
private fanVars;
|
|
58
|
+
/** `fan` changed: when a pile is on screen, move its cards to or from the fan in place (animated) and fit the view to it. Returns false when there is no pile to move. */
|
|
59
|
+
private setFan;
|
|
41
60
|
private renderDeck;
|
|
42
|
-
/** The card that just moved flies between the two piles, turning over sideways on the way if it lands face down. The same element, so the card is never drawn twice. */
|
|
61
|
+
/** The card that just moved flies between the two piles, turning over sideways on the way if it lands face down. The same element, so the card is never drawn twice. An open fan sends the card from where the fan holds it. */
|
|
43
62
|
private playFlip;
|
|
44
63
|
private renderFan;
|
|
64
|
+
/** Where every card is on screen now, by data index. */
|
|
65
|
+
private snapshot;
|
|
66
|
+
/** Cards that arrive grow and fade in, a little to the side the reader is heading. Only an opening keyframe: they end on the card's own style. */
|
|
67
|
+
private enter;
|
|
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. */
|
|
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;
|
|
45
74
|
private render;
|
|
46
75
|
}
|