@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.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +16 -0
  3. package/README.md +106 -33
  4. package/dist/binder.d.ts +4 -6
  5. package/dist/binder.js +32 -23
  6. package/dist/card-markup.d.ts +2 -0
  7. package/dist/card-markup.js +59 -0
  8. package/dist/card-options.d.ts +131 -0
  9. package/dist/card-options.js +48 -0
  10. package/dist/card-styles.d.ts +2 -0
  11. package/dist/card-styles.js +314 -0
  12. package/dist/choice.d.ts +1 -1
  13. package/dist/choice.js +27 -23
  14. package/dist/collection-address.d.ts +8 -0
  15. package/dist/collection-address.js +52 -0
  16. package/dist/collection-binder-view.d.ts +9 -0
  17. package/dist/collection-binder-view.js +123 -0
  18. package/dist/collection-controls.d.ts +2 -0
  19. package/dist/collection-controls.js +143 -0
  20. package/dist/collection-deck.d.ts +11 -0
  21. package/dist/collection-deck.js +165 -0
  22. package/dist/collection-dialog.d.ts +2 -0
  23. package/dist/collection-dialog.js +28 -0
  24. package/dist/collection-element.d.ts +36 -67
  25. package/dist/collection-element.js +283 -484
  26. package/dist/collection-host.d.ts +5 -0
  27. package/dist/collection-host.js +1 -0
  28. package/dist/collection-icons.d.ts +3 -0
  29. package/dist/collection-icons.js +19 -0
  30. package/dist/collection-motion.d.ts +11 -0
  31. package/dist/collection-motion.js +72 -0
  32. package/dist/collection-styles.d.ts +4 -0
  33. package/dist/collection-styles.js +336 -0
  34. package/dist/collection-views.d.ts +8 -0
  35. package/dist/collection-views.js +8 -0
  36. package/dist/collection.d.ts +154 -11
  37. package/dist/collection.js +140 -34
  38. package/dist/element-define.d.ts +2 -0
  39. package/dist/element-define.js +3 -0
  40. package/dist/element.d.ts +20 -1
  41. package/dist/element.js +289 -98
  42. package/dist/index.d.ts +9 -52
  43. package/dist/index.js +5 -5
  44. package/dist/live-3d.d.ts +87 -4
  45. package/dist/live-3d.js +120 -52
  46. package/dist/materials.d.ts +117 -6
  47. package/dist/materials.js +246 -28
  48. package/dist/motion.d.ts +2 -0
  49. package/dist/motion.js +4 -0
  50. package/dist/pile-card.js +138 -91
  51. package/dist/pile.d.ts +61 -8
  52. package/dist/pile.js +89 -29
  53. package/dist/stack.d.ts +42 -6
  54. package/dist/stack.js +28 -3
  55. package/dist/version.d.ts +11 -0
  56. package/dist/version.js +11 -0
  57. package/dist/wear.d.ts +147 -9
  58. package/dist/wear.js +273 -89
  59. package/dist/zoom.d.ts +1 -1
  60. package/dist/zoom.js +73 -42
  61. package/docs/API.md +138 -134
  62. package/docs/collection-displays.md +4 -4
  63. package/docs/collection-input.md +5 -5
  64. package/docs/framework-integration.md +1 -1
  65. package/docs/guides/architecture.md +8 -8
  66. package/docs/guides/bundlers.md +60 -0
  67. package/docs/guides/card-element.md +26 -2
  68. package/docs/guides/collections.md +2 -2
  69. package/docs/guides/embed-in-an-iframe.md +39 -0
  70. package/docs/guides/frameworks.md +93 -66
  71. package/docs/guides/getting-started.md +4 -2
  72. package/docs/guides/html-and-cdn.md +86 -0
  73. package/docs/guides/ja/architecture.md +4 -4
  74. package/docs/guides/ja/bundlers.md +60 -0
  75. package/docs/guides/ja/card-element.md +26 -2
  76. package/docs/guides/ja/collections.md +2 -2
  77. package/docs/guides/ja/embed-in-an-iframe.md +39 -0
  78. package/docs/guides/ja/frameworks.md +93 -66
  79. package/docs/guides/ja/getting-started.md +4 -2
  80. package/docs/guides/ja/html-and-cdn.md +86 -0
  81. package/docs/guides/ja/live-3d.md +37 -24
  82. package/docs/guides/ja/materials-and-stacks.md +4 -4
  83. package/docs/guides/ja/troubleshooting.md +2 -2
  84. package/docs/guides/ja/typescript-and-node.md +45 -0
  85. package/docs/guides/ja/upgrading.md +7 -2
  86. package/docs/guides/ja/wear.md +1 -1
  87. package/docs/guides/live-3d.md +37 -24
  88. package/docs/guides/materials-and-stacks.md +4 -4
  89. package/docs/guides/troubleshooting.md +2 -2
  90. package/docs/guides/typescript-and-node.md +45 -0
  91. package/docs/guides/upgrading.md +7 -2
  92. package/docs/guides/wear.md +1 -1
  93. package/docs/live-3d.md +1 -18
  94. package/docs/materials.md +15 -11
  95. package/docs/wear.md +4 -12
  96. package/package.json +57 -10
@@ -1,11 +1,11 @@
1
1
  # Collection displays
2
2
 
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 twelve layouts now exist in `<fuda-collection>`. They are prototypes; the detailed capabilities below remain design goals unless described as implemented in the README.
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.** All twelve displays are buttons on screen at once, in a row that spans the width, each with a small picture of its layout. No drop-down. At least 48 px high; 4 to a row on a phone, 6 on a desk; arrow keys move the choice; light and dark follow the reader.
8
- - **Piles (0.7.0).** The Overlapping Deck, Random Draw, the Jukebox Carousel and the Flip Tower (the last three drew a pile of three cards) are the same pile with their own look. Every pile turns in 3D (angle, tilt, Auto-turn), fans open and closed, and has a card taken off it. `<fuda-card stack>` is a pile too. Rolodex and Spotlight spread their cards and are carousels, not 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
- Every view has the shared view controls (`@johnmorrisdotca/kazoku-ui`) on the view: zoom out, the zoom as a number, zoom in, **Fit**, and, under **More**, an arrow pad. A double press on the view goes to 2 times. 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.
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.
@@ -1,12 +1,12 @@
1
1
  # Collection input
2
2
 
3
- Fuda should display real collections as well as cards generated from other projects. The collection viewer accepts a JSON array or an object containing a cards array. The broader integration features below remain planned.
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
- - Treat image and asset URLs as supplied by the host, and give useful feedback when a file, URL, or field is missing. Support partial data and optional front and back images.
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
- - Provide stable IDs for selection and navigation; validate malformed input and report errors without discarding valid cards.
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
- - Each collection presentation (binder, case, jukebox, rotating index, random viewer) consumes the same normalized collection and can expose filtering and selection to the host.
37
+ - All ten displays consume the same normalised collection. The Random Draw view filters by name.
38
38
 
39
- No accounts, collection storage, third-party integrations, importers, or synchronization are implemented yet. Avoid requiring accounts or uploading a collection to Fuda merely to display it.
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
- Build with `pnpm build`, then install or link the package in the host application. The package is not published yet. Import each element's registration entry once in browser code. `cards` is a JavaScript **property**, not an HTML attribute: assign an array of `{ id, name, image, backImage? }` objects. Image URLs are supplied by the host. Equivalent integrations were bundled and exercised in Chromium using React 19, Angular 19, Vue 3 and Svelte 4; check your framework version and server-rendering setup.
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>`. | 21.4 KB, 6.5 KB |
16
- | `.../collection` | `dist/collection.js` | The collection's data rules: `parseCollection`, views, kinds, the fan's layout. No DOM. | 4.7 KB, 1.6 KB |
17
- | `.../collection-element` | `dist/collection-element.js` | Registers `<fuda-collection>`. | 45.1 KB, 13.4 KB |
18
- | `.../live-3d` | `dist/live-3d.js` | The focus policy for live 3D cards. | 7.5 KB, 2.3 KB |
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`** (17 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`** (13.7 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`.
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
- // 13 10 true
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. Both are part of `pnpm check` and the release. See [Development](../../README.md#development).
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.3 };
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.3. |
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
- The input may be an array or an object with a `cards` array. Each item needs a `name` and an `image` URL. `id` is optional (the position is used), and must be unique. `backImage` is optional; without one the package draws its own navy back.
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 and the zoom, the display, the fan, the landing, Animate and Speed are kept in the page address (`?view=fan&fan=open&land=face-down&zoom=2`), so a link opens the same view. `theme="light"` or `theme="dark"` fixes the colours; without it they follow the reader. `--fuda-stage-height` sets the height of the view (default: the window less 440 px, between 300 and 620 px) so the controls stay on the first screen.
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 and bundlers
2
+ title: Frameworks
3
3
  section: how-to
4
- order: 9
5
- description: Use Fuda in plain HTML with an import map, in a bundler, and in React, Vue, Svelte and Angular, including server rendering and the cards property.
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. The two rules that matter are the same everywhere: **import the registration module once, in the browser**, and **set `cards` as a property**, never as an attribute.
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
- Set the property with a ref. In TypeScript, declare the tags in JSX's intrinsic elements for your React version, or create the element with DOM calls in a wrapper.
37
-
38
- ```jsx
39
- import { useEffect, useRef } from 'react';
40
- import '@johnmorrisdotca/fuda-cards/collection-element';
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
- export function Cards({ cards }) {
43
- const ref = useRef(null);
44
- useEffect(() => { if (ref.current) ref.current.cards = cards; }, [cards]);
45
- return <fuda-collection ref={ref} view="binder" />;
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 bind the array as a DOM property with `.prop`:
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 '@johnmorrisdotca/fuda-cards/collection-element';
56
- defineProps({ cards: { type: Array, required: true } });
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
- <template><fuda-collection view="binder" :cards.prop="cards" /></template>
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
- import { onMount } from 'svelte';
66
- import '@johnmorrisdotca/fuda-cards/collection-element';
67
- export let cards = [];
68
- let viewer;
69
- onMount(() => { viewer.cards = cards; });
70
- $: if (viewer) viewer.cards = cards;
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
- <fuda-collection bind:this={viewer} view="binder"></fuda-collection>
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 registration module in browser code. Property binding sets the array property.
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 '@angular/core';
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: 'app-cards',
107
+ selector: "app-fuda-card",
85
108
  standalone: true,
86
109
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
87
- template: '<fuda-collection view="binder" [cards]="cards"></fuda-collection>',
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 CardsComponent {
90
- cards = [{ id: 'one', name: 'Example', image: '/cards/one.jpg' }];
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
- ## Server rendering
126
+ ## A collection in a framework
95
127
 
96
- The elements extend `HTMLElement` when their module is evaluated, so importing one on a server fails with "HTMLElement is not defined". Import the registration module only on the client, after the DOM exists (in React, inside `useEffect` or a dynamic import with server rendering off), and render a placeholder on the server. The main entry, `@johnmorrisdotca/fuda-cards`, is safe on a server: it holds only the tables and the wear and stack maths.
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
- ```ts
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 integrations were bundled and exercised in Chromium with React 19, Angular 19, Vue 3 and Svelte 4; check your own framework version. There are no framework wrappers yet.
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 [Frameworks and bundlers](frameworks.md)).
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="Relic" thickness="1.5" flipped></fuda-card>
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)