@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.
- package/LICENSE +21 -0
- package/NOTICE.md +14 -0
- package/README.md +89 -7
- 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 +30 -65
- 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 +140 -11
- package/dist/collection.js +139 -33
- 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 +191 -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 +121 -131
- package/docs/guides/bundlers.md +60 -0
- package/docs/guides/card-element.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 +3 -1
- package/docs/guides/html-and-cdn.md +69 -0
- package/docs/guides/ja/bundlers.md +60 -0
- package/docs/guides/ja/card-element.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 +3 -1
- package/docs/guides/ja/html-and-cdn.md +69 -0
- package/docs/guides/ja/materials-and-stacks.md +3 -3
- package/docs/guides/ja/troubleshooting.md +2 -2
- package/docs/guides/ja/typescript-and-node.md +45 -0
- package/docs/guides/ja/upgrading.md +1 -1
- package/docs/guides/materials-and-stacks.md +3 -3
- package/docs/guides/troubleshooting.md +2 -2
- package/docs/guides/typescript-and-node.md +45 -0
- package/docs/guides/upgrading.md +1 -1
- package/package.json +57 -10
|
@@ -1,105 +1,132 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
2
|
+
title: フレームワーク
|
|
3
3
|
section: how-to
|
|
4
|
-
order:
|
|
5
|
-
description:
|
|
4
|
+
order: 11
|
|
5
|
+
description: React、Vue、Svelte、Angularでカードを使う方法です。要素のインポートはブラウザー側だけで行います。ふつうのHTML、バンドラー、iframeは別のガイドにあります。
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
どちらの要素も標準のカスタム要素なので、カスタムタグを描画できるフレームワークなら表示できます。どこでも守る規則は2つです。**登録用のモジュールを、ブラウザー側で1
|
|
9
|
-
|
|
10
|
-
## インポートマップを使うふつうのHTML
|
|
11
|
-
|
|
12
|
-
バンドラーを使わないと、ブラウザーは3つのものを名前から探さなければなりません。パッケージ、kazoku-uiのズームバー(コレクションに必要)、そしてライブ3D用の`three`です。インポートマップで、それぞれの場所を指定します。`dist`と`node_modules/@johnmorrisdotca/kazoku-ui/dist`(またはそのコピー)を配信してください。
|
|
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
|
-
カード1枚用の`@johnmorrisdotca/fuda-cards/element`は、自前の小さなモジュールしか読み込まないので、kazoku-uiのインポートマップは要りません。
|
|
29
|
-
|
|
30
|
-
## バンドラー
|
|
31
|
-
|
|
32
|
-
バンドラーは、すべてを`node_modules`から解決します。ブラウザーで動く場所のどこかで、`@johnmorrisdotca/fuda-cards/element`か`/collection-element`を1回インポートします。この2つのファイルは`sideEffects`に指定されているので、何も使わなくてもバンドラーはこのインポートを残します。
|
|
8
|
+
どちらの要素も標準のカスタム要素なので、カスタムタグを描画できるフレームワークなら表示できます。どこでも守る規則は2つです。**登録用のモジュールを、ブラウザー側で1回だけインポートする**こと(要素は`HTMLElement`を継承しますが、サーバーにはありません)、そして**コレクションの`cards`は属性ではなくプロパティに設定する**ことです。カードの設定は属性で、`cardAttributes(options)`がオブジェクトから属性を作るので、同じ設定がどのフレームワークでも使えます。下の例はどれも`examples/`のファイルで、`pnpm test:usage`が、npmが作るとおりのパッケージを使ってビルドし、開いて確かめています。
|
|
33
9
|
|
|
34
10
|
## React
|
|
35
11
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
import {
|
|
40
|
-
import
|
|
12
|
+
コンポーネントは効果(effect)の中で要素をインポートするので、サーバーでの描画はそこに届きません。設定の属性は展開して渡します。TypeScriptでは、タグを1度だけ宣言します。
|
|
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
|
-
|
|
45
|
+
タグがカスタム要素であることをコンパイラーに伝え(Viteでは、Vueプラグインの`template.compilerOptions`の`isCustomElement`)、コンポーネントがページに載ってから要素をインポートします。
|
|
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`はサーバーでは実行されないので、インポートはそこに置きます。
|
|
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
|
-
|
|
101
|
+
コンポーネントのschemasに`CUSTOM_ELEMENTS_SCHEMA`を加え、要素はブラウザー側のコードで読み込みます。`[attr.name]`のプロパティバインディングで属性を書き込みます。
|
|
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
|
+
## フレームワークの中のコレクション
|
|
95
127
|
|
|
96
|
-
|
|
128
|
+
コレクションは配列を受け取るので、DOMのプロパティとして設定します。Reactではrefと効果(`ref.current.cards = cards`)、Vueでは`:cards.prop="cards"`、Svelteでは`bind:this`と、配列が変わるたびに実行される文、Angularではプロパティバインディング`[cards]="cards"`を使います。項目に入れられる内容は[コレクション](collections.md)にあります。
|
|
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
|
+
## 次に読むもの
|
|
104
131
|
|
|
105
|
-
|
|
132
|
+
ページそのものは、CDNから読むふつうのHTML([HTMLとCDN](html-and-cdn.md))、バンドラー([バンドラー](bundlers.md))、埋め込みページのiframe([iframeに埋め込む](embed-in-an-iframe.md))のどれでも作れます。TypeScriptの型とサーバー側は[TypeScriptとNode](typescript-and-node.md)にあります。
|
|
@@ -15,6 +15,8 @@ Fuda Cardsは、コレクション用のカードをWebコンポーネントと
|
|
|
15
15
|
npm install @johnmorrisdotca/fuda-cards
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
このパッケージ自身のバージョンは`VERSION`として公開されているので、ページが実行中のバージョンを示せます。
|
|
19
|
+
|
|
18
20
|
パッケージは`dist/`にあるふつうのESモジュールです。実行時の依存は[`@johnmorrisdotca/kazoku-ui`](https://github.com/johnmorrisdotca/kazoku-ui)が1つだけで、コレクションのズームバーを描くために使います。カード1枚だけなら、ほかに何も要りません。
|
|
19
21
|
|
|
20
22
|
## 最初のカード
|
|
@@ -32,7 +34,7 @@ npm install @johnmorrisdotca/fuda-cards
|
|
|
32
34
|
|
|
33
35
|
`variant`は`classic`、`sport`、`cosmic`のいずれか、`finish`は`foil`か`matte`です。カードの幅は初期値で300 pxで、本物のカードと同じ2.5対3.5の比率を保ちます。CSSで要素の`width`を変えると、中身もいっしょに拡大・縮小します。
|
|
34
36
|
|
|
35
|
-
バンドラーを使わないページでは、パッケージ名だけのインポートを`dist/element.js`のパスに置き換えて`dist`フォルダー全体を配信するか、インポートマップを使います([
|
|
37
|
+
バンドラーを使わないページでは、パッケージ名だけのインポートを`dist/element.js`のパスに置き換えて`dist`フォルダー全体を配信するか、インポートマップを使います([HTMLとCDN](html-and-cdn.md)と[バンドラー](bundlers.md)を参照)。
|
|
36
38
|
|
|
37
39
|
## 裏返す、厚みを持たせる
|
|
38
40
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: HTMLとCDN
|
|
3
|
+
section: how-to
|
|
4
|
+
order: 9
|
|
5
|
+
description: ビルドなしでカードをページに置く方法です。jsDelivrまたはunpkgから読み込みます。コレクションとライブ3Dにはインポートマップを使います。
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
カードに必要なのはscriptタグ1つだけです。`<fuda-card>`は自分の小さなモジュールしかインポートしないので、インポートマップはいりません。どちらのCDNもこのパッケージを配信します。`pnpm test:usage`は、下のページをそれぞれ開き、CDNの返事をnpmが作るとおりのパッケージで置き換えて確かめています。
|
|
9
|
+
|
|
10
|
+
## jsDelivrから
|
|
11
|
+
|
|
12
|
+
アドレスの終わりに`/+esm`を付けると、jsDelivrはパッケージのサブパスを、依存するものと一緒にまとめて返します。
|
|
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
|
+
## unpkgから
|
|
32
|
+
|
|
33
|
+
unpkgはパッケージのファイルをそのまま配信します。`?module`を付けると、ブラウザーがたどれるようにインポートを書き換えて返します。
|
|
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
|
+
## CDNから使うコレクションとライブ3D
|
|
53
|
+
|
|
54
|
+
`<fuda-collection>`はズームバーの描画にkazoku-uiを使い、ライブ3Dは`three`を読み込みます。バンドラーなしでは、インポートマップでそれぞれの場所を指定します。
|
|
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
|
+
1枚のカードには、このどれも必要ありません。同じモジュールをサーバーやバンドラーで読み込む方法は、[バンドラー](bundlers.md)と[フレームワーク](frameworks.md)を見てください。
|
|
@@ -11,7 +11,7 @@ Fudaのカードには厚みがあり、カードの山の高さは、枚数に
|
|
|
11
11
|
|
|
12
12
|
## 厚み
|
|
13
13
|
|
|
14
|
-
`thickness`はミリメートルです。初期値は`0.
|
|
14
|
+
`thickness`はミリメートルです。初期値は`0.325`(トランプの黒芯用紙、13 pt。`DEFAULT_CARD_THICKNESS_MM`として公開)で、`0`は平らなカードです。`material`を指定すると、実際の用紙の厚みと縁の色が使われます。`thickness`を併せて指定すると、そちらが優先されます。
|
|
15
15
|
|
|
16
16
|
```html
|
|
17
17
|
<script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
|
|
@@ -55,10 +55,10 @@ console.log(130 * mmPerPoint);
|
|
|
55
55
|
`stackPresets`は出典のある4つの枚数です。トランプ2種類(52枚と54枚)、ポケモンのデッキ60枚、ブースターパック10枚です。ページにカードを置かなくても、山の高さを計算できます。
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
|
-
import { cardMaterial, stackHeightMm, stackLayout, stackPresets } from '@johnmorrisdotca/fuda-cards';
|
|
58
|
+
import { cardMaterial, DEFAULT_CARD_THICKNESS_MM, stackHeightMm, stackLayout, stackPresets } from '@johnmorrisdotca/fuda-cards';
|
|
59
59
|
|
|
60
60
|
const stock = cardMaterial('paper-310-black-core');
|
|
61
|
-
console.log(stackHeightMm(52, stock?.thicknessMm ??
|
|
61
|
+
console.log(stackHeightMm(52, stock?.thicknessMm ?? DEFAULT_CARD_THICKNESS_MM));
|
|
62
62
|
console.log(stackPresets.map((preset) => preset.count).join(' '));
|
|
63
63
|
console.log(stackLayout(5, { messiness: 0, seed: 1 }).length);
|
|
64
64
|
// 16.9
|
|
@@ -21,7 +21,7 @@ description: カードが空白、画像がちらつく、コレクションが
|
|
|
21
21
|
|
|
22
22
|
## 「HTMLElement is not defined」
|
|
23
23
|
|
|
24
|
-
`element`か`collection-element`をサーバーでインポートしています。これらは評価時に`HTMLElement`を継承します。ブラウザーだけでインポートしてください([
|
|
24
|
+
`element`か`collection-element`をサーバーでインポートしています。これらは評価時に`HTMLElement`を継承します。ブラウザーだけでインポートしてください([HTMLとCDN](html-and-cdn.md)と[バンドラー](bundlers.md)を参照)。メインのエントリーと`@johnmorrisdotca/fuda-cards/collection`は、サーバーでも安全です。
|
|
25
25
|
|
|
26
26
|
## コレクションに何も表示されない
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ description: カードが空白、画像がちらつく、コレクションが
|
|
|
29
29
|
|
|
30
30
|
## ズームバーがない、またはコンソールに`@johnmorrisdotca/kazoku-ui/view-controls/define`を解決できないと出る
|
|
31
31
|
|
|
32
|
-
バンドラーのないページでは、コレクションにその名前のインポートマップが要ります([
|
|
32
|
+
バンドラーのないページでは、コレクションにその名前のインポートマップが要ります([HTMLとCDN](html-and-cdn.md)を参照)。カード1枚の`<fuda-card>`には要りません。
|
|
33
33
|
|
|
34
34
|
## 角度、傾き、自動回転が出ない
|
|
35
35
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TypeScriptとNode
|
|
3
|
+
section: how-to
|
|
4
|
+
order: 13
|
|
5
|
+
description: すべての設定の型と、DOMのないサーバーでも動く表、計算、配置を説明します。
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
パッケージは自分の型を同梱しています。`CardOptions`はカードのすべての設定の型で、`cardAttributes(options)`がそれを属性にし、素材、山の枚数、傷みの段階の表はただのデータです。名前や値の間違いはビルド時のエラーになります。下の例の最後の行は、わざとそのエラーにしてあります。
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import {
|
|
12
|
+
type CardMaterial,
|
|
13
|
+
type CardOptions,
|
|
14
|
+
cardAttributes,
|
|
15
|
+
cardMaterial,
|
|
16
|
+
stackHeightMm,
|
|
17
|
+
wearPresets,
|
|
18
|
+
} from "@johnmorrisdotca/fuda-cards";
|
|
19
|
+
|
|
20
|
+
const options: CardOptions = { title: "Explorer One", material: "paper-310-black-core", stack: 52, wear: "near-mint" };
|
|
21
|
+
const stock: CardMaterial | undefined = cardMaterial(options.material);
|
|
22
|
+
console.log(stock?.name, stackHeightMm(options.stack ?? 1, stock?.thicknessMm ?? 0.325));
|
|
23
|
+
console.log(Object.keys(cardAttributes(options)).join(" "), wearPresets.length);
|
|
24
|
+
|
|
25
|
+
// @ts-expect-error "neon" is not a look
|
|
26
|
+
cardAttributes({ variant: "neon" });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## サーバーで
|
|
30
|
+
|
|
31
|
+
メインのエントリー`@johnmorrisdotca/fuda-cards`、コレクションの補助関数(`/collection`)、配置の関数は、ブラウザーなしで動きます。要素は`HTMLElement`を継承するので、クライアント側だけでインポートしてください([フレームワーク](frameworks.md)を見てください)。
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { cardMaterials, stackHeightMm, stackLayout, wearLayout, wearPreset } from "@johnmorrisdotca/fuda-cards";
|
|
35
|
+
|
|
36
|
+
// The tables and the maths run on a server too: nothing here touches a browser.
|
|
37
|
+
const black = cardMaterials.find((material) => material.id === "paper-310-black-core");
|
|
38
|
+
console.log(stackHeightMm(52, black.thicknessMm));
|
|
39
|
+
console.log(stackLayout(52, { seed: 7 }).length);
|
|
40
|
+
console.log(wearLayout(wearPreset("damaged").levels, 3).front.creases.length > 0);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 副作用のない部分
|
|
44
|
+
|
|
45
|
+
山の配置と傷みの配置は、数字とシードだけで決まる純粋な関数です。同じシードなら、Nodeでもブラウザーでもいつでも同じ山と同じ傷になるので、カードの見た目は、設定とシードとして書き残せます。
|
|
@@ -41,7 +41,7 @@ description: 0.1から0.10まで、各バージョンで対応が必要な変更
|
|
|
41
41
|
|
|
42
42
|
## 0.2へ
|
|
43
43
|
|
|
44
|
-
- **`@johnmorrisdotca/kazoku-ui`は実行時の依存になりました。** バンドラーのないページでは、`@johnmorrisdotca/kazoku-ui/view-controls/define`のインポートマップが要ります。[
|
|
44
|
+
- **`@johnmorrisdotca/kazoku-ui`は実行時の依存になりました。** バンドラーのないページでは、`@johnmorrisdotca/kazoku-ui/view-controls/define`のインポートマップが要ります。[HTMLとCDN](html-and-cdn.md)と[バンドラー](bundlers.md)を参照してください。
|
|
45
45
|
- `<fuda-collection>`の`address`属性が、表示の状態をページのURLに保ちます。
|
|
46
46
|
|
|
47
47
|
## アップグレードの確認
|
|
@@ -11,7 +11,7 @@ A Fuda card has a thickness, and a stack of cards is as high as its count times
|
|
|
11
11
|
|
|
12
12
|
## Thickness
|
|
13
13
|
|
|
14
|
-
`thickness` is in millimetres. The default is `0.
|
|
14
|
+
`thickness` is in millimetres. The default is `0.325` (a playing card's black-core stock, 13 pt, exported as `DEFAULT_CARD_THICKNESS_MM`); `0` is a flat card. A `material` takes the thickness, and the edge colour, of a real stock, and `thickness` still overrides it.
|
|
15
15
|
|
|
16
16
|
```html
|
|
17
17
|
<script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
|
|
@@ -55,10 +55,10 @@ A card put on top of the stack moves none of those under it, because each card's
|
|
|
55
55
|
`stackPresets` are four counts with a source: two decks of playing cards (52 and 54), a Pokémon deck of 60 and a booster pack of 10. Work out the height of any pile in code without a card on the page:
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
|
-
import { cardMaterial, stackHeightMm, stackLayout, stackPresets } from '@johnmorrisdotca/fuda-cards';
|
|
58
|
+
import { cardMaterial, DEFAULT_CARD_THICKNESS_MM, stackHeightMm, stackLayout, stackPresets } from '@johnmorrisdotca/fuda-cards';
|
|
59
59
|
|
|
60
60
|
const stock = cardMaterial('paper-310-black-core');
|
|
61
|
-
console.log(stackHeightMm(52, stock?.thicknessMm ??
|
|
61
|
+
console.log(stackHeightMm(52, stock?.thicknessMm ?? DEFAULT_CARD_THICKNESS_MM));
|
|
62
62
|
console.log(stackPresets.map((preset) => preset.count).join(' '));
|
|
63
63
|
console.log(stackLayout(5, { messiness: 0, seed: 1 }).length);
|
|
64
64
|
// 16.9
|
|
@@ -21,7 +21,7 @@ The element is not registered. Check that `@johnmorrisdotca/fuda-cards/element`
|
|
|
21
21
|
|
|
22
22
|
## "HTMLElement is not defined"
|
|
23
23
|
|
|
24
|
-
You imported `element` or `collection-element` on a server. They extend `HTMLElement` when evaluated. Import them only in the browser (see [
|
|
24
|
+
You imported `element` or `collection-element` on a server. They extend `HTMLElement` when evaluated. Import them only in the browser (see [TypeScript and Node](typescript-and-node.md#on-a-server)). The main entry and `@johnmorrisdotca/fuda-cards/collection` are safe on a server.
|
|
25
25
|
|
|
26
26
|
## The collection shows nothing
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ You imported `element` or `collection-element` on a server. They extend `HTMLEle
|
|
|
29
29
|
|
|
30
30
|
## The zoom bar is missing, or the console says it cannot resolve `@johnmorrisdotca/kazoku-ui/view-controls/define`
|
|
31
31
|
|
|
32
|
-
On a page without a bundler the collection needs an import map for that name (see [
|
|
32
|
+
On a page without a bundler the collection needs an import map for that name (see [HTML and CDN](html-and-cdn.md#the-collection-and-live-3d-from-a-cdn)). The single `<fuda-card>` does not.
|
|
33
33
|
|
|
34
34
|
## Angle, Tilt and Auto-turn are not there
|
|
35
35
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TypeScript and Node
|
|
3
|
+
section: how-to
|
|
4
|
+
order: 13
|
|
5
|
+
description: The types of every option, and the tables, the maths and the layouts that run on a server with no DOM.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
The package ships its own types. `CardOptions` types every setting of the card, `cardAttributes(options)` turns it into attributes, and the tables of materials, stack sizes and wear grades are plain data. A mistake in a name or a value is an error at build time; the last line of the example below is meant to be one.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import {
|
|
12
|
+
type CardMaterial,
|
|
13
|
+
type CardOptions,
|
|
14
|
+
cardAttributes,
|
|
15
|
+
cardMaterial,
|
|
16
|
+
stackHeightMm,
|
|
17
|
+
wearPresets,
|
|
18
|
+
} from "@johnmorrisdotca/fuda-cards";
|
|
19
|
+
|
|
20
|
+
const options: CardOptions = { title: "Explorer One", material: "paper-310-black-core", stack: 52, wear: "near-mint" };
|
|
21
|
+
const stock: CardMaterial | undefined = cardMaterial(options.material);
|
|
22
|
+
console.log(stock?.name, stackHeightMm(options.stack ?? 1, stock?.thicknessMm ?? 0.325));
|
|
23
|
+
console.log(Object.keys(cardAttributes(options)).join(" "), wearPresets.length);
|
|
24
|
+
|
|
25
|
+
// @ts-expect-error "neon" is not a look
|
|
26
|
+
cardAttributes({ variant: "neon" });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## On a server
|
|
30
|
+
|
|
31
|
+
The main entry, `@johnmorrisdotca/fuda-cards`, the collection helpers (`/collection`) and the layouts need no browser. The elements extend `HTMLElement`, so import them only on the client (see [Frameworks](frameworks.md)).
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { cardMaterials, stackHeightMm, stackLayout, wearLayout, wearPreset } from "@johnmorrisdotca/fuda-cards";
|
|
35
|
+
|
|
36
|
+
// The tables and the maths run on a server too: nothing here touches a browser.
|
|
37
|
+
const black = cardMaterials.find((material) => material.id === "paper-310-black-core");
|
|
38
|
+
console.log(stackHeightMm(52, black.thicknessMm));
|
|
39
|
+
console.log(stackLayout(52, { seed: 7 }).length);
|
|
40
|
+
console.log(wearLayout(wearPreset("damaged").levels, 3).front.creases.length > 0);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## What is pure
|
|
44
|
+
|
|
45
|
+
The stack's layout and the wear's layout are pure functions of their numbers and a seed: the same seed lays the same stack and the same marks every time, in Node and in a browser, so a card's look can be written down as its settings and its seeds.
|
package/docs/guides/upgrading.md
CHANGED
|
@@ -41,7 +41,7 @@ The package is in early development (0.x), and each minor release can add to the
|
|
|
41
41
|
|
|
42
42
|
## To 0.2
|
|
43
43
|
|
|
44
|
-
- **`@johnmorrisdotca/kazoku-ui` is a runtime dependency.** A page without a bundler needs an import map for `@johnmorrisdotca/kazoku-ui/view-controls/define`. See [
|
|
44
|
+
- **`@johnmorrisdotca/kazoku-ui` is a runtime dependency.** A page without a bundler needs an import map for `@johnmorrisdotca/kazoku-ui/view-controls/define`. See [HTML and CDN](html-and-cdn.md) and [Bundlers](bundlers.md).
|
|
45
45
|
- The `address` attribute on `<fuda-collection>` keeps the view's state in the page address.
|
|
46
46
|
|
|
47
47
|
## Checking an upgrade
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/fuda-cards",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.11.0",
|
|
4
|
+
"description": "Collectible card frames for the web: images and live 3D in a card with a true thickness, foil, stacks, wear and a binder.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "John Morris",
|
|
5
7
|
"type": "module",
|
|
6
8
|
"sideEffects": [
|
|
7
9
|
"./dist/element.js",
|
|
8
|
-
"./dist/collection-element.js"
|
|
10
|
+
"./dist/collection-element.js",
|
|
11
|
+
"./dist/element-define.js"
|
|
9
12
|
],
|
|
10
13
|
"main": "./dist/index.js",
|
|
11
14
|
"types": "./dist/index.d.ts",
|
|
@@ -18,6 +21,10 @@
|
|
|
18
21
|
"types": "./dist/element.d.ts",
|
|
19
22
|
"import": "./dist/element.js"
|
|
20
23
|
},
|
|
24
|
+
"./element/define": {
|
|
25
|
+
"types": "./dist/element-define.d.ts",
|
|
26
|
+
"import": "./dist/element-define.js"
|
|
27
|
+
},
|
|
21
28
|
"./package.json": "./package.json",
|
|
22
29
|
"./live-3d": {
|
|
23
30
|
"types": "./dist/live-3d.d.ts",
|
|
@@ -35,6 +42,7 @@
|
|
|
35
42
|
"files": [
|
|
36
43
|
"dist",
|
|
37
44
|
"README.md",
|
|
45
|
+
"LICENSE",
|
|
38
46
|
"docs/collection-displays.md",
|
|
39
47
|
"docs/collection-input.md",
|
|
40
48
|
"docs/framework-integration.md",
|
|
@@ -43,27 +51,38 @@
|
|
|
43
51
|
"docs/wear.md",
|
|
44
52
|
"assets/README.md",
|
|
45
53
|
"docs/API.md",
|
|
46
|
-
"docs/guides"
|
|
54
|
+
"docs/guides",
|
|
55
|
+
"NOTICE.md"
|
|
47
56
|
],
|
|
48
57
|
"engines": {
|
|
49
58
|
"node": ">=22"
|
|
50
59
|
},
|
|
51
60
|
"scripts": {
|
|
52
|
-
"build": "tsc -p tsconfig.json",
|
|
61
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json",
|
|
53
62
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
54
63
|
"test": "pnpm build && node --test test/*.test.mjs test/*.test.ts",
|
|
55
|
-
"check": "pnpm typecheck && pnpm build && pnpm test",
|
|
64
|
+
"check": "pnpm lint && pnpm typecheck && pnpm build && pnpm check:size && pnpm test",
|
|
56
65
|
"test:e2e": "pnpm build && node scripts/e2e.mjs",
|
|
57
66
|
"test:freeze": "pnpm site && node scripts/e2e.mjs live-3d",
|
|
58
67
|
"dev": "pnpm build && node scripts/dev.mjs",
|
|
59
68
|
"site": "pnpm build && node scripts/site.mjs",
|
|
60
69
|
"screenshots:readme": "pnpm site && node scripts/readme-pictures.mjs",
|
|
61
70
|
"docs:api": "pnpm build && node scripts/docs.mjs api",
|
|
62
|
-
"docs:check": "pnpm build && node scripts/docs.mjs check",
|
|
63
|
-
"test:readme": "pnpm build && node scripts/check-readme-examples.mjs"
|
|
71
|
+
"docs:check": "pnpm build && node scripts/docs.mjs check && node scripts/docs-site.mjs check",
|
|
72
|
+
"test:readme": "pnpm build && node scripts/check-readme-examples.mjs",
|
|
73
|
+
"lint": "biome check .",
|
|
74
|
+
"format": "biome check --write .",
|
|
75
|
+
"check:size": "node scripts/check-size.mjs",
|
|
76
|
+
"test:package": "pnpm build && node scripts/check-package.mjs",
|
|
77
|
+
"check:standard": "node scripts/check-standard.mjs",
|
|
78
|
+
"family:readme": "node scripts/family-readme.mjs",
|
|
79
|
+
"docs:site": "pnpm build && node scripts/docs-site.mjs build",
|
|
80
|
+
"size": "node scripts/docs-site.mjs size",
|
|
81
|
+
"test:usage": "pnpm site && node scripts/check-usage.ts",
|
|
82
|
+
"test:demo": "pnpm site && node scripts/docs-site.mjs build && playwright test"
|
|
64
83
|
},
|
|
65
84
|
"dependencies": {
|
|
66
|
-
"@johnmorrisdotca/kazoku-ui": "^0.
|
|
85
|
+
"@johnmorrisdotca/kazoku-ui": "^0.12.0"
|
|
67
86
|
},
|
|
68
87
|
"peerDependencies": {
|
|
69
88
|
"three": ">=0.160.0"
|
|
@@ -74,10 +93,33 @@
|
|
|
74
93
|
}
|
|
75
94
|
},
|
|
76
95
|
"devDependencies": {
|
|
96
|
+
"@angular/common": "^22.2.4",
|
|
97
|
+
"@angular/compiler": "^22.2.4",
|
|
98
|
+
"@angular/core": "^22.2.4",
|
|
99
|
+
"@angular/platform-browser": "^22.2.4",
|
|
100
|
+
"@biomejs/biome": "2.6.4",
|
|
77
101
|
"@johnmorrisdotca/uchusen-rockets": "0.2.2",
|
|
102
|
+
"@playwright/test": "1.64.0",
|
|
103
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
104
|
+
"@types/node": "^24.19.2",
|
|
105
|
+
"@types/react": "^19.3.0",
|
|
106
|
+
"@types/react-dom": "^19.3.0",
|
|
107
|
+
"@types/three": "^0.187.0",
|
|
108
|
+
"@vitejs/plugin-vue": "^6.0.10",
|
|
109
|
+
"esbuild": "^0.25.12",
|
|
110
|
+
"marked": "^18.1.3",
|
|
111
|
+
"pagefind": "^1.6.0",
|
|
78
112
|
"playwright": "1.64.0",
|
|
113
|
+
"react": "^19.3.1",
|
|
114
|
+
"react-dom": "^19.3.1",
|
|
115
|
+
"rxjs": "^7.8.2",
|
|
116
|
+
"svelte": "^5.57.3",
|
|
79
117
|
"three": "0.186.1",
|
|
80
|
-
"typescript": "5.9.3"
|
|
118
|
+
"typescript": "5.9.3",
|
|
119
|
+
"vite": "^8.3.5",
|
|
120
|
+
"vue": "^3.5.44",
|
|
121
|
+
"webpack": "^5.112.2",
|
|
122
|
+
"webpack-cli": "^7.3.1"
|
|
81
123
|
},
|
|
82
124
|
"publishConfig": {
|
|
83
125
|
"access": "public"
|
|
@@ -90,5 +132,10 @@
|
|
|
90
132
|
},
|
|
91
133
|
"bugs": {
|
|
92
134
|
"url": "https://github.com/johnmorrisdotca/fuda-cards/issues"
|
|
135
|
+
},
|
|
136
|
+
"pnpm": {
|
|
137
|
+
"onlyBuiltDependencies": [
|
|
138
|
+
"esbuild"
|
|
139
|
+
]
|
|
93
140
|
}
|
|
94
141
|
}
|