@johnmorrisdotca/fuda-cards 0.1.0 → 0.2.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 +26 -6
- package/dist/collection-element.d.ts +6 -2
- package/dist/collection-element.js +80 -88
- package/dist/element.js +7 -4
- package/dist/index.d.ts +2 -0
- package/dist/zoom.d.ts +39 -0
- package/dist/zoom.js +107 -0
- package/docs/collection-displays.md +9 -0
- package/docs/framework-integration.md +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Fuda Cards
|
|
2
2
|
|
|
3
|
-
Reusable collectible card frames for caller-provided images and interactive 3D viewers. The core is a standards-based web component, suitable for plain HTML, Angular, React, Vue, Svelte, and other frameworks that support custom elements. No framework or 3D engine is required by the component.
|
|
3
|
+
Reusable collectible card frames for caller-provided images and interactive 3D viewers. The core is a standards-based web component, suitable for plain HTML, Angular, React, Vue, Svelte, and other frameworks that support custom elements. No framework or 3D engine is required by the component. `<fuda-card>` imports nothing; `<fuda-collection>` uses [`@johnmorrisdotca/kazoku-ui`](https://github.com/johnmorrisdotca/kazoku-ui) for its zoom controls (see Collection viewer).
|
|
4
4
|
|
|
5
5
|
This is an early prototype: classic, sport and cosmic are exploratory CSS designs, not yet historically researched recreations or photorealistic materials. The demo uses a still from Uchusen Rockets; see [assets/README.md](assets/README.md) for its model credit.
|
|
6
6
|
|
|
@@ -23,15 +23,27 @@ Requires Node 22+ and pnpm. Run `pnpm install`, `pnpm check`, then `pnpm dev` an
|
|
|
23
23
|
|
|
24
24
|
In a bundler, import `@johnmorrisdotca/fuda-cards/element` once before rendering `<fuda-card>`. Frameworks may require custom-element configuration (for example, Angular's `CUSTOM_ELEMENTS_SCHEMA`). Framework-specific wrappers have not yet been implemented; see [framework integration examples](docs/framework-integration.md). For published releases, install with `npm install @johnmorrisdotca/fuda-cards`.
|
|
25
25
|
|
|
26
|
-
The default slot accepts HTML, including an existing interactive 3D viewer; its owner handles rotation, zoom and model loading. The card has no drag-to-flip handler, leaving pointer interaction to that viewer. Control the card's reverse independently by adding or removing the `flipped` attribute. The demo provides a flip button. Attributes: `title`, `category`, `subtitle`, `description`, `number`, `rarity`, `variant` (`classic`, `sport`, `cosmic`), `finish` (`foil`, `matte`) and `flipped` (boolean). Set the element width to scale it. The main package entry exports the TypeScript options and available variants and finishes without registering the custom element.
|
|
26
|
+
The default slot accepts HTML, including an existing interactive 3D viewer; its owner handles rotation, zoom and model loading. The card has no drag-to-flip handler, leaving pointer interaction to that viewer. Control the card's reverse independently by adding or removing the `flipped` attribute. The demo provides a flip button. Attributes: `title`, `category`, `subtitle`, `description`, `number`, `rarity`, `variant` (`classic`, `sport`, `cosmic`), `finish` (`foil`, `matte`), `thickness` (millimetres, default `0.3`) and `flipped` (boolean). Set the element width to scale it. The main package entry exports the TypeScript options and available variants and finishes without registering the custom element.
|
|
27
27
|
|
|
28
28
|
3D integrations, framework-specific examples, polished front and back designs, accessibility validation, and photorealistic finishes remain future work.
|
|
29
29
|
|
|
30
30
|
Collection presentation prototypes are available as a reusable `<fuda-collection>` component. See the [collection demo](demo/collections-component.html) and [collection display notes](docs/collection-displays.md).
|
|
31
31
|
|
|
32
|
+
### Back face and thickness
|
|
33
|
+
|
|
34
|
+
A card turned past 90° shows its back (the navy FUDA face), never the mirrored front, and the front's Animate button cannot be seen or clicked from behind. The back is the card's own face and is shown for `flipped` too.
|
|
35
|
+
|
|
36
|
+
The card has thickness, drawn to scale at the 63 mm wide card size: set `thickness` in millimetres (default `0.3`, a standard trading card of about 12 pt stock; roughly `0.8` for a metal card and `1` to `1.5` for a patch or relic card; `0` for a flat card). The edge is drawn from thin planes between the two faces, so it shows edge-on and at any angle, and it scales with the element's width (a 300px card is about 1.4px thick at the default). It is gold foil for the classic gold frame and card-stock cream for the sport and cosmic variants; override it with the `--fuda-edge` CSS custom property (any CSS background). The drop shadow is on the element itself, so a `filter` must not be added to anything between the card and its faces.
|
|
37
|
+
|
|
38
|
+
```html
|
|
39
|
+
<fuda-card title="Relic" thickness="1.5"></fuda-card>
|
|
40
|
+
```
|
|
41
|
+
|
|
32
42
|
### Whole-card rotation
|
|
33
43
|
|
|
34
|
-
Set `card-spin="center"` for a slow 3D turn around the card’s vertical center, or `card-spin="corner"` for a
|
|
44
|
+
Set `card-spin="center"` for a slow 3D turn around the card’s vertical center, or `card-spin="corner"` for a 3D spin like an ice skater: the card keeps its full size and turns a full 360° around the vertical axis through its bottom-left corner, which stays still at the middle of the element, and shows its back half way round. The card sweeps out to both sides of that point, so give it room (a stage about three times its width and twice its height). Both rotate the entire card, including either face and its content. The default is one turn every 180 seconds; set `--fuda-card-spin-duration` to a positive CSS duration such as `30s`. Set `card-spin-direction="reverse"` to reverse the rotation. Add `card-spin-paused` to pause at the current angle, and remove it to resume. Remove `card-spin` to stop and reset the rotation. These attributes are independent of the artwork `motion` and `playing` attributes and the card’s `flipped` state. Reduced-motion preferences disable the rotation and the flip transition.
|
|
45
|
+
|
|
46
|
+
To drive the turn from your own controls instead of the built-in animation, add the boolean `card-view` attribute and set the CSS custom properties `--fuda-yaw` and `--fuda-tilt` (angles, for example `40deg`); the pivot is the one chosen by `card-spin`. The Card Studio does this with [`@johnmorrisdotca/kazoku-ui`](https://www.npmjs.com/package/@johnmorrisdotca/kazoku-ui) view controls (angle, tilt, Auto-turn, Front, zoom out, 2x, zoom in, Fit, pan, drag and pinch, kept in the address), which also zoom and move the whole stage so the full sweep can always be seen. That package is used by the demo only (a dev dependency); `<fuda-card>` itself has no dependencies. `--fuda-perspective` (default `1000px`) sets the card’s perspective.
|
|
35
47
|
|
|
36
48
|
```html
|
|
37
49
|
<fuda-card title="Explorer" card-spin="center" style="--fuda-card-spin-duration: 30s">
|
|
@@ -39,7 +51,7 @@ Set `card-spin="center"` for a slow 3D turn around the card’s vertical center,
|
|
|
39
51
|
</fuda-card>
|
|
40
52
|
```
|
|
41
53
|
|
|
42
|
-
To review, run `pnpm install` and `pnpm dev`, then open the Card Studio. Under **Card rotation**, choose **Rotate around center** or **Spin around corner
|
|
54
|
+
To review, run `pnpm install` and `pnpm dev`, then open the Card Studio. Under **Card rotation**, choose **Rotate around center** or **Spin around bottom corner**. The view controls under the card turn and tip it (Angle, Tilt), start **Auto-turn**, and zoom with **−**, **2×**, **+** and **Fit** (Ctrl or Command with the wheel, or a pinch, also zoom; zoomed in, a drag or the arrows move the view). The Card Studio opens at full card size; **Fit** is one press away and shows the whole sweep, and the corner stays at the middle of the stage at every zoom. Choose **Fast** to see a full turn in eight seconds, and try the direction control and **Flip card**. Auto-turn does not start by itself when your operating system or browser asks for reduced motion. The spin is decorative; use the separate flip control to choose the face.
|
|
43
55
|
|
|
44
56
|
### Moving artwork
|
|
45
57
|
|
|
@@ -55,12 +67,20 @@ Planned JSON, API, scanned-card and interactive-content inputs are outlined in [
|
|
|
55
67
|
|
|
56
68
|
## Pokémon binder demo
|
|
57
69
|
|
|
58
|
-
Open `demo/tcgdex.html` through the local server to browse the Pokémon Base Set as full-card images supplied by [TCGdex](https://tcgdex.dev/). Search by name or number, change pages and select a card to enlarge it. This standalone demo fetches public set data and remote images in the browser; it requires an internet connection. No API key, personal collection storage, or image hosting by Fuda is involved. A missing image or failed request is reported in the UI. Card images and metadata are provided by TCGdex; consult provider terms before deploying a public demo.
|
|
70
|
+
Open `demo/tcgdex.html` through the local server to browse the Pokémon Base Set as full-card images supplied by [TCGdex](https://tcgdex.dev/). Search by name or number, change pages and select a card to enlarge it. The view controls under the binder page zoom in and out (−, 2×, +), **Fit** shows the whole page, and zoomed in you drag, use the arrows or the wheel to move. This standalone demo fetches public set data and remote images in the browser; it requires an internet connection. No API key, personal collection storage, or image hosting by Fuda is involved. A missing image or failed request is reported in the UI. Card images and metadata are provided by TCGdex; consult provider terms before deploying a public demo.
|
|
59
71
|
|
|
60
72
|
## Collection viewer
|
|
61
73
|
|
|
62
74
|
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`, `jukebox`, `random`, `story`, `wall`, `tower`, `spotlight`, or `atlas`. 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.
|
|
63
75
|
|
|
76
|
+
**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. No view turns in 3D, so all eleven use zoom and move only. Nothing animates the zoom, so reduced motion needs no special case. Add the boolean `address` attribute to keep the zoom in the page address (`?zoom=2`). 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.
|
|
77
|
+
|
|
78
|
+
`@johnmorrisdotca/kazoku-ui` is a runtime dependency of the package (it was a development dependency until 0.2.0). 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`:
|
|
79
|
+
|
|
80
|
+
```html
|
|
81
|
+
<script type="importmap">{"imports":{"@johnmorrisdotca/kazoku-ui/view-controls/define":"/node_modules/@johnmorrisdotca/kazoku-ui/dist/view-controls/define.js"}}</script>
|
|
82
|
+
```
|
|
83
|
+
|
|
64
84
|
```html
|
|
65
85
|
<fuda-collection view="deck"></fuda-collection>
|
|
66
86
|
<script type="module">
|
|
@@ -71,7 +91,7 @@ Run `pnpm dev` and open `/demo/collections-component.html`. Import `@johnmorrisd
|
|
|
71
91
|
</script>
|
|
72
92
|
```
|
|
73
93
|
|
|
74
|
-
These are early display prototypes: the case and rotating displays use CSS perspective rather than fully modeled 3D devices; the atlas is a
|
|
94
|
+
These are early display prototypes: the case and rotating displays use CSS perspective rather than fully modeled 3D devices; the atlas is a zoomable, movable plane rather than an unbounded or virtualized canvas. The demo can save and load named collections in the current browser using localStorage; this is not account-based sync or a backup. Configurable case geometry, integrated 3D content, and full browser and accessibility testing remain to be completed. Zoom, Fit, move and pinch are tested in headless Chromium at a desk and a phone size (pinch with synthetic pointer events); a real phone, Safari and Firefox are not tested.
|
|
75
95
|
|
|
76
96
|
Saved demo collections are scoped to the selected profile. Use “Import older saved collections” to copy pre-profile saves without overwriting same-named collections; the originals remain intact. The demo supports JSON export and deletion, and storage stays local to this browser.
|
|
77
97
|
|
|
@@ -3,20 +3,24 @@ export declare class FudaCollection extends HTMLElement {
|
|
|
3
3
|
private root;
|
|
4
4
|
private data;
|
|
5
5
|
private index;
|
|
6
|
-
private zoom;
|
|
7
6
|
private pageSize;
|
|
8
7
|
private selected;
|
|
9
8
|
private back;
|
|
10
9
|
private drawFilter;
|
|
10
|
+
private zoom;
|
|
11
11
|
static get observedAttributes(): string[];
|
|
12
12
|
set cards(value: CollectionCard[]);
|
|
13
13
|
get cards(): CollectionCard[];
|
|
14
14
|
connectedCallback(): void;
|
|
15
|
-
attributeChangedCallback(): void;
|
|
15
|
+
attributeChangedCallback(name: string): void;
|
|
16
16
|
private get currentView();
|
|
17
|
+
private get stacked();
|
|
18
|
+
private q;
|
|
17
19
|
private move;
|
|
18
20
|
private image;
|
|
19
21
|
private open;
|
|
20
22
|
private renderDialog;
|
|
23
|
+
private canDraw;
|
|
24
|
+
private build;
|
|
21
25
|
private render;
|
|
22
26
|
}
|
|
@@ -1,21 +1,41 @@
|
|
|
1
1
|
import { collectionViews, parseCollection, randomDrawIndex, movePage } from './collection.js';
|
|
2
|
+
import { zoomView } from './zoom.js';
|
|
3
|
+
const STYLE = `<style>
|
|
4
|
+
:host{display:block;color:#f6f4f1;font:16px system-ui}*{box-sizing:border-box}.shell{background:#20212c;padding:1rem;border-radius:1rem}header,.nav{display:flex;gap:.6rem;align-items:center;justify-content:center;flex-wrap:wrap}button,select{font:inherit;color:inherit;background:#353747;border:1px solid #79798c;border-radius:.5rem;padding:.55rem .8rem;cursor:pointer}button:focus-visible,select:focus-visible{outline:3px solid #ffd27e}
|
|
5
|
+
.stage{position:relative;height:var(--fuda-stage-height,clamp(300px,calc(100svh - 440px),620px));overflow:hidden;border-radius:1rem;margin:1rem 0 .5rem;background:radial-gradient(ellipse,#52495a,#222330 68%)}.stage:focus-visible{outline:3px solid #ffd27e;outline-offset:2px}.v{position:absolute;inset:0}kazoku-view-controls{display:block;margin-bottom:.75rem}
|
|
6
|
+
.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}
|
|
7
|
+
.stack .card{position:absolute;width:min(64vw,300px);height:86%;top:7%;left:50%;transition:transform .25s}
|
|
8
|
+
.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)}
|
|
9
|
+
.v.case{perspective:800px}.stage.case{background:linear-gradient(#615346,#222)}.case .card{transform:perspective(600px) rotateX(-15deg)}
|
|
10
|
+
.wall{display:flex;gap:1rem;align-items:center;padding:1rem}.wall .card{height:90%;flex:0 0 190px}
|
|
11
|
+
.story{display:flex;flex-direction:column;align-items:center;gap:1rem;padding:1rem}.story .card{width:min(75%,300px);flex:0 0 90%}
|
|
12
|
+
.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}
|
|
13
|
+
.stage.jukebox{border:12px solid #aa7147;box-shadow:inset 0 0 20px #fbb579}.stage.spotlight{background:radial-gradient(ellipse at center,#e5ce99,#454054 40%,#171822 78%)}
|
|
14
|
+
dialog{color:white;background:#242632;border:1px solid #777;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}
|
|
15
|
+
@media(max-width:500px){.grid{grid-template-columns:repeat(min(2,var(--columns,3)),minmax(0,1fr))}}@media(prefers-reduced-motion:reduce){*{transition:none!important}}
|
|
16
|
+
</style>`;
|
|
17
|
+
const SHELL = `<section class="shell"><header><label>Display <select aria-label="Collection display"></select></label></header><div class="stage" tabindex="0" role="group" aria-label="Collection"><div class="v"></div></div><div class="nav"><button class="prev">← Previous</button><span class="count" aria-live="polite"></span><button class="next">Next →</button><label class="draw-filter" hidden>Filter cards <input type="search" aria-label="Filter cards for random draw"></label><button class="draw" hidden>Draw a card</button></div><dialog aria-label="Card detail"></dialog></section>`;
|
|
18
|
+
const pages = ['binder', 'case'];
|
|
19
|
+
const scrolling = ['wall', 'story', 'atlas'];
|
|
2
20
|
export class FudaCollection extends HTMLElement {
|
|
3
21
|
root = this.attachShadow({ mode: 'open' });
|
|
4
22
|
data = [];
|
|
5
23
|
index = 0;
|
|
6
|
-
zoom = 1;
|
|
7
24
|
pageSize = 9;
|
|
8
25
|
selected = null;
|
|
9
26
|
back = false;
|
|
10
27
|
drawFilter = "";
|
|
28
|
+
zoom = null;
|
|
11
29
|
static get observedAttributes() { return ['view', 'page-size', 'columns']; }
|
|
12
30
|
set cards(value) { this.data = parseCollection(value); this.index = Math.min(this.index, Math.max(0, this.data.length - 1)); this.render(); }
|
|
13
31
|
get cards() { return this.data.map(c => ({ ...c, ...(c.metadata ? { metadata: { ...c.metadata } } : {}) })); }
|
|
14
32
|
connectedCallback() { this.render(); }
|
|
15
|
-
attributeChangedCallback() { this.pageSize = Math.min(100, Math.max(1, Math.floor(Number(this.getAttribute('page-size')) || 9))); this.index = 0; this.render(); }
|
|
33
|
+
attributeChangedCallback(name) { this.pageSize = Math.min(100, Math.max(1, Math.floor(Number(this.getAttribute('page-size')) || 9))); this.index = 0; this.render(name === 'view'); }
|
|
16
34
|
get currentView() { let v = this.getAttribute('view'); return collectionViews.some(x => x.id === v) ? v : 'deck'; }
|
|
35
|
+
get stacked() { return ![...pages, ...scrolling].includes(this.currentView); }
|
|
36
|
+
q(selector) { return this.root.querySelector(selector); }
|
|
17
37
|
move(n) { if (!this.data.length)
|
|
18
|
-
return; if (
|
|
38
|
+
return; if (pages.includes(this.currentView)) {
|
|
19
39
|
this.index = movePage(this.index, this.data.length, this.pageSize, n);
|
|
20
40
|
}
|
|
21
41
|
else {
|
|
@@ -23,7 +43,7 @@ export class FudaCollection extends HTMLElement {
|
|
|
23
43
|
} this.render(); }
|
|
24
44
|
image(c) { let button = document.createElement('button'); button.className = 'card'; 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; }
|
|
25
45
|
open(c) { this.selected = c; this.back = false; this.renderDialog(); }
|
|
26
|
-
renderDialog() { let dlg = this.
|
|
46
|
+
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) {
|
|
27
47
|
let img = document.createElement('img');
|
|
28
48
|
img.className = 'detail';
|
|
29
49
|
img.src = this.back && this.selected.backImage ? this.selected.backImage : this.selected.image;
|
|
@@ -39,91 +59,76 @@ export class FudaCollection extends HTMLElement {
|
|
|
39
59
|
}
|
|
40
60
|
} if (!dlg.open)
|
|
41
61
|
dlg.showModal(); }
|
|
42
|
-
|
|
43
|
-
|
|
62
|
+
canDraw() { const query = this.drawFilter.trim().toLocaleLowerCase(); return this.data.some(c => c.name.toLocaleLowerCase().includes(query)); }
|
|
63
|
+
build() {
|
|
64
|
+
if (this.zoom)
|
|
44
65
|
return;
|
|
45
|
-
this.root.innerHTML =
|
|
46
|
-
|
|
47
|
-
</style><section class="shell"><header><label>Display <select aria-label="Collection display"></select></label></header><div class="stage" aria-label="Collection"></div><div class="nav"><button class="prev">← Previous</button><span class="count" aria-live="polite"></span><button class="next">Next →</button><label class="draw-filter" hidden>Filter cards <input type="search" aria-label="Filter cards for random draw"></label><button class="draw" hidden>Draw a card</button><label class="zoom" hidden>Zoom <input type="range" min="0.4" max="2" step="0.1" value="${this.zoom}" aria-label="Zoom card atlas"></label></div><dialog aria-label="Card detail"></dialog></section>`;
|
|
48
|
-
let select = this.root.querySelector('select');
|
|
66
|
+
this.root.innerHTML = STYLE + SHELL;
|
|
67
|
+
const select = this.q('select');
|
|
49
68
|
collectionViews.forEach(v => select.add(new Option(v.label, v.id)));
|
|
50
|
-
select.value = this.currentView;
|
|
51
69
|
select.onchange = () => this.setAttribute('view', select.value);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
this.q('.prev').onclick = () => this.move(-1);
|
|
71
|
+
this.q('.next').onclick = () => this.move(1);
|
|
72
|
+
const input = this.q('.draw-filter input'), draw = this.q('.draw');
|
|
73
|
+
input.oninput = () => { this.drawFilter = input.value; draw.disabled = !this.canDraw(); };
|
|
74
|
+
draw.onclick = () => { const next = randomDrawIndex(this.data, this.index, this.drawFilter); if (next === null)
|
|
75
|
+
return; this.index = next; this.render(); };
|
|
76
|
+
const stage = this.q('.stage');
|
|
77
|
+
this.zoom = zoomView(stage, this.q('.v'), { address: this.hasAttribute('address') });
|
|
78
|
+
let startX = 0;
|
|
79
|
+
stage.addEventListener('touchstart', e => { if (e.touches.length === 1)
|
|
80
|
+
startX = e.touches[0].clientX; }, { passive: true });
|
|
81
|
+
stage.addEventListener('touchend', e => { if (!this.stacked || this.zoom.zoomed() || e.changedTouches.length !== 1)
|
|
82
|
+
return; const dx = e.changedTouches[0].clientX - startX; if (Math.abs(dx) > 45) {
|
|
83
|
+
if (e.cancelable)
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
this.move(dx < 0 ? 1 : -1);
|
|
86
|
+
} }, { passive: false });
|
|
87
|
+
stage.addEventListener('keydown', (e) => { if (!this.stacked || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft'))
|
|
88
|
+
return; e.preventDefault(); this.move(e.key === 'ArrowRight' ? 1 : -1); this.q('.stack .card:last-child')?.focus(); });
|
|
89
|
+
}
|
|
90
|
+
render(reset = false) {
|
|
91
|
+
if (!this.isConnected)
|
|
74
92
|
return;
|
|
93
|
+
this.build();
|
|
94
|
+
let view = this.currentView, stage = this.q('.stage'), v = this.q('.v');
|
|
95
|
+
this.q('select').value = view;
|
|
96
|
+
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';
|
|
97
|
+
for (const selector of ['.prev', '.next'])
|
|
98
|
+
this.q(selector).disabled = !this.data.length;
|
|
99
|
+
const random = view === 'random';
|
|
100
|
+
this.q('.draw-filter').hidden = !random;
|
|
101
|
+
this.q('.draw').hidden = !random;
|
|
102
|
+
this.q('.draw-filter input').value = this.drawFilter;
|
|
103
|
+
this.q('.draw').disabled = !this.canDraw();
|
|
104
|
+
stage.className = `stage ${view}`;
|
|
105
|
+
v.className = 'v';
|
|
106
|
+
v.replaceChildren();
|
|
107
|
+
v.style.removeProperty('--columns');
|
|
108
|
+
this.zoom.minOpen = scrolling.includes(view) ? .5 : 0;
|
|
109
|
+
if (!this.data.length) {
|
|
110
|
+
v.innerHTML = '<p class="empty">No cards in this collection.</p>';
|
|
75
111
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
stage.classList.add('grid', view);
|
|
112
|
+
else if (pages.includes(view)) {
|
|
113
|
+
v.classList.add('grid', view);
|
|
79
114
|
const columns = Math.min(10, Math.max(1, Math.floor(Number(this.getAttribute('columns')) || 3)));
|
|
80
|
-
|
|
115
|
+
v.style.setProperty('--columns', String(columns));
|
|
81
116
|
let start = Math.floor(this.index / this.pageSize) * this.pageSize;
|
|
82
|
-
this.data.slice(start, start + this.pageSize).forEach(c =>
|
|
117
|
+
this.data.slice(start, start + this.pageSize).forEach(c => v.append(this.image(c)));
|
|
83
118
|
}
|
|
84
119
|
else if (view === 'wall' || view === 'story') {
|
|
85
|
-
|
|
86
|
-
this.data.forEach(c =>
|
|
120
|
+
v.classList.add(view);
|
|
121
|
+
this.data.forEach(c => v.append(this.image(c)));
|
|
87
122
|
}
|
|
88
123
|
else if (view === 'atlas') {
|
|
89
|
-
|
|
124
|
+
v.classList.add('atlas');
|
|
90
125
|
let plane = document.createElement('div');
|
|
91
126
|
plane.className = 'plane';
|
|
92
127
|
this.data.forEach(c => plane.append(this.image(c)));
|
|
93
|
-
|
|
94
|
-
let x = 0, y = 0;
|
|
95
|
-
const paint = () => plane.style.transform = `translate(${x}px,${y}px) scale(${this.zoom})`;
|
|
96
|
-
paint();
|
|
97
|
-
let start = null;
|
|
98
|
-
stage.onpointerdown = e => { if (e.target.closest('button'))
|
|
99
|
-
return; start = { x: e.clientX, y: e.clientY, px: x, py: y }; stage.setPointerCapture(e.pointerId); };
|
|
100
|
-
stage.onpointermove = e => { if (start) {
|
|
101
|
-
x = start.px + e.clientX - start.x;
|
|
102
|
-
y = start.py + e.clientY - start.y;
|
|
103
|
-
paint();
|
|
104
|
-
} };
|
|
105
|
-
stage.onpointerup = () => { start = null; };
|
|
106
|
-
stage.onpointercancel = () => { start = null; };
|
|
107
|
-
let touchDistance = 0;
|
|
108
|
-
stage.addEventListener('touchstart', e => { if (e.touches.length === 2) {
|
|
109
|
-
touchDistance = Math.hypot(e.touches[0].clientX - e.touches[1].clientX, e.touches[0].clientY - e.touches[1].clientY);
|
|
110
|
-
start = null;
|
|
111
|
-
} }, { passive: true });
|
|
112
|
-
stage.addEventListener('touchmove', e => { if (e.touches.length === 2 && touchDistance) {
|
|
113
|
-
e.preventDefault();
|
|
114
|
-
const distance = Math.hypot(e.touches[0].clientX - e.touches[1].clientX, e.touches[0].clientY - e.touches[1].clientY);
|
|
115
|
-
this.zoom = Math.min(2, Math.max(.4, this.zoom * distance / touchDistance));
|
|
116
|
-
touchDistance = distance;
|
|
117
|
-
this.root.querySelector('.zoom input').value = String(this.zoom);
|
|
118
|
-
paint();
|
|
119
|
-
} }, { passive: false });
|
|
120
|
-
stage.addEventListener('touchend', () => { touchDistance = 0; }, { passive: true });
|
|
121
|
-
let wrap = this.root.querySelector('.zoom');
|
|
122
|
-
wrap.hidden = false;
|
|
123
|
-
wrap.querySelector('input').oninput = e => { this.zoom = Number(e.target.value); paint(); };
|
|
128
|
+
v.append(plane);
|
|
124
129
|
}
|
|
125
130
|
else {
|
|
126
|
-
|
|
131
|
+
v.classList.add('stack', view);
|
|
127
132
|
let count = Math.min(3, this.data.length);
|
|
128
133
|
for (let d = count - 1; d >= 0; d--) {
|
|
129
134
|
let c = this.data[(this.index + d) % this.data.length], el = this.image(c);
|
|
@@ -131,23 +136,10 @@ export class FudaCollection extends HTMLElement {
|
|
|
131
136
|
let rotation = view === 'rolodex' ? d * 12 : view === 'tower' ? 0 : d * 5;
|
|
132
137
|
el.style.transform = `translateX(calc(-50% + ${offset}px)) rotate(${rotation}deg) scale(${1 - d * .08})`;
|
|
133
138
|
el.style.opacity = String(1 - d * .2);
|
|
134
|
-
|
|
139
|
+
v.append(el);
|
|
135
140
|
}
|
|
136
|
-
let startX = 0;
|
|
137
|
-
stage.addEventListener('touchstart', e => { if (e.touches.length === 1)
|
|
138
|
-
startX = e.touches[0].clientX; }, { passive: true });
|
|
139
|
-
stage.addEventListener('touchend', e => { if (e.changedTouches.length !== 1)
|
|
140
|
-
return; const dx = e.changedTouches[0].clientX - startX; if (Math.abs(dx) > 45) {
|
|
141
|
-
if (e.cancelable)
|
|
142
|
-
e.preventDefault();
|
|
143
|
-
this.move(dx < 0 ? 1 : -1);
|
|
144
|
-
} }, { passive: false });
|
|
145
|
-
stage.addEventListener('keydown', e => { if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
|
|
146
|
-
e.preventDefault();
|
|
147
|
-
this.move(e.key === 'ArrowRight' ? 1 : -1);
|
|
148
|
-
this.root.querySelector('.stack .card:last-child')?.focus();
|
|
149
|
-
} });
|
|
150
141
|
}
|
|
142
|
+
this.zoom.refresh(reset);
|
|
151
143
|
}
|
|
152
144
|
}
|
|
153
145
|
if (!customElements.get('fuda-collection'))
|
package/dist/element.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
const template = document.createElement('template');
|
|
2
2
|
template.innerHTML = `<style>
|
|
3
|
-
:host{display:inline-block;width:300px;aspect-ratio:2.5/3.5;perspective:1000px;font-family:Georgia,serif;color:#27201b}*{box-sizing:border-box}.rotation{height:100%;transform-style:preserve-3d;transform-origin:center center}:host([card-spin="center"]) .rotation{animation:fuda-turn var(--fuda-card-spin-duration, 180s) linear infinite}:host([card-spin="corner"]) .rotation{transform-origin:
|
|
4
|
-
</style><div class="rotation"><div class="card"><div class="face front"><div class="inner"><div class="heading"><span id="title"></span><span class="badge" id="category"></span></div><div class="art"><slot></slot><button class="motion-button" type="button" aria-pressed="false" hidden>▶ Animate</button></div><div class="subtitle" id="subtitle"></div><div class="description" id="description"></div><div class="footer"><span id="number"></span><span>✦ FUDA COLLECTION</span><span id="rarity"></span></div></div><div class="shine"></div></div><div class="face back"><div class="emblem">FUDA</div><div class="shine"></div></div></div></div>`;
|
|
3
|
+
:host{display:inline-block;width:300px;aspect-ratio:2.5/3.5;perspective:var(--fuda-perspective,1000px);container-type:inline-size;filter:drop-shadow(0 12px 14px #0006);--edge:linear-gradient(90deg,#f6dc8c,#b98631 50%,#f6dc8c);font-family:Georgia,serif;color:#27201b}*{box-sizing:border-box}.rotation{height:100%;transform-style:preserve-3d;transform-origin:center center}:host([card-spin="center"]) .rotation{animation:fuda-turn var(--fuda-card-spin-duration, 180s) linear infinite}:host([card-spin="corner"]) .rotation{transform-origin:0 100%;transform:translate(50%,-50%);animation:fuda-corner-turn var(--fuda-card-spin-duration, 180s) linear infinite}:host([card-spin-direction="reverse"]) .rotation{animation-direction:reverse}:host([card-spin-paused]) .rotation{animation-play-state:paused}@keyframes fuda-turn{to{transform:rotateY(360deg)}}@keyframes fuda-corner-turn{from{transform:translate(50%,-50%) rotateY(0)}to{transform:translate(50%,-50%) rotateY(360deg)}}:host([card-view]) .rotation{animation:none;transform:rotateX(var(--fuda-tilt,0deg)) rotateY(var(--fuda-yaw,0deg))}:host([card-view][card-spin="corner"]) .rotation{transform:translate(50%,-50%) rotateX(var(--fuda-tilt,0deg)) rotateY(var(--fuda-yaw,0deg))}@media (prefers-reduced-motion:reduce){:host([card-spin]) .rotation{animation:none}:host .card{transition:none}}.card{--t:calc(var(--mm,.3) * 100cqw / 63);height:100%;position:relative;transform-style:preserve-3d;transition:transform .65s}:host([flipped]) .card{transform:rotateY(180deg)}.face{position:absolute;inset:0;border-radius:15px;backface-visibility:hidden;overflow:hidden}.front{transform:translateZ(calc(var(--t) / 2));padding:13px;background:linear-gradient(135deg,#fbdf87,#ab742c 35%,#ffe9a6 58%,#ae792d);border:2px solid #9c702d}.inner{height:100%;padding:12px;background:linear-gradient(150deg,#f9edc8,#d6b477);border:2px solid #76512a;display:flex;flex-direction:column;gap:8px}.heading,.footer{display:flex;justify-content:space-between;align-items:center;gap:5px}.heading{font-weight:bold;font-size:20px}.badge{font:700 10px sans-serif;letter-spacing:.12em}.art{position:relative;height:53%;border:5px ridge #dcc18a;box-shadow:0 2px 5px #47301488;background:radial-gradient(circle at 50% 35%,#7496a1,#273c4c);overflow:hidden}.art ::slotted(*){width:100%;height:100%;object-fit:contain;display:block}:host([motion="pan"]) .art ::slotted(img){object-fit:cover;object-position:var(--fuda-focus-x, 50%) var(--fuda-focus-y, 25%)}:host([motion="pan"][playing]) .art ::slotted(img){animation:fuda-pan var(--fuda-pan-duration, 12s) ease-in-out infinite alternate}:host([motion="pan"][pan-loop="restart"]) .art ::slotted(img){animation-direction:normal}:host([motion="pan"][pan-direction="up"]) .art ::slotted(img){animation-direction:alternate-reverse}:host([motion="pan"][pan-direction="up"][pan-loop="restart"]) .art ::slotted(img){animation-direction:reverse}@keyframes fuda-pan{from{object-position:50% 0%}to{object-position:50% 100%}}@media (prefers-reduced-motion:reduce){:host([motion="pan"][playing]) .art ::slotted(img){animation:none}}.motion-button{position:absolute;right:6px;bottom:6px;z-index:1;border:1px solid #fff9;border-radius:20px;padding:5px 9px;background:#101827dd;color:white;font:600 10px system-ui;cursor:pointer}.motion-button:focus-visible{outline:3px solid white;outline-offset:2px}.motion-button[hidden]{display:none}.subtitle{text-align:center;font:italic 11px Georgia}.description{border-top:1px solid #9d8054;padding-top:9px;font-size:13px;line-height:1.35;flex:1}.footer{border-top:1px solid #9d8054;padding-top:5px;font:700 9px sans-serif;letter-spacing:.08em}.back{transform:rotateY(180deg) translateZ(calc(var(--t) / 2));background:radial-gradient(ellipse at center,#b78745 0 12%,#152d46 13% 27%,#386988 28% 31%,#10233b 32% 62%,#d2b074 63% 66%,#182c45 67%);border:11px solid #b39158;display:grid;place-items:center;color:#f7e9bf}.emblem{width:125px;height:125px;border:2px solid #edd18c;border-radius:50%;display:grid;place-items:center;background:#17334a;box-shadow:0 0 0 7px #967344,0 0 30px #e6c98288;font:bold 23px Georgia;letter-spacing:.12em}.shine{pointer-events:none;position:absolute;inset:0;opacity:.35;mix-blend-mode:screen;background:linear-gradient(125deg,transparent 25%,#fff9 36%,transparent 48%,#7cf6 56%,#f9a5 62%,transparent 70%)}:host([finish=matte]) .shine{display:none}.edge{position:absolute;background:var(--fuda-edge,var(--edge))}:host([variant=sport]),:host([variant=cosmic]){--edge:#ece4d2}:host([variant=sport]) .front{background:linear-gradient(135deg,#ebedef,#525e69,#fff,#47505d)}:host([variant=sport]) .inner{background:linear-gradient(145deg,#eef1ee,#aebac1);border-color:#394c5b}:host([variant=sport]) .art{border-color:#a9b9c0}:host([variant=cosmic]) .front{background:linear-gradient(130deg,#c9b4ff,#433b83,#dabdff,#503969)}:host([variant=cosmic]) .inner{background:linear-gradient(145deg,#e6dafa,#a997cd);border-color:#584378}
|
|
4
|
+
</style><div class="rotation"><div class="card"><div class="face front"><div class="inner"><div class="heading"><span id="title"></span><span class="badge" id="category"></span></div><div class="art"><slot></slot><button class="motion-button" type="button" aria-pressed="false" hidden>▶ Animate</button></div><div class="subtitle" id="subtitle"></div><div class="description" id="description"></div><div class="footer"><span id="number"></span><span>✦ FUDA COLLECTION</span><span id="rarity"></span></div></div><div class="shine"></div></div><div class="face back"><div class="emblem">FUDA</div><div class="shine"></div></div><i class="edge" style="left:50%;top:0;width:calc(100% - 30px);height:var(--t);transform:translate(-50%,-50%) rotate(0deg) rotateX(90deg)"></i><i class="edge" style="left:50%;top:100%;width:calc(100% - 30px);height:var(--t);transform:translate(-50%,-50%) rotate(0deg) rotateX(90deg)"></i><i class="edge" style="left:0;top:50%;width:var(--t);height:calc(100% - 30px);transform:translate(-50%,-50%) rotateY(90deg)"></i><i class="edge" style="left:100%;top:50%;width:var(--t);height:calc(100% - 30px);transform:translate(-50%,-50%) rotateY(90deg)"></i><i class="edge" style="left:2.20px;top:9.70px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-67.5deg) rotateX(90deg)"></i><i class="edge" style="left:9.70px;top:2.20px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-22.5deg) rotateX(90deg)"></i><i class="edge" style="left:2.20px;top:calc(100% - 9.70px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(67.5deg) rotateX(90deg)"></i><i class="edge" style="left:9.70px;top:calc(100% - 2.20px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(22.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 2.20px);top:9.70px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(67.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 9.70px);top:2.20px;width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(22.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 2.20px);top:calc(100% - 9.70px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-67.5deg) rotateX(90deg)"></i><i class="edge" style="left:calc(100% - 9.70px);top:calc(100% - 2.20px);width:11.48px;height:var(--t);transform:translate(-50%,-50%) rotate(-22.5deg) rotateX(90deg)"></i></div></div>`;
|
|
5
5
|
const defaults = { title: 'Untitled', category: 'COLLECTIBLE', subtitle: 'An item worth collecting', description: 'Add a description to tell its story.', number: 'NO. 001', rarity: '✦' };
|
|
6
6
|
export class FudaCard extends HTMLElement {
|
|
7
|
-
static observedAttributes = ['title', 'category', 'subtitle', 'description', 'number', 'rarity', 'motion', 'playing'];
|
|
7
|
+
static observedAttributes = ['title', 'category', 'subtitle', 'description', 'number', 'rarity', 'motion', 'playing', 'thickness'];
|
|
8
8
|
constructor() { super(); const root = this.attachShadow({ mode: 'open' }); root.append(template.content.cloneNode(true)); root.querySelector('button')?.addEventListener('click', () => this.toggleAttribute('playing')); }
|
|
9
9
|
connectedCallback() { this.render(); }
|
|
10
10
|
attributeChangedCallback(name) { if (name === 'motion' && this.getAttribute('motion') !== 'pan' && this.hasAttribute('playing'))
|
|
11
11
|
this.removeAttribute('playing'); if (this.shadowRoot)
|
|
12
12
|
this.render(); }
|
|
13
|
-
render() { const
|
|
13
|
+
render() { const mm = Number.parseFloat(this.getAttribute('thickness') ?? ''); const card = this.shadowRoot?.querySelector('.card'); if (mm >= 0)
|
|
14
|
+
card?.style.setProperty('--mm', String(mm));
|
|
15
|
+
else
|
|
16
|
+
card?.style.removeProperty('--mm'); const button = this.shadowRoot?.querySelector('.motion-button'); if (button) {
|
|
14
17
|
button.hidden = this.getAttribute('motion') !== 'pan';
|
|
15
18
|
const active = this.hasAttribute('playing');
|
|
16
19
|
button.textContent = active ? '■ Stop' : '▶ Animate';
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface CardOptions {
|
|
|
10
10
|
rarity?: string;
|
|
11
11
|
variant?: CardVariant;
|
|
12
12
|
finish?: CardFinish;
|
|
13
|
+
/** Card thickness in millimetres at the 63 mm wide card size; default 0.3, 0 for a flat card. */
|
|
14
|
+
thickness?: number;
|
|
13
15
|
flipped?: boolean;
|
|
14
16
|
motion?: 'still' | 'pan';
|
|
15
17
|
playing?: boolean;
|
package/dist/zoom.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import '@johnmorrisdotca/kazoku-ui/view-controls/define';
|
|
2
|
+
interface ViewState {
|
|
3
|
+
zoom: number;
|
|
4
|
+
panX: number;
|
|
5
|
+
panY: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ZoomControls extends HTMLElement {
|
|
8
|
+
readonly state: ViewState;
|
|
9
|
+
readonly controller: {
|
|
10
|
+
readonly startZoom: number;
|
|
11
|
+
};
|
|
12
|
+
view: HTMLElement | undefined;
|
|
13
|
+
set(next: Partial<ViewState>): void;
|
|
14
|
+
setFitScale(scale: number): void;
|
|
15
|
+
}
|
|
16
|
+
export interface ZoomOptions {
|
|
17
|
+
/** Selector for the items that must be visible at Fit. */
|
|
18
|
+
items?: string;
|
|
19
|
+
/** Keep zoom in the page address. */
|
|
20
|
+
address?: boolean;
|
|
21
|
+
/** Put the controls after this element instead of after the stage. */
|
|
22
|
+
after?: Element;
|
|
23
|
+
}
|
|
24
|
+
export interface ZoomView {
|
|
25
|
+
controls: ZoomControls;
|
|
26
|
+
/** The smallest scale the view opens at; 0 opens at Fit. */
|
|
27
|
+
minOpen: number;
|
|
28
|
+
/** Measure again after the content or the stage changed. */
|
|
29
|
+
refresh(open?: boolean): void;
|
|
30
|
+
/** Go back to the opening view. */
|
|
31
|
+
reset(): void;
|
|
32
|
+
zoomed(): boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Zoom, Fit and pan for a flat view. `stage` clips, `view` is its absolutely positioned child that holds the items and is
|
|
36
|
+
* moved and scaled. Fit shows every item at once; the reader's zoom and pan are never reset by a change of content.
|
|
37
|
+
*/
|
|
38
|
+
export declare function zoomView(stage: HTMLElement, view: HTMLElement, options?: ZoomOptions): ZoomView;
|
|
39
|
+
export {};
|
package/dist/zoom.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import '@johnmorrisdotca/kazoku-ui/view-controls/define';
|
|
2
|
+
const MARGIN = 12;
|
|
3
|
+
const ZOOMED = 1.05;
|
|
4
|
+
const TAPPABLE = 'button:not(:disabled), a[href]';
|
|
5
|
+
/**
|
|
6
|
+
* Zoom, Fit and pan for a flat view. `stage` clips, `view` is its absolutely positioned child that holds the items and is
|
|
7
|
+
* moved and scaled. Fit shows every item at once; the reader's zoom and pan are never reset by a change of content.
|
|
8
|
+
*/
|
|
9
|
+
export function zoomView(stage, view, options = {}) {
|
|
10
|
+
const items = options.items ?? '.card';
|
|
11
|
+
const controls = document.createElement('kazoku-view-controls');
|
|
12
|
+
controls.setAttribute('flat', '');
|
|
13
|
+
controls.setAttribute('ignore', '');
|
|
14
|
+
controls.setAttribute('zoom-min', '0.4');
|
|
15
|
+
controls.setAttribute('theme', 'dark');
|
|
16
|
+
if (options.address)
|
|
17
|
+
controls.setAttribute('address', '');
|
|
18
|
+
(options.after ?? stage).after(controls);
|
|
19
|
+
controls.view = stage;
|
|
20
|
+
stage.style.userSelect = 'none';
|
|
21
|
+
stage.addEventListener('dragstart', e => e.preventDefault());
|
|
22
|
+
let box = { w: 0, h: 0, cx: 0, cy: 0, bw: 0, bh: 0 };
|
|
23
|
+
let fit = 1;
|
|
24
|
+
const self = { controls, minOpen: 0, refresh, reset: () => refresh(true), zoomed: () => controls.state.zoom > ZOOMED };
|
|
25
|
+
function measure() {
|
|
26
|
+
const previous = view.style.transform;
|
|
27
|
+
view.style.transform = 'none';
|
|
28
|
+
const origin = stage.getBoundingClientRect();
|
|
29
|
+
const left = origin.left + stage.clientLeft, top = origin.top + stage.clientTop;
|
|
30
|
+
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
31
|
+
for (const item of Array.from(view.querySelectorAll(items))) {
|
|
32
|
+
const r = item.getBoundingClientRect();
|
|
33
|
+
if (!r.width || !r.height)
|
|
34
|
+
continue;
|
|
35
|
+
x0 = Math.min(x0, r.left - left);
|
|
36
|
+
y0 = Math.min(y0, r.top - top);
|
|
37
|
+
x1 = Math.max(x1, r.right - left);
|
|
38
|
+
y1 = Math.max(y1, r.bottom - top);
|
|
39
|
+
}
|
|
40
|
+
view.style.transform = previous;
|
|
41
|
+
const w = stage.clientWidth, h = stage.clientHeight;
|
|
42
|
+
if (x0 > x1) {
|
|
43
|
+
x0 = 0;
|
|
44
|
+
y0 = 0;
|
|
45
|
+
x1 = w;
|
|
46
|
+
y1 = h;
|
|
47
|
+
}
|
|
48
|
+
box = { w, h, cx: (x0 + x1) / 2, cy: (y0 + y1) / 2, bw: x1 - x0, bh: y1 - y0 };
|
|
49
|
+
}
|
|
50
|
+
function draw(state) {
|
|
51
|
+
const scale = fit * state.zoom;
|
|
52
|
+
view.style.transformOrigin = `${box.cx}px ${box.cy}px`;
|
|
53
|
+
view.style.transform = `translate(${box.w / 2 - box.cx + state.panX}px,${box.h / 2 - box.cy + state.panY}px) scale(${scale})`;
|
|
54
|
+
}
|
|
55
|
+
function refresh(open = false) {
|
|
56
|
+
measure();
|
|
57
|
+
if (!box.w || !box.h)
|
|
58
|
+
return;
|
|
59
|
+
fit = Math.min(1, (box.w - 2 * MARGIN) / (box.bw || 1), (box.h - 2 * MARGIN) / (box.bh || 1));
|
|
60
|
+
if (!(fit > 0))
|
|
61
|
+
fit = 1;
|
|
62
|
+
controls.setAttribute('zoom-max', String(Math.max(5, Math.ceil(2 / fit))));
|
|
63
|
+
const atOpening = Math.abs(controls.state.zoom - controls.controller.startZoom) < 1e-6;
|
|
64
|
+
controls.setFitScale(fit);
|
|
65
|
+
if (open || atOpening) {
|
|
66
|
+
const scale = Math.max(fit, Math.min(1, self.minOpen));
|
|
67
|
+
controls.setAttribute('zoom', String(scale));
|
|
68
|
+
const s = fit * controls.state.zoom;
|
|
69
|
+
controls.set({
|
|
70
|
+
panX: box.bw * s > box.w - 2 * MARGIN ? MARGIN - box.w / 2 + (box.bw * s) / 2 : 0,
|
|
71
|
+
panY: box.bh * s > box.h - 2 * MARGIN ? MARGIN - box.h / 2 + (box.bh * s) / 2 : 0
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
draw(controls.state);
|
|
75
|
+
}
|
|
76
|
+
controls.addEventListener('kazoku-viewchange', e => draw(e.detail));
|
|
77
|
+
new ResizeObserver(() => refresh()).observe(stage);
|
|
78
|
+
let queued = 0;
|
|
79
|
+
view.addEventListener('transitionend', () => { cancelAnimationFrame(queued); queued = requestAnimationFrame(() => refresh()); });
|
|
80
|
+
stage.addEventListener('wheel', e => {
|
|
81
|
+
if (e.ctrlKey || e.metaKey || !self.zoomed())
|
|
82
|
+
return;
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
const k = e.deltaMode === 1 ? 16 : 1, s = controls.state;
|
|
85
|
+
controls.set({ panX: s.panX - e.deltaX * k, panY: s.panY - e.deltaY * k });
|
|
86
|
+
}, { passive: false });
|
|
87
|
+
// The controls take every press on the stage, so a drag or a pinch works over the items too. A tap that did not move is passed on as a click.
|
|
88
|
+
let tap = null;
|
|
89
|
+
stage.addEventListener('pointerdown', e => {
|
|
90
|
+
const target = e.isPrimary ? e.composedPath().find((n) => n instanceof HTMLElement && n !== stage && n.matches(TAPPABLE)) : undefined;
|
|
91
|
+
tap = target ? { id: e.pointerId, x: e.clientX, y: e.clientY, at: e.timeStamp, target } : null;
|
|
92
|
+
}, true);
|
|
93
|
+
stage.addEventListener('pointerup', e => {
|
|
94
|
+
if (tap && e.pointerId === tap.id && Math.hypot(e.clientX - tap.x, e.clientY - tap.y) < 10 && e.timeStamp - tap.at < 800)
|
|
95
|
+
tap.target.click();
|
|
96
|
+
tap = null;
|
|
97
|
+
});
|
|
98
|
+
stage.addEventListener('pointercancel', () => { tap = null; });
|
|
99
|
+
stage.addEventListener('click', e => {
|
|
100
|
+
if (e.isTrusted && e.detail > 0) {
|
|
101
|
+
e.stopImmediatePropagation();
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
}
|
|
104
|
+
}, true);
|
|
105
|
+
queueMicrotask(() => refresh());
|
|
106
|
+
return self;
|
|
107
|
+
}
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Fuda supplies reusable frames for a caller's cards and reusable ways to display collections on websites. The hosting site supplies the card data and artwork or interactive content. Initial versions of eleven layouts now exist in `<fuda-collection>`. They are prototypes; the detailed capabilities below remain design goals unless described as implemented in the README.
|
|
4
4
|
|
|
5
|
+
## Zoom, Fit and move (every view)
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
- The controls take every press on the view, including one that starts on a card, so a drag or a pinch works over the cards. A tap that did not move is passed to the card as a click, and the keyboard still opens a focused card with Enter.
|
|
10
|
+
- **Fit** shows every card the view draws, at most at natural size. The wall, story and atlas open at half size or larger and start at their first card; the other views open at Fit. Zoom out goes to 0.4 of Fit.
|
|
11
|
+
- 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.
|
|
12
|
+
- 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.
|
|
13
|
+
|
|
5
14
|
## Binder and booklet
|
|
6
15
|
|
|
7
16
|
- Configurable page grids, such as 3 columns by 4 rows or 4 by 4, and responsive alternatives for small screens.
|
|
@@ -14,7 +14,7 @@ Build with `pnpm build`, then install or link the package in the host applicatio
|
|
|
14
14
|
<fuda-collection view="binder"></fuda-collection>
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
For an unbundled page, replace the bare import with the URL of `dist/collection-element.js` and serve the complete `dist` directory.
|
|
17
|
+
For an unbundled page, replace the bare import with the URL of `dist/collection-element.js` and serve the complete `dist` directory. `<fuda-collection>` imports `@johnmorrisdotca/kazoku-ui/view-controls/define` for its zoom controls, so also add an import map for that name pointing at `node_modules/@johnmorrisdotca/kazoku-ui/dist/view-controls/define.js` (or a copy of it); see the demos in `demo/`.
|
|
18
18
|
|
|
19
19
|
## React
|
|
20
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/fuda-cards",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Fuda Cards: collectible card frames for images and interactive 3D content.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -44,9 +44,13 @@
|
|
|
44
44
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
45
45
|
"test": "pnpm build && node --test test/*.test.mjs",
|
|
46
46
|
"check": "pnpm typecheck && pnpm build && pnpm test",
|
|
47
|
+
"test:e2e": "pnpm build && node --test test/e2e/*.e2e.mjs",
|
|
47
48
|
"dev": "pnpm build && node scripts/dev.mjs",
|
|
48
49
|
"site": "pnpm build && node scripts/site.mjs"
|
|
49
50
|
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@johnmorrisdotca/kazoku-ui": "^0.2.1"
|
|
53
|
+
},
|
|
50
54
|
"devDependencies": {
|
|
51
55
|
"typescript": "5.9.3"
|
|
52
56
|
},
|