@johnmorrisdotca/fuda-cards 0.10.1 → 0.11.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 (82) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +14 -0
  3. package/README.md +89 -7
  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 +30 -65
  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 +140 -11
  37. package/dist/collection.js +139 -33
  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 +191 -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 +121 -131
  62. package/docs/guides/bundlers.md +60 -0
  63. package/docs/guides/card-element.md +2 -2
  64. package/docs/guides/embed-in-an-iframe.md +39 -0
  65. package/docs/guides/frameworks.md +93 -66
  66. package/docs/guides/getting-started.md +3 -1
  67. package/docs/guides/html-and-cdn.md +69 -0
  68. package/docs/guides/ja/bundlers.md +60 -0
  69. package/docs/guides/ja/card-element.md +2 -2
  70. package/docs/guides/ja/embed-in-an-iframe.md +39 -0
  71. package/docs/guides/ja/frameworks.md +93 -66
  72. package/docs/guides/ja/getting-started.md +3 -1
  73. package/docs/guides/ja/html-and-cdn.md +69 -0
  74. package/docs/guides/ja/materials-and-stacks.md +3 -3
  75. package/docs/guides/ja/troubleshooting.md +2 -2
  76. package/docs/guides/ja/typescript-and-node.md +45 -0
  77. package/docs/guides/ja/upgrading.md +1 -1
  78. package/docs/guides/materials-and-stacks.md +3 -3
  79. package/docs/guides/troubleshooting.md +2 -2
  80. package/docs/guides/typescript-and-node.md +45 -0
  81. package/docs/guides/upgrading.md +1 -1
  82. package/package.json +57 -10
@@ -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's modules for stacks, wear and piles are loaded only when a card asks for one, so a plain card costs little. 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
  ```
@@ -48,7 +48,7 @@ The perspective for 3D turns is `--fuda-perspective` (default `1000px`). The edg
48
48
  | Member | What it gives |
49
49
  |---|---|
50
50
  | `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. |
51
+ | `card.cardThicknessMm` | The thickness in use: `thickness`, else the material's, else 0.325. |
52
52
  | `card.stackCount` | How many cards the stack holds, 1 to 1000. |
53
53
  | `card.stackHeight` | The stack's height in millimetres. |
54
54
  | `card.heldCount` | How many cards are still in the stack, after any taken off. |
@@ -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
 
@@ -0,0 +1,69 @@
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>` draws its zoom bar with kazoku-ui, and live 3D loads `three`. Without a bundler, an import map says where each lives.
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
+ The single card needs none of this. For a server's or a bundler's way of loading the same modules see [Bundlers](bundlers.md) and [Frameworks](frameworks.md).
@@ -0,0 +1,60 @@
1
+ ---
2
+ title: バンドラー
3
+ section: how-to
4
+ order: 10
5
+ description: Viteまたはwebpackでカードを使う方法です。要素は、ブラウザーで動くコードの中で1回インポートするだけで、ほかに設定はいりません。
6
+ ---
7
+
8
+ バンドラーはすべてを`node_modules`から解決します。`@johnmorrisdotca/fuda-cards/element`(コレクションなら`/collection-element`も)を、ブラウザーで動く場所のどこかで1回インポートしてください。パッケージは要素のファイルを副作用ありと印してあるので、インポートしたものを何も使わなくても、バンドラーはそのインポートを残します。どちらの例も、`pnpm test:usage`がnpmの作るとおりのパッケージからビルドし、できたページを開いて確かめています。
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
+ ## 得られるもの
59
+
60
+ 山、傷み、カードの山のためのモジュールは、カードがそれを必要としたときだけ読み込まれるので、ふつうのカードは軽く済みます。各エントリーポイントの大きさは[アーキテクチャ](architecture.md)にあります。
@@ -26,7 +26,7 @@ description: fuda-card要素のすべての属性、プロパティ、CSS変数
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
  ```
@@ -48,7 +48,7 @@ console.log(options.variant, options.finish);
48
48
  | メンバー | 内容 |
49
49
  |---|---|
50
50
  | `card.wear` | 属性と同じ、摩耗のプリセット。空文字列を代入すると取り除かれる。 |
51
- | `card.cardThicknessMm` | 実際に使われる厚み。`thickness`、なければ素材の厚み、なければ0.3。 |
51
+ | `card.cardThicknessMm` | 実際に使われる厚み。`thickness`、なければ素材の厚み、なければ0.325。 |
52
52
  | `card.stackCount` | 山の枚数。1から1000。 |
53
53
  | `card.stackHeight` | 山の高さ(ミリメートル)。 |
54
54
  | `card.heldCount` | 取り出した分を除いて、山に残っている枚数。 |
@@ -0,0 +1,39 @@
1
+ ---
2
+ title: iframeに埋め込む
3
+ section: how-to
4
+ order: 12
5
+ description: 自分で作らないページにカードを載せる方法です。埋め込みページのiframeを使い、設定はそのアドレスに入れます。
6
+ ---
7
+
8
+ `demo/embed.html`は、`<iframe>`に入れるために作ったページで、カード以外は何もなく、アドレスに書かれた内容を描きます。何も追跡せず、訪れた人の端末に何も残さず、指定された絵以外は何も読み込みません。
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
+ ## アドレス
32
+
33
+ `<fuda-card>`の設定はどれも、属性名のままパラメーターにできます。`title`、`variant`、`finish`、`stack`、`wear`、`material`、`card-spin`などで、残りは[カード要素](card-element.md)にあります。スイッチは`1`にします。`image`は絵のアドレスで、指定しなければスターシップの絵になります。[ビルダー](https://johnmorrisdotca.github.io/fuda-cards/builder.html)は、選んだ設定から、幅と高さを含めたiframeを書き出します。
34
+
35
+ コレクションには専用のページ`demo/embed-collection.html`があり、コレクションの属性(`view`、`cover`、`pockets`)をパラメーターにでき、見本のカード18枚か、`cards`で指定したJSONファイルを表示します。
36
+
37
+ ## 大きさ
38
+
39
+ ページはiframeに合わせます。カードはiframeが許す幅まで、最大300ピクセルの幅になり、縦横の比は保ちます。例のように、iframeの高さは幅の1.4倍に、影の分の余裕を少し足してください。