@johnmorrisdotca/fuda-cards 0.10.1 → 0.12.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/LICENSE +21 -0
- package/NOTICE.md +16 -0
- package/README.md +106 -33
- package/dist/binder.d.ts +4 -6
- package/dist/binder.js +32 -23
- package/dist/card-markup.d.ts +2 -0
- package/dist/card-markup.js +59 -0
- package/dist/card-options.d.ts +131 -0
- package/dist/card-options.js +48 -0
- package/dist/card-styles.d.ts +2 -0
- package/dist/card-styles.js +314 -0
- package/dist/choice.d.ts +1 -1
- package/dist/choice.js +27 -23
- package/dist/collection-address.d.ts +8 -0
- package/dist/collection-address.js +52 -0
- package/dist/collection-binder-view.d.ts +9 -0
- package/dist/collection-binder-view.js +123 -0
- package/dist/collection-controls.d.ts +2 -0
- package/dist/collection-controls.js +143 -0
- package/dist/collection-deck.d.ts +11 -0
- package/dist/collection-deck.js +165 -0
- package/dist/collection-dialog.d.ts +2 -0
- package/dist/collection-dialog.js +28 -0
- package/dist/collection-element.d.ts +36 -67
- package/dist/collection-element.js +283 -484
- package/dist/collection-host.d.ts +5 -0
- package/dist/collection-host.js +1 -0
- package/dist/collection-icons.d.ts +3 -0
- package/dist/collection-icons.js +19 -0
- package/dist/collection-motion.d.ts +11 -0
- package/dist/collection-motion.js +72 -0
- package/dist/collection-styles.d.ts +4 -0
- package/dist/collection-styles.js +336 -0
- package/dist/collection-views.d.ts +8 -0
- package/dist/collection-views.js +8 -0
- package/dist/collection.d.ts +154 -11
- package/dist/collection.js +140 -34
- package/dist/element-define.d.ts +2 -0
- package/dist/element-define.js +3 -0
- package/dist/element.d.ts +20 -1
- package/dist/element.js +289 -98
- package/dist/index.d.ts +9 -52
- package/dist/index.js +5 -5
- package/dist/live-3d.d.ts +87 -4
- package/dist/live-3d.js +120 -52
- package/dist/materials.d.ts +117 -6
- package/dist/materials.js +246 -28
- package/dist/motion.d.ts +2 -0
- package/dist/motion.js +4 -0
- package/dist/pile-card.js +138 -91
- package/dist/pile.d.ts +61 -8
- package/dist/pile.js +89 -29
- package/dist/stack.d.ts +42 -6
- package/dist/stack.js +28 -3
- package/dist/version.d.ts +11 -0
- package/dist/version.js +11 -0
- package/dist/wear.d.ts +147 -9
- package/dist/wear.js +273 -89
- package/dist/zoom.d.ts +1 -1
- package/dist/zoom.js +73 -42
- package/docs/API.md +138 -134
- package/docs/collection-displays.md +4 -4
- package/docs/collection-input.md +5 -5
- package/docs/framework-integration.md +1 -1
- package/docs/guides/architecture.md +8 -8
- package/docs/guides/bundlers.md +60 -0
- package/docs/guides/card-element.md +26 -2
- package/docs/guides/collections.md +2 -2
- package/docs/guides/embed-in-an-iframe.md +39 -0
- package/docs/guides/frameworks.md +93 -66
- package/docs/guides/getting-started.md +4 -2
- package/docs/guides/html-and-cdn.md +86 -0
- package/docs/guides/ja/architecture.md +4 -4
- package/docs/guides/ja/bundlers.md +60 -0
- package/docs/guides/ja/card-element.md +26 -2
- package/docs/guides/ja/collections.md +2 -2
- package/docs/guides/ja/embed-in-an-iframe.md +39 -0
- package/docs/guides/ja/frameworks.md +93 -66
- package/docs/guides/ja/getting-started.md +4 -2
- package/docs/guides/ja/html-and-cdn.md +86 -0
- package/docs/guides/ja/live-3d.md +37 -24
- package/docs/guides/ja/materials-and-stacks.md +4 -4
- package/docs/guides/ja/troubleshooting.md +2 -2
- package/docs/guides/ja/typescript-and-node.md +45 -0
- package/docs/guides/ja/upgrading.md +7 -2
- package/docs/guides/ja/wear.md +1 -1
- package/docs/guides/live-3d.md +37 -24
- package/docs/guides/materials-and-stacks.md +4 -4
- package/docs/guides/troubleshooting.md +2 -2
- package/docs/guides/typescript-and-node.md +45 -0
- package/docs/guides/upgrading.md +7 -2
- package/docs/guides/wear.md +1 -1
- package/docs/live-3d.md +1 -18
- package/docs/materials.md +15 -11
- package/docs/wear.md +4 -12
- package/package.json +57 -10
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Collection displays
|
|
2
2
|
|
|
3
|
-
Fuda supplies reusable frames
|
|
3
|
+
Fuda supplies reusable card frames and collection displays for websites. The host supplies the data and artwork. `<fuda-collection>` offers ten displays. The later sections describe both implemented features and design goals. [Current feature roadmap](feature-roadmap.md)
|
|
4
4
|
|
|
5
5
|
## Choosing a display, piles, the fan and animation (0.6.0, 0.7.0)
|
|
6
6
|
|
|
7
|
-
- **Display buttons.**
|
|
8
|
-
- **Piles
|
|
7
|
+
- **Display buttons.** The ten displays have tiles with layout illustrations. Arrow keys move the choice, and the colours follow the reader's light or dark setting.
|
|
8
|
+
- **Piles.** Overlapping Deck, Random Draw and `<fuda-card stack>` can turn, fan open and send a card to a side pile. Rolodex and Spotlight show staggered cards as carousels.
|
|
9
9
|
- **Deck.** A deck and a pile. Next flips the top card off to the pile on the deck's other side, Previous brings it back. The landing is a choice: still facing up, or turned over (a sideways turn about the card's vertical axis, like turning a page, showing the back image or the package's own back). A card never lands with its picture on its head; the 0.6.0 value `upside-down` still works and means turned over. One element flies, so a card is never drawn twice.
|
|
10
10
|
- **Fan.** Every pile fans open and closed with a control right under the view: up to ten cards in an arc, most of each card showing, closing back exactly. `view="fan"` is the same pile with only the fan. In the address (`?fan=open`).
|
|
11
11
|
- **Animate (0.7.0).** `animate="off"` and `speed` for every move: the fan, a card taken off, Next in the carousels, a binder page turn, a switch of display, a pan to the card in the wall, story and atlas. On when the attribute is missing; reduced motion always wins. One shared timing, CSS transforms and one-shot animations, nothing running when idle. Moves with it on and off end in exactly the same place.
|
|
@@ -22,7 +22,7 @@ An item says what it is with `kind` (`"card"`, the default, or `"object"`; see `
|
|
|
22
22
|
|
|
23
23
|
## Zoom, Fit and move (every view)
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
The shared `@johnmorrisdotca/kazoku-ui` controls zoom and pan every collection display. The bar offers zoom out, the current zoom, zoom in and Fit. More shows the arrow pad. A double press goes to 2 times, and Ctrl or Command with the wheel or a pinch zooms about the pointer. Pile displays with cards also offer angle, tilt and Auto-turn.
|
|
26
26
|
|
|
27
27
|
- 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.
|
|
28
28
|
- **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.
|
package/docs/collection-input.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Collection input
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The collection viewer accepts a JavaScript array or an object containing a `cards` array. To use a JSON file, parse it and pass its result to `parseCollection` or assign it to the element's `cards` property.
|
|
4
4
|
|
|
5
5
|
## Sources
|
|
6
6
|
|
|
7
7
|
- A JSON file, a JavaScript array or object supplied by the host, and data fetched from an API by the host.
|
|
8
8
|
- Adapters can map different external APIs and collection exports into Fuda's common card format. The host controls authentication, fetch, refresh and error handling; Fuda does not require a server or assume an external service.
|
|
9
|
-
-
|
|
9
|
+
- Supply a `name` and front `image` URL for each record. The browser requests the images, and the displays can show a fallback when a request fails. The reverse image, `backImage`, is optional.
|
|
10
10
|
|
|
11
11
|
## Card data
|
|
12
12
|
|
|
@@ -32,9 +32,9 @@ An example supported collection format:
|
|
|
32
32
|
- **What an item is.** `kind` is `"card"` (the default: a collection written without it is all cards, as before) or `"object"`. A card is flat and thin with a back, so it turns in 3D, can be seen from behind and lands turned over when taken off a pile. An object is a picture of a thing that is not a card (a games console, a trophy): it has no back and no thickness, so it never turns over, is never seen edge-on or from behind, and always lands facing up. No angle, tilt, Auto-turn or "turned over" landing is offered for a collection with no card in it, and an angle in the address is dropped. In a mixed collection the controls are there for the cards, and the objects stay square to the reader. Objects can still be fanned open (a flat layout) and taken off a pile (they fly across and land facing up). A real 3D object would be a third kind, once an item can carry one.
|
|
33
33
|
- Represent photographed or scanned cards as full-card front and back images, so collectors can display what they already own. Alternatively, use a Fuda frame with a separate image or host-provided interactive artwork in its window.
|
|
34
34
|
- Keep collector details optional: set, year, card number, edition, condition, grade, quantity, notes, and other metadata. Do not assume every item has a market price or grade.
|
|
35
|
-
-
|
|
35
|
+
- Use unique ids to identify cards. Without an id, the parser uses the item's zero-based position. `parseCollection` validates the whole input before returning a normalised array, and a failed assignment keeps the previous collection.
|
|
36
36
|
- Allow host-supplied visual content, including interactive 3D elements, in addition to serializable image references; JSON alone cannot contain a live 3D viewer.
|
|
37
|
-
-
|
|
37
|
+
- All ten displays consume the same normalised collection. The Random Draw view filters by name.
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
The collection demo imports and exports JSON and saves named collections in browser-local storage. Hosts provide their own accounts, storage and sync when needed.
|
|
40
40
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Framework integration
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Install `@johnmorrisdotca/fuda-cards` in the host application. Import the element's registration entry once in browser code. Assign the collection to its JavaScript `cards` property. The [frameworks guide](guides/frameworks.md) covers the current built examples and server rendering.
|
|
4
4
|
|
|
5
5
|
## Plain HTML
|
|
6
6
|
|
|
@@ -12,16 +12,16 @@ Fuda is plain TypeScript compiled to ES modules, with no framework and no 3D eng
|
|
|
12
12
|
| Entry | File | What it is | Size (raw, gzip -9) |
|
|
13
13
|
|---|---|---|---|
|
|
14
14
|
| `@johnmorrisdotca/fuda-cards` | `dist/index.js` | Types and tables: variants, finishes, materials, stack presets, the stack and wear maths. No DOM. | 0.4 KB, plus its modules |
|
|
15
|
-
| `.../element` | `dist/element.js` | Registers `<fuda-card>`. |
|
|
16
|
-
| `.../collection` | `dist/collection.js` | The collection's data rules: `parseCollection`, views, kinds, the fan's layout. No DOM. |
|
|
17
|
-
| `.../collection-element` | `dist/collection-element.js` | Registers `<fuda-collection>`. |
|
|
18
|
-
| `.../live-3d` | `dist/live-3d.js` | The focus policy for live 3D cards. |
|
|
15
|
+
| `.../element` | `dist/element.js` | Registers `<fuda-card>`. | 16.5 KB, 4.9 KB |
|
|
16
|
+
| `.../collection` | `dist/collection.js` | The collection's data rules: `parseCollection`, views, kinds, the fan's layout. No DOM. | 8.1 KB, 2.6 KB |
|
|
17
|
+
| `.../collection-element` | `dist/collection-element.js` | Registers `<fuda-collection>`. | 15.0 KB, 4.4 KB |
|
|
18
|
+
| `.../live-3d` | `dist/live-3d.js` | The focus policy for live 3D cards. | 9.0 KB, 2.7 KB |
|
|
19
19
|
|
|
20
20
|
## The modules behind them
|
|
21
21
|
|
|
22
22
|
- **`element.ts`** draws the card: two faces, an edge made of thin planes, the art slot, the Animate button and the pan, the spin. It imports `materials.ts` and `stack.ts`, and loads the rest on demand. The class it registers, `FudaCard`, is exported too, for a subclass or a type.
|
|
23
|
-
- **`wear.ts`** (
|
|
24
|
-
- **`pile-card.ts`** (
|
|
23
|
+
- **`wear.ts`** (20.6 KB) is a module of its own, loaded with `import()` only when a card has a `wear` attribute. A perfect card is drawn exactly as before.
|
|
24
|
+
- **`pile-card.ts`** (14.3 KB) holds the fan, the take-off and the side pile for `<fuda-card stack>`, loaded only when a card asks for `fan`, `taken-off` or `pile-controls`.
|
|
25
25
|
- **`pile.ts`** is what every pile shares: the landing, the fan layout and the timing (`animate`, `speed`, reduced motion). Both the card and the collection use it, so a pile behaves the same everywhere.
|
|
26
26
|
- **`stack.ts`** lays the cards under the top one from a seed (a small seeded generator, mulberry32), the same way each time.
|
|
27
27
|
- **`materials.ts`** is the table of sourced thicknesses and the stack presets.
|
|
@@ -35,7 +35,7 @@ import { cardMaterials, stackLayout, wearLayout, wearLevels } from '@johnmorrisd
|
|
|
35
35
|
|
|
36
36
|
const levels = wearLevels({ wear: 'damaged' });
|
|
37
37
|
console.log(cardMaterials.length, stackLayout(11).length, Boolean(levels && wearLayout(levels, 1)));
|
|
38
|
-
//
|
|
38
|
+
// 17 10 true
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
## Drawing
|
|
@@ -50,4 +50,4 @@ The art is kept hidden until the card has a size on screen and every slotted ima
|
|
|
50
50
|
|
|
51
51
|
## Tests
|
|
52
52
|
|
|
53
|
-
`pnpm test` runs unit tests on the tables and the rules. `pnpm test:e2e` drives headless Chromium, in software, at a desk and a phone size, one file at a time.
|
|
53
|
+
`pnpm test` runs unit tests on the tables and the rules. `pnpm test:e2e` drives headless Chromium, in software, at a desk and a phone size, one file at a time. `pnpm check` includes the unit tests. CI runs the browser suite separately. See [Development](../../README.md#development).
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Bundlers
|
|
3
|
+
section: how-to
|
|
4
|
+
order: 10
|
|
5
|
+
description: "Use the card with Vite or webpack: import the element once, in code that runs in the browser, and build with nothing more to configure."
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
A bundler resolves everything from `node_modules`. Import `@johnmorrisdotca/fuda-cards/element` (and `/collection-element` for the collection) once, anywhere that runs in the browser. The package marks its element files as having side effects, so a bundler keeps the import even though nothing is used from it. Both examples are built by `pnpm test:usage` from the package as npm packs it, and the page they make is opened.
|
|
9
|
+
|
|
10
|
+
## Vite
|
|
11
|
+
|
|
12
|
+
```ts no-run
|
|
13
|
+
import "@johnmorrisdotca/fuda-cards/element";
|
|
14
|
+
import { type CardOptions, cardAttributes } from "@johnmorrisdotca/fuda-cards";
|
|
15
|
+
|
|
16
|
+
const options: CardOptions = { title: "Explorer One", category: "ROCKET", stack: 10, wear: "near-mint" };
|
|
17
|
+
const card = document.createElement("fuda-card");
|
|
18
|
+
for (const [name, value] of Object.entries(cardAttributes(options))) card.setAttribute(name, value);
|
|
19
|
+
document.getElementById("app")?.append(card);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<!doctype html>
|
|
24
|
+
<html lang="en">
|
|
25
|
+
<head>
|
|
26
|
+
<meta charset="utf-8" />
|
|
27
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
28
|
+
<title>Fuda Cards with Vite</title>
|
|
29
|
+
</head>
|
|
30
|
+
<body>
|
|
31
|
+
<div id="app"></div>
|
|
32
|
+
<script type="module" src="./main.ts"></script>
|
|
33
|
+
</body>
|
|
34
|
+
</html>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## webpack
|
|
38
|
+
|
|
39
|
+
```js no-run
|
|
40
|
+
import "@johnmorrisdotca/fuda-cards/element";
|
|
41
|
+
|
|
42
|
+
const card = document.createElement("fuda-card");
|
|
43
|
+
card.setAttribute("title", "Explorer One");
|
|
44
|
+
card.setAttribute("variant", "cosmic");
|
|
45
|
+
document.body.append(card);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import { fileURLToPath } from "node:url";
|
|
50
|
+
|
|
51
|
+
export default {
|
|
52
|
+
mode: "production",
|
|
53
|
+
entry: "./src/index.js",
|
|
54
|
+
output: { path: fileURLToPath(new URL("./dist", import.meta.url)), filename: "main.js" },
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## What you get
|
|
59
|
+
|
|
60
|
+
The element loads wear and pile rendering when a card uses them. The standard card module imports the stack layout helpers. The sizes of every entry point are in [Architecture](architecture.md).
|
|
@@ -26,7 +26,7 @@ The default slot holds the art: an `<img>`, or any HTML, including an existing i
|
|
|
26
26
|
```ts
|
|
27
27
|
import { cardFinishes, cardVariants, type CardOptions } from '@johnmorrisdotca/fuda-cards';
|
|
28
28
|
|
|
29
|
-
const options: CardOptions = { title: 'Explorer One', variant: cardVariants[2], finish: cardFinishes[0], thickness: 0.
|
|
29
|
+
const options: CardOptions = { title: 'Explorer One', variant: cardVariants[2], finish: cardFinishes[0], thickness: 0.325 };
|
|
30
30
|
console.log(options.variant, options.finish);
|
|
31
31
|
// cosmic foil
|
|
32
32
|
```
|
|
@@ -43,12 +43,36 @@ The element is 300 px wide by default, `aspect-ratio: 2.5 / 3.5`, and every meas
|
|
|
43
43
|
|
|
44
44
|
The perspective for 3D turns is `--fuda-perspective` (default `1000px`). The edge colour is `--fuda-edge`, any CSS background; the default is gold for the classic frame and card-stock cream for the others. The drop shadow is on the element itself, so do not put a `filter` on anything between the card and its faces.
|
|
45
45
|
|
|
46
|
+
### Narrow vintage formats
|
|
47
|
+
|
|
48
|
+
Use CSS `aspect-ratio` to set the proportions of the card's face. These original baseball card layouts use sheet measurements from two Met objects. The 1887–90 Old Judge card measures 3.5 × 6.9 cm and the 1909–11 White Border card measures 3.7 × 6.7 cm. The stock in the example is Fuda's default black-core paper. Fuda still scales the drawn edge using its default 63 mm reference width. [Met record for Old Judge](https://collectionapi.metmuseum.org/public/collection/v1/objects/402300) · [Met record for White Border](https://collectionapi.metmuseum.org/public/collection/v1/objects/413225)
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
|
|
52
|
+
<style>
|
|
53
|
+
.vintage-cards { display: flex; flex-wrap: wrap; align-items: start; gap: 1rem; }
|
|
54
|
+
.vintage-cards fuda-card { width: min(100%, 11rem); }
|
|
55
|
+
.vintage-cards .early-photo { aspect-ratio: 35 / 69; }
|
|
56
|
+
.vintage-cards .early-print { aspect-ratio: 37 / 67; }
|
|
57
|
+
.early-photo .field { background: radial-gradient(ellipse at 50% 70%, #a18562 28%, #565348 29% 58%, #c1aa83 59%); }
|
|
58
|
+
.early-print .field { background: radial-gradient(ellipse at 50% 70%, #b58958 28%, #536346 29% 58%, #bdceb7 59%); }
|
|
59
|
+
</style>
|
|
60
|
+
<div class="vintage-cards">
|
|
61
|
+
<fuda-card class="early-photo" title="Ballpark" subtitle="Infield" finish="matte">
|
|
62
|
+
<span class="field" aria-hidden="true"></span>
|
|
63
|
+
</fuda-card>
|
|
64
|
+
<fuda-card class="early-print" title="Ballpark" subtitle="Outfield" variant="sport" finish="matte">
|
|
65
|
+
<span class="field" aria-hidden="true"></span>
|
|
66
|
+
</fuda-card>
|
|
67
|
+
</div>
|
|
68
|
+
```
|
|
69
|
+
|
|
46
70
|
## Properties and methods
|
|
47
71
|
|
|
48
72
|
| Member | What it gives |
|
|
49
73
|
|---|---|
|
|
50
74
|
| `card.wear` | The wear preset, as the attribute. Setting an empty string removes it. |
|
|
51
|
-
| `card.cardThicknessMm` | The thickness in use: `thickness`, else the material's, else 0.
|
|
75
|
+
| `card.cardThicknessMm` | The thickness in use: `thickness`, else the material's, else 0.325. |
|
|
52
76
|
| `card.stackCount` | How many cards the stack holds, 1 to 1000. |
|
|
53
77
|
| `card.stackHeight` | The stack's height in millimetres. |
|
|
54
78
|
| `card.heldCount` | How many cards are still in the stack, after any taken off. |
|
|
@@ -25,7 +25,7 @@ Import `@johnmorrisdotca/fuda-cards/collection-element` once, then set the `card
|
|
|
25
25
|
</script>
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Assign an array of `CollectionCardInput` records or an object with a `cards` array. Each item needs a `name` and an `image` URL. Ids must be unique, and the parser uses the item's zero-based position when `id` is omitted. Reading the property returns normalised `CollectionCard` records with ids. The deck uses a navy back when `backImage` is omitted. The inspection dialog offers a back view when a back image is supplied.
|
|
29
29
|
|
|
30
30
|
## Check a list first
|
|
31
31
|
|
|
@@ -79,7 +79,7 @@ try { parseCollection([{ name: 'No picture' }]); } catch (error) { console.log((
|
|
|
79
79
|
|
|
80
80
|
## The address and theme
|
|
81
81
|
|
|
82
|
-
Add the boolean `address` attribute
|
|
82
|
+
Add the boolean `address` attribute to keep the display, view controls, fan, landing, Animate, Speed and binder options in the link. For example, `?view=binder&binder=zip&cover=navy&sheet=black&pockets=12` opens the same binder. `theme="light"` or `theme="dark"` sets the colours explicitly. By default they follow the reader's preference. `--fuda-stage-height` sets the view height, which defaults to the window height minus 440 px within a range of 300 to 620 px.
|
|
83
83
|
|
|
84
84
|
## Live 3D in a collection
|
|
85
85
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Embed in an iframe
|
|
3
|
+
section: how-to
|
|
4
|
+
order: 12
|
|
5
|
+
description: Show a card on a page you do not build, with an iframe of the embed page and the settings in its address.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
`demo/embed.html` is a page made for an `<iframe>`: a card and nothing else, drawn from what its address says. It tracks nothing, keeps nothing on the visitor's device and loads nothing but the picture it was told to.
|
|
9
|
+
|
|
10
|
+
```html no-check
|
|
11
|
+
<!doctype html>
|
|
12
|
+
<html lang="en">
|
|
13
|
+
<head>
|
|
14
|
+
<meta charset="utf-8" />
|
|
15
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
16
|
+
<title>A Fuda card in an iframe</title>
|
|
17
|
+
</head>
|
|
18
|
+
<body>
|
|
19
|
+
<iframe
|
|
20
|
+
src="https://johnmorrisdotca.github.io/fuda-cards/demo/embed.html?title=Explorer+One&variant=sport&finish=foil&stack=10&card-spin=center"
|
|
21
|
+
title="Explorer One, a silver card on a stack of ten"
|
|
22
|
+
width="340"
|
|
23
|
+
height="480"
|
|
24
|
+
loading="lazy"
|
|
25
|
+
style="border: 0"
|
|
26
|
+
></iframe>
|
|
27
|
+
</body>
|
|
28
|
+
</html>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## The address
|
|
32
|
+
|
|
33
|
+
Every setting of `<fuda-card>` is a parameter, by its attribute name: `title`, `variant`, `finish`, `stack`, `wear`, `material`, `card-spin` and the rest of [the card element](card-element.md). A switch is `1`. `image` is the address of the picture (the Starship picture otherwise). The [Builder](https://johnmorrisdotca.github.io/fuda-cards/builder.html) writes the iframe for you, with its width and height, from the settings you choose.
|
|
34
|
+
|
|
35
|
+
A collection has its own page, `demo/embed-collection.html`, with the collection's attributes (`view`, `cover`, `pockets`) as parameters and eighteen sample cards, or the JSON file that `cards` names.
|
|
36
|
+
|
|
37
|
+
## Sizing
|
|
38
|
+
|
|
39
|
+
The page fits the iframe: the card is as wide as the iframe allows, up to 300 pixels, and keeps its proportions. Give the iframe a width and a height of 1.4 times the width plus a little room for the shadow, as the example does.
|
|
@@ -1,105 +1,132 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Frameworks
|
|
2
|
+
title: Frameworks
|
|
3
3
|
section: how-to
|
|
4
|
-
order:
|
|
5
|
-
description: Use
|
|
4
|
+
order: 11
|
|
5
|
+
description: Use the card in React, Vue, Svelte and Angular, with the element imported only in the browser, and the whole page in plain HTML, a bundler or an iframe elsewhere.
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
Both elements are standard custom elements, so any framework that can render a custom tag can show them.
|
|
9
|
-
|
|
10
|
-
## Plain HTML with an import map
|
|
11
|
-
|
|
12
|
-
Without a bundler the browser has to find three things by name: the package, kazoku-ui's zoom bar (the collection needs it) and, for live 3D, `three`. An import map says where each lives. Serve `dist` and `node_modules/@johnmorrisdotca/kazoku-ui/dist` (or copies of them):
|
|
13
|
-
|
|
14
|
-
```html
|
|
15
|
-
<script type="importmap">
|
|
16
|
-
{ "imports": {
|
|
17
|
-
"@johnmorrisdotca/fuda-cards/collection-element": "/node_modules/@johnmorrisdotca/fuda-cards/dist/collection-element.js",
|
|
18
|
-
"@johnmorrisdotca/kazoku-ui/view-controls/define": "/node_modules/@johnmorrisdotca/kazoku-ui/dist/view-controls/define.js"
|
|
19
|
-
} }
|
|
20
|
-
</script>
|
|
21
|
-
<fuda-collection view="binder"></fuda-collection>
|
|
22
|
-
<script type="module">
|
|
23
|
-
import '@johnmorrisdotca/fuda-cards/collection-element';
|
|
24
|
-
document.querySelector('fuda-collection').cards = [{ id: 'one', name: 'Example', image: '/cards/one.jpg' }];
|
|
25
|
-
</script>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
The single card, `@johnmorrisdotca/fuda-cards/element`, imports only its own small modules and needs no import map for kazoku-ui.
|
|
29
|
-
|
|
30
|
-
## A bundler
|
|
31
|
-
|
|
32
|
-
A bundler resolves everything from `node_modules`. Import `@johnmorrisdotca/fuda-cards/element` or `/collection-element` once, anywhere that runs in the browser. The package marks these two files in `sideEffects`, so a bundler keeps the import even though nothing is used from it.
|
|
8
|
+
Both elements are standard custom elements, so any framework that can render a custom tag can show them. Two rules hold everywhere: **import the registration module once, in the browser only** (the elements extend `HTMLElement`, which a server does not have), and **set a collection's `cards` as a property, not an attribute**. A card's settings are attributes, and `cardAttributes(options)` writes them from an object, so the same options work in every framework. Each example below is a file in `examples/` that `pnpm test:usage` builds and opens against the package as npm packs it.
|
|
33
9
|
|
|
34
10
|
## React
|
|
35
11
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
import {
|
|
40
|
-
import
|
|
12
|
+
The component imports the element in an effect, so a server render never reaches it, and spreads the attributes of the options. Declare the tag for TypeScript once.
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { type CardOptions, cardAttributes } from "@johnmorrisdotca/fuda-cards";
|
|
16
|
+
import { useEffect } from "react";
|
|
17
|
+
|
|
18
|
+
export function FudaCard({ picture, ...options }: CardOptions & { picture: string }) {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
// The element needs a browser, so it is imported here, never at the top of the file: a server render never reaches an effect.
|
|
21
|
+
void import("@johnmorrisdotca/fuda-cards/element");
|
|
22
|
+
}, []);
|
|
23
|
+
return (
|
|
24
|
+
<fuda-card {...cardAttributes(options)}>
|
|
25
|
+
<img src={picture} alt={options.title ?? ""} />
|
|
26
|
+
</fuda-card>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
```ts
|
|
32
|
+
import type { DetailedHTMLProps, HTMLAttributes } from "react";
|
|
33
|
+
|
|
34
|
+
declare module "react" {
|
|
35
|
+
namespace JSX {
|
|
36
|
+
interface IntrinsicElements {
|
|
37
|
+
"fuda-card": DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement> & Record<string, string | undefined>;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
46
40
|
}
|
|
47
41
|
```
|
|
48
42
|
|
|
49
43
|
## Vue 3
|
|
50
44
|
|
|
51
|
-
Tell the compiler the tag is a custom element (`isCustomElement`, in the Vue plugin's `template.compilerOptions` for Vite) and
|
|
45
|
+
Tell the compiler that the tag is a custom element (`isCustomElement`, in the Vue plugin's `template.compilerOptions` for Vite), and import the element once the component is on the page.
|
|
52
46
|
|
|
53
47
|
```vue
|
|
54
|
-
<script setup>
|
|
55
|
-
import
|
|
56
|
-
|
|
48
|
+
<script setup lang="ts">
|
|
49
|
+
import { onMounted } from "vue";
|
|
50
|
+
|
|
51
|
+
defineProps<{ title: string; picture: string; stack?: number; wear?: string }>();
|
|
52
|
+
|
|
53
|
+
// The element needs a browser: import it once the component is on the page, never while a server renders it.
|
|
54
|
+
onMounted(() => {
|
|
55
|
+
void import("@johnmorrisdotca/fuda-cards/element");
|
|
56
|
+
});
|
|
57
57
|
</script>
|
|
58
|
-
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<fuda-card :title="title" :stack="stack" :wear="wear"><img :src="picture" :alt="title" /></fuda-card>
|
|
61
|
+
</template>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```ts no-check
|
|
65
|
+
import { createApp, h } from "vue";
|
|
66
|
+
import FudaCard from "./FudaCard.vue";
|
|
67
|
+
|
|
68
|
+
const picture =
|
|
69
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Crect width='10' height='10' fill='%23335'/%3E%3C/svg%3E";
|
|
70
|
+
const app = createApp({ render: () => h(FudaCard, { title: "Explorer One", picture, stack: 10, wear: "near-mint" }) });
|
|
71
|
+
app.config.compilerOptions.isCustomElement = (tag) => tag === "fuda-card";
|
|
72
|
+
app.mount("#app");
|
|
59
73
|
```
|
|
60
74
|
|
|
61
75
|
## Svelte
|
|
62
76
|
|
|
77
|
+
`onMount` never runs on the server, so the import goes there.
|
|
78
|
+
|
|
63
79
|
```svelte
|
|
64
|
-
<script>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
<script lang="ts">
|
|
81
|
+
import { onMount } from "svelte";
|
|
82
|
+
|
|
83
|
+
let {
|
|
84
|
+
title,
|
|
85
|
+
picture,
|
|
86
|
+
stack = 1,
|
|
87
|
+
wear = "",
|
|
88
|
+
}: { title: string; picture: string; stack?: number; wear?: string } = $props();
|
|
89
|
+
|
|
90
|
+
// The element needs a browser: onMount never runs on the server.
|
|
91
|
+
onMount(() => {
|
|
92
|
+
void import("@johnmorrisdotca/fuda-cards/element");
|
|
93
|
+
});
|
|
71
94
|
</script>
|
|
72
|
-
|
|
95
|
+
|
|
96
|
+
<fuda-card {title} {stack} {wear}><img src={picture} alt={title} /></fuda-card>
|
|
73
97
|
```
|
|
74
98
|
|
|
75
99
|
## Angular
|
|
76
100
|
|
|
77
|
-
Add `CUSTOM_ELEMENTS_SCHEMA` to the component's schemas and load the
|
|
101
|
+
Add `CUSTOM_ELEMENTS_SCHEMA` to the component's schemas and load the element in browser code. A property binding on `[attr.name]` writes the attribute.
|
|
78
102
|
|
|
79
103
|
```ts no-check
|
|
80
|
-
import { Component, CUSTOM_ELEMENTS_SCHEMA } from
|
|
81
|
-
import '@johnmorrisdotca/fuda-cards/collection-element';
|
|
104
|
+
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input, type OnInit } from "@angular/core";
|
|
82
105
|
|
|
83
106
|
@Component({
|
|
84
|
-
selector:
|
|
107
|
+
selector: "app-fuda-card",
|
|
85
108
|
standalone: true,
|
|
86
109
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
87
|
-
template:
|
|
110
|
+
template: `<fuda-card [attr.title]="title" [attr.stack]="stack" [attr.wear]="wear"><img [src]="picture" [alt]="title" /></fuda-card>`,
|
|
88
111
|
})
|
|
89
|
-
export class
|
|
90
|
-
|
|
112
|
+
export class FudaCardComponent implements OnInit {
|
|
113
|
+
@Input() title = "Explorer One";
|
|
114
|
+
@Input() picture =
|
|
115
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Crect width='10' height='10' fill='%23335'/%3E%3C/svg%3E";
|
|
116
|
+
@Input() stack = 10;
|
|
117
|
+
@Input() wear = "near-mint";
|
|
118
|
+
|
|
119
|
+
ngOnInit(): void {
|
|
120
|
+
// The element needs a browser: ngOnInit also runs when a server renders, so the import waits for one.
|
|
121
|
+
if (typeof window !== "undefined") void import("@johnmorrisdotca/fuda-cards/element");
|
|
122
|
+
}
|
|
91
123
|
}
|
|
92
124
|
```
|
|
93
125
|
|
|
94
|
-
##
|
|
126
|
+
## A collection in a framework
|
|
95
127
|
|
|
96
|
-
The
|
|
128
|
+
The collection takes an array, so set it as a DOM property: in React with a ref and an effect (`ref.current.cards = cards`), in Vue with `:cards.prop="cards"`, in Svelte with `bind:this` and a statement that runs when the array changes, and in Angular with the property binding `[cards]="cards"`. [Collections](collections.md) lists what an item holds.
|
|
97
129
|
|
|
98
|
-
|
|
99
|
-
import { cardMaterials, stackHeightMm } from '@johnmorrisdotca/fuda-cards';
|
|
100
|
-
|
|
101
|
-
console.log(typeof document, cardMaterials.length, stackHeightMm(10, 0.3));
|
|
102
|
-
// undefined 13 3
|
|
103
|
-
```
|
|
130
|
+
## Where to go next
|
|
104
131
|
|
|
105
|
-
The
|
|
132
|
+
The page itself can be plain HTML from a CDN ([HTML and CDN](html-and-cdn.md)), a bundler's ([Bundlers](bundlers.md)) or an iframe of the embed page ([Embed in an iframe](embed-in-an-iframe.md)). TypeScript's types and the server side are in [TypeScript and Node](typescript-and-node.md).
|
|
@@ -15,6 +15,8 @@ Fuda Cards draws collectible cards as web components. A card is a frame around a
|
|
|
15
15
|
npm install @johnmorrisdotca/fuda-cards
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
The package's own version is exported as `VERSION`, so a page can say which one it runs.
|
|
19
|
+
|
|
18
20
|
The package is plain ES modules in `dist/`. It has one runtime dependency, [`@johnmorrisdotca/kazoku-ui`](https://github.com/johnmorrisdotca/kazoku-ui), which draws the zoom bar of the collection viewer. A single card needs nothing else.
|
|
19
21
|
|
|
20
22
|
## Your first card
|
|
@@ -32,7 +34,7 @@ Import the element once, then write the tag. The picture goes inside it, as a ch
|
|
|
32
34
|
|
|
33
35
|
`variant` is `classic`, `sport` or `cosmic`; `finish` is `foil` or `matte`. The card is 300 px wide by default and keeps the 2.5 by 3.5 proportion of a real card: set the element's `width` in CSS to scale it, and everything inside scales with it.
|
|
34
36
|
|
|
35
|
-
On a page with no bundler, replace the bare name with the path of `dist/element.js` and serve the whole `dist` folder, or add an import map (see [
|
|
37
|
+
On a page with no bundler, replace the bare name with the path of `dist/element.js` and serve the whole `dist` folder, or add an import map (see [HTML and CDN](html-and-cdn.md) and [Bundlers](bundlers.md)).
|
|
36
38
|
|
|
37
39
|
## Turn it over and give it thickness
|
|
38
40
|
|
|
@@ -40,7 +42,7 @@ A card has two faces and an edge. `flipped` shows the back; `thickness` is in mi
|
|
|
40
42
|
|
|
41
43
|
```html
|
|
42
44
|
<script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
|
|
43
|
-
<fuda-card title="
|
|
45
|
+
<fuda-card title="Thick card" thickness="1.5" flipped></fuda-card>
|
|
44
46
|
```
|
|
45
47
|
|
|
46
48
|
## A stack, and a card that has been used
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: HTML and CDN
|
|
3
|
+
section: how-to
|
|
4
|
+
order: 9
|
|
5
|
+
description: Put a card on a page with no build step, from jsDelivr or unpkg, or with an import map for the collection and live 3D.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
A card needs one script tag and nothing else: `<fuda-card>` imports only its own small modules, so no import map is needed. Both CDNs answer for the package; `pnpm test:usage` opens each page below with the CDN's answers stood in by the package as npm packs it.
|
|
9
|
+
|
|
10
|
+
## From jsDelivr
|
|
11
|
+
|
|
12
|
+
jsDelivr bundles a subpath of the package with its dependencies when the address ends in `/+esm`.
|
|
13
|
+
|
|
14
|
+
```html no-check
|
|
15
|
+
<!doctype html>
|
|
16
|
+
<html lang="en">
|
|
17
|
+
<head>
|
|
18
|
+
<meta charset="utf-8" />
|
|
19
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
20
|
+
<title>Fuda Cards from jsDelivr</title>
|
|
21
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@johnmorrisdotca/fuda-cards/element/+esm"></script>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<fuda-card title="Explorer One" category="ROCKET" variant="cosmic" finish="foil" stack="10" wear="near-mint">
|
|
25
|
+
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Crect width='10' height='10' fill='%23335'/%3E%3C/svg%3E" alt="Explorer One" />
|
|
26
|
+
</fuda-card>
|
|
27
|
+
</body>
|
|
28
|
+
</html>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## From unpkg
|
|
32
|
+
|
|
33
|
+
unpkg serves the package's own files; `?module` makes it rewrite the imports so that the browser can follow them.
|
|
34
|
+
|
|
35
|
+
```html no-check
|
|
36
|
+
<!doctype html>
|
|
37
|
+
<html lang="en">
|
|
38
|
+
<head>
|
|
39
|
+
<meta charset="utf-8" />
|
|
40
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
41
|
+
<title>Fuda Cards from unpkg</title>
|
|
42
|
+
<script type="module" src="https://unpkg.com/@johnmorrisdotca/fuda-cards/dist/element.js?module"></script>
|
|
43
|
+
</head>
|
|
44
|
+
<body>
|
|
45
|
+
<fuda-card title="Explorer One" category="ROCKET" variant="sport" finish="matte" material="steel-0.5">
|
|
46
|
+
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Crect width='10' height='10' fill='%23335'/%3E%3C/svg%3E" alt="Explorer One" />
|
|
47
|
+
</fuda-card>
|
|
48
|
+
</body>
|
|
49
|
+
</html>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## The collection and live 3D from a CDN
|
|
53
|
+
|
|
54
|
+
`<fuda-collection>` uses kazoku-ui for its zoom bar. The jsDelivr bundle includes that dependency.
|
|
55
|
+
|
|
56
|
+
```html
|
|
57
|
+
<script type="importmap">
|
|
58
|
+
{ "imports": {
|
|
59
|
+
"@johnmorrisdotca/fuda-cards/collection-element": "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/fuda-cards/collection-element/+esm"
|
|
60
|
+
} }
|
|
61
|
+
</script>
|
|
62
|
+
<fuda-collection view="binder"></fuda-collection>
|
|
63
|
+
<script type="module">
|
|
64
|
+
import '@johnmorrisdotca/fuda-cards/collection-element';
|
|
65
|
+
document.querySelector('fuda-collection').cards = [{ id: 'one', name: 'Example', image: 'one.jpg' }];
|
|
66
|
+
</script>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
For live 3D, give the browser a URL for `@johnmorrisdotca/fuda-cards/live-3d` and for the `three` module passed to `createLiveCards`. See [Live 3D](live-3d.md) for the setup.
|
|
70
|
+
|
|
71
|
+
## Serve installed modules yourself
|
|
72
|
+
|
|
73
|
+
If you serve the installed packages, give the browser both module addresses before importing the collection. Serve each package's complete `dist` directory so relative imports can resolve.
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<script type="importmap">
|
|
77
|
+
{ "imports": {
|
|
78
|
+
"@johnmorrisdotca/fuda-cards/collection-element": "/node_modules/@johnmorrisdotca/fuda-cards/dist/collection-element.js",
|
|
79
|
+
"@johnmorrisdotca/kazoku-ui/view-controls/define": "/node_modules/@johnmorrisdotca/kazoku-ui/dist/view-controls/define.js"
|
|
80
|
+
} }
|
|
81
|
+
</script>
|
|
82
|
+
<script type="module">import '@johnmorrisdotca/fuda-cards/collection-element';</script>
|
|
83
|
+
<fuda-collection view="binder"></fuda-collection>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
For live 3D, also map `@johnmorrisdotca/fuda-cards/live-3d`, `@johnmorrisdotca/kazoku-ui/renderer` and `three` to their modules. [Live 3D](live-3d.md) · [Bundlers](bundlers.md) · [Frameworks](frameworks.md)
|