@johnmorrisdotca/fuda-cards 0.9.1 → 0.10.1

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 (35) hide show
  1. package/README.md +382 -58
  2. package/dist/collection-element.d.ts +13 -0
  3. package/dist/collection-element.js +20 -2
  4. package/dist/live-3d.d.ts +43 -0
  5. package/dist/live-3d.js +161 -0
  6. package/docs/API.md +793 -0
  7. package/docs/collection-displays.md +1 -1
  8. package/docs/guides/accessibility-and-theming.md +62 -0
  9. package/docs/guides/architecture.md +53 -0
  10. package/docs/guides/binder-and-piles.md +83 -0
  11. package/docs/guides/card-element.md +65 -0
  12. package/docs/guides/collections.md +86 -0
  13. package/docs/guides/frameworks.md +105 -0
  14. package/docs/guides/getting-started.md +94 -0
  15. package/docs/guides/ja/accessibility-and-theming.md +62 -0
  16. package/docs/guides/ja/architecture.md +53 -0
  17. package/docs/guides/ja/binder-and-piles.md +83 -0
  18. package/docs/guides/ja/card-element.md +65 -0
  19. package/docs/guides/ja/collections.md +86 -0
  20. package/docs/guides/ja/frameworks.md +105 -0
  21. package/docs/guides/ja/getting-started.md +94 -0
  22. package/docs/guides/ja/live-3d.md +75 -0
  23. package/docs/guides/ja/materials-and-stacks.md +73 -0
  24. package/docs/guides/ja/motion-and-spin.md +73 -0
  25. package/docs/guides/ja/troubleshooting.md +60 -0
  26. package/docs/guides/ja/upgrading.md +56 -0
  27. package/docs/guides/ja/wear.md +63 -0
  28. package/docs/guides/live-3d.md +75 -0
  29. package/docs/guides/materials-and-stacks.md +73 -0
  30. package/docs/guides/motion-and-spin.md +73 -0
  31. package/docs/guides/troubleshooting.md +60 -0
  32. package/docs/guides/upgrading.md +56 -0
  33. package/docs/guides/wear.md +63 -0
  34. package/docs/live-3d.md +59 -0
  35. package/package.json +29 -6
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: 素材と山
3
+ section: how-to
4
+ order: 3
5
+ description: 実際のカード用紙、プラスチック、金属と同じ厚みをカードに持たせ、デッキ全体を、乱れ具合とシードを決めた1つの山として描きます。
6
+ ---
7
+
8
+ Fudaのカードには厚みがあり、カードの山の高さは、枚数にカード1枚の厚みをかけたものになります。どちらも幅63 mmのカードの大きさを基準に実寸の比率で描かれるので、52枚のデッキは52枚分の高さに見えます。
9
+
10
+ ![厚み4.5 mmのカードを、縁が見えるように回したところ(スマートフォン)](../../images/thick-phone-light.webp)
11
+
12
+ ## 厚み
13
+
14
+ `thickness`はミリメートルです。初期値は`0.3`(約12 ptの用紙)で、`0`は平らなカードです。`material`を指定すると、実際の用紙の厚みと縁の色が使われます。`thickness`を併せて指定すると、そちらが優先されます。
15
+
16
+ ```html
17
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
18
+ <fuda-card title="Thin" thickness="0.3"></fuda-card>
19
+ <fuda-card title="Trading card, 130 pt" material="card-130pt"></fuda-card>
20
+ <fuda-card title="Metal" material="steel-0.5"></fuda-card>
21
+ ```
22
+
23
+ 素材の厚みはすべて、メーカーのページまたは規格から読み取ったもので、[docs/materials.md](../../materials.md)の表に出典と引用があります(英語)。IDは4つのグループに分かれます。カード用紙の`paper-250`、`paper-310-black-core`、`paper-350`、銀行カードサイズの`plastic-id1`、厚手のトレーディングカードの`card-35pt`から`card-180pt`と`booklet-175pt`、金属の`aluminium-0.8`と`steel-0.5`です。コードからも読めます。
24
+
25
+ ```ts
26
+ import { cardMaterials, mmPerPoint } from '@johnmorrisdotca/fuda-cards';
27
+
28
+ const thick = cardMaterials.filter((material) => material.group === 'thick-card');
29
+ console.log(thick.length, thick[0].id, thick[0].thicknessMm);
30
+ console.log(130 * mmPerPoint);
31
+ // 7 card-35pt 0.889
32
+ // 3.302
33
+ ```
34
+
35
+ 縁の色は見た目の設定で、測定値ではありません。好みの色にするには、カードに`--fuda-edge`を指定します。任意のCSS背景が使えます。
36
+
37
+ ## 山
38
+
39
+ `stack="52"`は52枚のカードを描きます。一番上は実際のカード要素で、その下のかたまりは、カード1枚ごとに細い線を引いた1つのブロックです。枚数は自由で、1から1000です。
40
+
41
+ ```html
42
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
43
+ <fuda-card title="Deck" material="paper-310-black-core" stack="52" stack-messiness="0.6" stack-seed="7" stack-depth="10"></fuda-card>
44
+ ```
45
+
46
+ | 属性 | 範囲 | 初期値 | 意味 |
47
+ |---|---|---|---|
48
+ | `stack` | 1から1000 | 1 | カードの枚数。 |
49
+ | `stack-messiness` | 0から1 | 0.3 | 0は揃っている、1はとても乱れている。 |
50
+ | `stack-seed` | 整数 | 1 | 同じシードなら、同じ山が同じように積まれる。 |
51
+ | `stack-depth` | 0から52 | 10 | 一番上の下にあるカードのうち、少しずらして回した状態で並べる枚数。 |
52
+
53
+ 山の上にカードを1枚足しても、下のカードは動きません。各カードの位置は、下から数えた番号で決まるからです。一番上の下にあるカードは文字も絵もない平らな静止画で、52枚の山の描画量は11枚の山と変わりません。山は静止中は何も描かず、52枚の山がフレームを要求しないことをテストで確かめています。
54
+
55
+ `stackPresets`は出典のある4つの枚数です。トランプ2種類(52枚と54枚)、ポケモンのデッキ60枚、ブースターパック10枚です。ページにカードを置かなくても、山の高さを計算できます。
56
+
57
+ ```ts
58
+ import { cardMaterial, stackHeightMm, stackLayout, stackPresets } from '@johnmorrisdotca/fuda-cards';
59
+
60
+ const stock = cardMaterial('paper-310-black-core');
61
+ console.log(stackHeightMm(52, stock?.thicknessMm ?? 0.3));
62
+ console.log(stackPresets.map((preset) => preset.count).join(' '));
63
+ console.log(stackLayout(5, { messiness: 0, seed: 1 }).length);
64
+ // 16.9
65
+ // 52 54 60 10
66
+ // 4
67
+ ```
68
+
69
+ ![52枚のカードの山を表示したカードスタジオ。乱れ具合は少し高め](../../images/stack-desk-light.webp)
70
+
71
+ ## スクリプトから山を読む
72
+
73
+ `card.stackCount`と`card.stackHeight`(ミリメートル)は読み取り専用です。山を扇状に開いたりカードを取り出したりするには、[バインダーと山](binder-and-piles.md)を参照してください。きれいから乱れまでの山という考え方は、[toranpu](https://github.com/johnmorrisdotca/toranpu)から来ています。
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: 動きと回転
3
+ section: how-to
4
+ order: 5
5
+ description: 縦長の画像をパンさせ、フォーカスしたカードで自動再生し、カード全体を回し、自分の操作で回転を動かします。
6
+ ---
7
+
8
+ カードの上で動くものは3つあり、互いに独立しています。**画像**はパンでき、**カード**は回転でき、カードは**裏返せます**(`flipped`。[カード要素](card-element.md)を参照)。閲覧者のシステムが動きの軽減を求めている場合は、どれも止まります。
9
+
10
+ ## 画像を動かす
11
+
12
+ スロットに`<img>`を入れたカードに`motion="pan"`を付けると、縦長の画像でAnimateボタンが使えます。ボタンは画像の角にある小さな再生・一時停止の印で、ポインターを重ねるかフォーカスするまでは薄く描かれます。タップやクリックできる範囲は48 px四方、アクセシブルな名前は「Animate the picture」で、動いているかどうかは`aria-pressed`が示します。
13
+
14
+ ```html
15
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
16
+ <fuda-card title="Starship" motion="pan" pan-direction="down" style="--fuda-pan-duration: 16s">
17
+ <img src="starship.jpg" alt="Starship">
18
+ </fuda-card>
19
+ ```
20
+
21
+ | 属性・プロパティ | 意味 |
22
+ |---|---|
23
+ | `motion="pan"` | パンを許可し、ボタンを表示する。 |
24
+ | `playing` | 動き始める。ホストが付け外しでき、ボタンで切り替わる。 |
25
+ | `pan-direction` | `down`(初期値)、または下から始まる`up`。 |
26
+ | `pan-loop` | `alternate`(初期値、往復)、または`restart`。 |
27
+ | `--fuda-pan-duration` | 1回の移動の時間。`16s`のようなCSSの時間。 |
28
+ | `--fuda-focus-x`、`--fuda-focus-y` | 静止画で中心にする位置。`50%`と`20%`など。 |
29
+ | `moving` | 画像が動いている間、カードが付ける。スタイル用で、読み取り専用。代わりに`playing`か`autoplay`を設定する。 |
30
+
31
+ 画像が幅いっぱいに広がったあとで、カードの表示枠より縦に長くなければ、動く距離がなく、パンしません。
32
+
33
+ ## フォーカスしたときの自動再生
34
+
35
+ `autoplay="focus"`は、カードがフォーカスされている間、画像を自動で動かします。フォーカスされるカードは同時に1枚だけで、マウスポインターの下にあるカード、キーボードのフォーカスを持つカード(Tabでボタンへ)、タッチ画面では最後にタップしたカードです。フォーカスが移ると、前のカードは静止画に戻るので、行やグリッドの中で動くのは常に1枚だけです。ボタンは残り、押すと次にフォーカスされるまで一時停止します。`prefers-reduced-motion: reduce`のときは、自動再生は始まりません。
36
+
37
+ ```html
38
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
39
+ <fuda-card title="Starship" motion="pan" autoplay="focus">
40
+ <img src="starship.jpg" alt="Starship">
41
+ </fuda-card>
42
+ ```
43
+
44
+ ## カード全体を回す
45
+
46
+ `card-spin="center"`は、カード全体を縦の中心軸でゆっくり3Dで回します。`card-spin="corner"`はアイススケーターのように、左下の角を通る縦軸で1周します。その角は要素の中央で動かず、半周したところで裏が見えます。角を軸にした回転は、その点の両側へ大きく振れるので、余白を取ってください。ステージは、カードの幅の約3倍、高さの約2倍が目安です。
47
+
48
+ ```html
49
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
50
+ <fuda-card title="Explorer" card-spin="center" style="--fuda-card-spin-duration: 30s"></fuda-card>
51
+ <fuda-card title="Skater" card-spin="corner" card-spin-direction="reverse" card-spin-paused></fuda-card>
52
+ ```
53
+
54
+ 初期値は180秒で1周です。`--fuda-card-spin-duration`には正のCSS時間を指定します。`card-spin-direction="reverse"`で逆回転、`card-spin-paused`でその角度に一時停止(外すと再開)、`card-spin`を外すと止まって元に戻ります。
55
+
56
+ ## 回転を自分で動かす
57
+
58
+ 真偽値の`card-view`属性を付けると、内蔵のアニメーションの代わりに、自分で設定する2つのCSSカスタムプロパティ`--fuda-yaw`と`--fuda-tilt`(角度)で動きます。回転の中心は、これまでどおり`card-spin`で選んだものです。カードスタジオはこれを、kazoku-uiの表示操作と組み合わせて使っています。表示操作は、全体のステージも拡大・移動できるので、回転の全体をいつでも見られます。
59
+
60
+ ```html
61
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
62
+ <fuda-card id="driven" title="By hand" card-view style="--fuda-yaw: 40deg; --fuda-tilt: 10deg"></fuda-card>
63
+ <script type="module">
64
+ const card = document.querySelector('#driven');
65
+ card.style.setProperty('--fuda-yaw', '-30deg');
66
+ </script>
67
+ ```
68
+
69
+ ![カードを約24度回したカードスタジオ。下に角度のスライダーがある](../../images/studio-desk-light.webp)
70
+
71
+ ## 動きの軽減
72
+
73
+ `prefers-reduced-motion: reduce`のときは、カードの回転、裏返しの遷移、画像のパン、自動再生がすべて無効になり、カードは静止画のままになります。回転は装飾です。面を選ぶには、回転ではなく`flipped`属性を使ってください。
@@ -0,0 +1,60 @@
1
+ ---
2
+ title: 困ったとき・よくある質問
3
+ section: troubleshooting
4
+ order: 12
5
+ description: カードが空白、画像がちらつく、コレクションが何も出ない、ズームバーがない、カードが回らないなど、うまくいかないときの対処です。
6
+ ---
7
+
8
+ ## カードが現れる前に画像がちらつく
9
+
10
+ スクリプトが`<fuda-card>`を定義するまで、ブラウザーは`<img>`を元の大きさで描くので、画像全体が枠に入る前に見えてしまいます。次の1行を、`<head>`の中で、スクリプトと自分のスタイルより前に置いてください。カードは見えないまま、カードの大きさの場所だけが確保されるので、現れても何も動きません。
11
+
12
+ ```html no-check
13
+ <style>fuda-card:where(:not(:defined)){display:inline-block;width:300px;aspect-ratio:2.5/3.5;overflow:hidden;visibility:hidden}fuda-collection:where(:not(:defined)){display:block;min-height:calc(var(--fuda-stage-height,clamp(300px,calc(100svh - 440px),620px)) + 380px)}</style>
14
+ ```
15
+
16
+ 定義されたあとも、カードは画面上の大きさを持ち、スロットのすべての画像が読み込まれるまで画像を隠し、それからフェードインさせます(動きの軽減のときはフェードなし)。スクリプトが実行されないと、カードは空白のままです。そのときに画像をそのまま見せたければ、`<noscript><style>fuda-card:not(:defined){visibility:visible}</style></noscript>`を加えてください。
17
+
18
+ ## カードが空白のまま
19
+
20
+ 要素が登録されていません。`@johnmorrisdotca/fuda-cards/element`が、ブラウザーで動くコードの中で1回インポートされているか、パスやインポートマップが解決できているか(ネットワークのパネルに404が出ます)、中の画像が読み込まれているかを確かめてください。画像はスロットのすべてが読み込まれるまで隠されます。画像の読み込みに失敗すると、枠は空のままになります。
21
+
22
+ ## 「HTMLElement is not defined」
23
+
24
+ `element`か`collection-element`をサーバーでインポートしています。これらは評価時に`HTMLElement`を継承します。ブラウザーだけでインポートしてください([フレームワークとバンドラー](frameworks.md#サーバーサイドレンダリング)を参照)。メインのエントリーと`@johnmorrisdotca/fuda-cards/collection`は、サーバーでも安全です。
25
+
26
+ ## コレクションに何も表示されない
27
+
28
+ `cards`はプロパティです。HTMLに`cards='[...]'`と書いても何も起きません。スクリプトで配列を確かめ、`parseCollection`に通してください。最初の不正な項目を示す`Error`を投げます(`name`や`image`がない、`id`の重複、`card`でも`object`でもない`kind`、不正な`metadata`)。
29
+
30
+ ## ズームバーがない、またはコンソールに`@johnmorrisdotca/kazoku-ui/view-controls/define`を解決できないと出る
31
+
32
+ バンドラーのないページでは、コレクションにその名前のインポートマップが要ります([フレームワークとバンドラー](frameworks.md#インポートマップを使うふつうのhtml)を参照)。カード1枚の`<fuda-card>`には要りません。
33
+
34
+ ## 角度、傾き、自動回転が出ない
35
+
36
+ カードを1枚も含まないコレクション(すべての項目が`kind: 'object'`)には、回るものがないので、これらは出ず、URLにも角度が含まれません。山以外の平らな表示も、回りません。
37
+
38
+ ## 何も動かない
39
+
40
+ 要素の`animate="off"`と、システムの動きの軽減の設定を確かめてください。動きの軽減がオンのときは、カードの回転、パン、自動再生、ライブ3Dのカードは、仕様として止まります。`autoplay="focus"`には`motion="pan"`が必要です。画像をカードの幅いっぱいに広げたとき、表示枠より縦に長くないと、動く距離がありません。
41
+
42
+ ## 取り出したカードを置く余白がない
43
+
44
+ `pile-controls`は、カードの下に3つのボタンを描きます。カードの下に約70 pxの余白を残してください。開いた扇や脇の山はカードの外まで広がります。`card.pileBounds`を読むか、`fuda-pile`を待ち受けて、レイアウトを合わせてください。
45
+
46
+ ## `wear`が何も表示しない
47
+
48
+ `perfect`、空の値、未知の名前、度合いがすべて0の場合は、意図して何も描きません。`wearPresets`と綴りを照らし合わせてください。摩耗は、`<fuda-collection>`の画像や、山の一番上より下のカードには描かれません。
49
+
50
+ ## 縁がおかしい、影で3Dが平らになる
51
+
52
+ ドロップシャドウは要素そのものに付いたフィルターです。カードとその面の間にある要素に`filter`を付けると3Dが平らになり、裏面が鏡像で見えます。フィルターを外すか、`--fuda-edge`で縁の色を変えてください。
53
+
54
+ ## ライブ3Dが始まらない
55
+
56
+ 動きの軽減のとき、WebGLがないとき、コンテキストを失ったあと、ほかのカードがフォーカスを持っている間は、カードは画像のままです。どの場合も`live.focus(card)`は`false`になります。`load`が`three`のモジュールを返していること、`item.build`がシーン、カメラ、`object`を返していることを確かめてください。
57
+
58
+ ## 質問
59
+
60
+ **フレームワークは必要ですか。** いいえ。**何かを取得しますか。** 渡された画像のURLだけを、閲覧者のブラウザーで取得します。**何かを保存しますか。** いいえ。デモは名前を付けたコレクションをブラウザーのlocalStorageに保存しますが、パッケージは保存しません。**アクセシブルですか。** 組み込まれているものと確かめた範囲は、[アクセシビリティとテーマ](accessibility-and-theming.md)を参照してください。
@@ -0,0 +1,56 @@
1
+ ---
2
+ title: アップグレード
3
+ section: upgrading
4
+ order: 13
5
+ description: 0.1から0.10まで、各バージョンで対応が必要な変更と、以前のバージョンから今も使えるものをまとめます。
6
+ ---
7
+
8
+ このパッケージは初期開発中(0.x)で、マイナーリリースごとにインターフェースが増えることがあります。このページには、対応が必要なものだけを書きます。日付つきの完全な記録は[変更履歴](../../../CHANGELOG.md)にあります。
9
+
10
+ ## 0.10へ
11
+
12
+ - `@johnmorrisdotca/kazoku-ui`は`^0.10.0`です。ズームバーは、本当のズーム値を1つの数字(`1.3×`)で示すようになりました。以前の`2×`は数字のように見えるプリセットでした。数字を押すとFitに戻ります。バーの基本は、角度、自動回転、ズーム、Fitで、**More**で傾き、正面、矢印パッドが加わります。
13
+ - ライブ3Dが新しくなりました。`@johnmorrisdotca/fuda-cards/live-3d`と`collection.live`です。`three`は省略可能なピア依存です。[カード内のライブ3D](live-3d.md)を参照してください。
14
+ - テスト:`playwright` 1.64.0が開発依存になり、ブラウザーのテストはソフトウェア描画のヘッドレスだけで動きます。
15
+
16
+ ## 0.9へ
17
+
18
+ - 項目に`kind`が加わりました。`"card"`(初期値)か`"object"`です。この項目ができる前に書いたコレクションは、すべてカードのままです。オブジェクトは裏返りません。ゲーム機やトロフィーには`kind: 'object'`を付けてください。新しいエクスポート:`collectionKinds`、`isCard`、`CollectionKind`。
19
+ - 裏返す途中でカードが透けることはなくなりました。対応は要りません。
20
+
21
+ ## 0.8へ
22
+
23
+ - **ジュークボックス・カルーセルとフリップタワーは表示から削除されました。** `view="jukebox"`と`view="tower"`は今もデッキを開きます(`collectionViewAliases`)。`collectionViews`は10種類の表示を挙げます。無限カードアトラスはカードテーブルになりました。`view="atlas"`は変わりません。
24
+ - バインダーは、リングかジップの本物のシートになりました。新しい設定:`binder`、`cover`、`sheet`、`pockets`。以前からの`page-size`と`columns`も使えます。
25
+
26
+ ## 0.7へ
27
+
28
+ - すべての山が扇状に開き、回り、カードを取り出せます。`<fuda-card>`に加わったもの:`fan`、`taken-off`、`deck-land`、`pile-controls`、`takeOff()`、`putBack()`、`pileBounds`、イベント`fuda-pile`。
29
+ - **`animate`は、属性がないときはオンです。** 0.6.0のようにぱっと切り替えたい場合は`animate="off"`にします。
30
+ - `fan-size`は2から10になりました(以前は2から20)。
31
+
32
+ ## 0.6へ
33
+
34
+ - `deck-land="upside-down"`は追加されましたが、0.6.1で誤りと分かりました(カードは同じ面の中で半回転するわけではないため)。今も使え、`face-down`の意味です。`normalizeLanding`で値を変換できます。
35
+ - **ページの`<head>`にある1行のCSSを更新してください。** 未定義の`<fuda-collection>`は、表示に加えて380 pxの場所を確保します(以前は200 px)。表示ボタンでコンポーネントが高くなったためです。その1行は[困ったとき・よくある質問](troubleshooting.md#カードが現れる前に画像がちらつく)にあります。
36
+ - 表示の選択は、ドロップダウンではなくボタンの列になり、`theme="light|dark"`で配色を選べます。
37
+
38
+ ## 0.5と0.4へ
39
+
40
+ - `wear`(0.5)と、`material`、`stack`(0.4)が新しく加わりました。これらのないカードは変わらず、そのコードも読み込みません。
41
+
42
+ ## 0.2へ
43
+
44
+ - **`@johnmorrisdotca/kazoku-ui`は実行時の依存になりました。** バンドラーのないページでは、`@johnmorrisdotca/kazoku-ui/view-controls/define`のインポートマップが要ります。[フレームワークとバンドラー](frameworks.md)を参照してください。
45
+ - `<fuda-collection>`の`address`属性が、表示の状態をページのURLに保ちます。
46
+
47
+ ## アップグレードの確認
48
+
49
+ ```ts
50
+ import { collectionViewAliases, collectionViews, normalizeLanding } from '@johnmorrisdotca/fuda-cards/collection';
51
+
52
+ console.log(collectionViews.map((view) => view.id).join(' '));
53
+ console.log(collectionViewAliases.jukebox, normalizeLanding('upside-down'));
54
+ // deck rolodex binder case random story wall spotlight atlas fan
55
+ // deck face-down
56
+ ```
@@ -0,0 +1,63 @@
1
+ ---
2
+ title: 摩耗
3
+ section: how-to
4
+ order: 4
5
+ description: 使い込んだカードを、ミントから破損まで、プリセット、シード、種類ごとのつまみで描きます。
6
+ ---
7
+
8
+ `wear`は、使われたあとのカードの見た目を描きます。柔らかくなった角、丸まった角、欠けた角、折れた角、縁の白化、折り目、傷、点状の汚れ、しみ、黄ばみ、中心からずれた印刷です。`wear`属性のないカードは、以前とバイト単位で同じです。摩耗のコードは別のモジュールで、カードが摩耗を求めたときだけ読み込まれます。
9
+
10
+ ![強く使い込んだカード。折れた角、欠けた縁、傷、折り目がある](../../images/wear-desk-light.webp)
11
+
12
+ ## 使い方
13
+
14
+ ```html
15
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
16
+ <fuda-card title="Rookie" wear="moderately-played" wear-seed="7"></fuda-card>
17
+ <fuda-card title="Half worn" wear="0.5"></fuda-card>
18
+ <fuda-card title="Only the corners" wear-corners="0.9"></fuda-card>
19
+ ```
20
+
21
+ `wear`には、プリセットのID、またはすべての度合いを一度に決める0から1の数を指定します。プリセットは、一般的な状態評価の言葉で、`mint`、`near-mint`、`lightly-played`、`moderately-played`、`heavily-played`、`damaged`です。`perfect`、属性なし、パッケージが知らない名前は、何も描きません。`wear-corners`、`wear-edges`、`wear-surface`、`wear-creases`(それぞれ0から1)は、プリセットに重ねて、1種類だけを変えます。
22
+
23
+ ## シード
24
+
25
+ `wear-seed`(整数、初期値1)は、傷や汚れの位置を決めます。カードはどの端末でも毎回同じに見えます。同じシードなら同じ位置に同じ印が付き、別のシードなら別の印になります。描画時に乱数は使わず、動くこともありません。
26
+
27
+ ## データとしての摩耗
28
+
29
+ パッケージは、ページに触れずに仕組み全体を公開しているので、`<fuda-card>`以外にも使い込んだカードを描けます。ポスター、PDF、サーバーで作る画像などです。
30
+
31
+ ```ts
32
+ import { wearLayout, wearLevels, wearOverlaySvg, wearPreset, wearPresets } from '@johnmorrisdotca/fuda-cards';
33
+
34
+ console.log(wearPresets.length);
35
+ console.log(wearPreset('lightly-played')?.says);
36
+ const levels = wearLevels({ wear: 'lightly-played', seed: 7 });
37
+ console.log(JSON.stringify(levels));
38
+ const layout = levels && wearLayout(levels, 7);
39
+ console.log(layout?.corners.map((corner) => corner.kind).join(' '));
40
+ console.log(layout ? wearOverlaySvg(layout, 'front').startsWith('<svg') : false);
41
+ console.log(wearLevels({ wear: 'perfect' }));
42
+ // 7
43
+ // Very slight corner rounding, whitening on one or two edges, scratches seen when tilted.
44
+ // {"corners":0.38,"edges":0.45,"surface":0.4,"creases":0,"toning":0.05,"centering":0.3}
45
+ // rounded rounded soft soft
46
+ // true
47
+ // null
48
+ ```
49
+
50
+ `wearLevels`は、カードが求める度合いを返し、何も求めていなければ`null`を返します。つまり`null`は「何も描かない」の意味です。`wearLayout(levels, seed)`はすべての印の位置を返し、`wearOutline`は欠けた角や折れた角を含むカードの輪郭をパスとして返し、`wearOverlaySvg`は表か裏の印をSVGの文字列として返します。
51
+
52
+ ## 描かれるもの
53
+
54
+ | 種類 | 見え方 | どの度合いから |
55
+ |---|---|---|
56
+ | 角 | 鋭い、柔らかい、丸い、欠けた、折れた(裏が見える折り返し)。折れた角は最大1つ、欠けた角は最大2つ。 | すべて |
57
+ | 縁 | 4辺に沿った、むき出しの用紙のクリーム色の細かい点。 | すべて |
58
+ | 表面 | 細く明るい傷と、暗いまたは明るい点状の汚れ。 | すべて |
59
+ | 折り目 | 明るい側と影の側を持つ曲線。強いものは印刷も途切れさせる。 | `moderately-played`以上 |
60
+ | 変色としみ | 縁に向かう黄褐色の暗がり。強く使うと柔らかいしみ。 | `lightly-played`以上 |
61
+ | 中心ずれ | 印刷が、幅300 pxで最大横7 px、縦5 pxずれる。 | すべて |
62
+
63
+ 状態評価の言葉は、評価会社自身のページに記載がなかったため、二次的な資料から取っています。出典と各プリセットの度合いは[docs/wear.md](../../wear.md)にあります(英語)。プリセットは、これらの言葉をこのパッケージなりに読み取ったもので、公式のグレードではありません。摩耗は、`<fuda-collection>`の画像や、山の一番上より下のカードには描かれません。
@@ -0,0 +1,75 @@
1
+ ---
2
+ title: Live 3D in a card
3
+ section: how-to
4
+ order: 8
5
+ description: Let one card at a time turn in real 3D on a single WebGL context, with every other card a picture, using the live-3d module and your own three.js.
6
+ ---
7
+
8
+ A shelf of fifty cards cannot each hold a WebGL context: every card live was measured at 41 contexts (the browser's limit is about 16), 24 cards dropped to a fallback and 40 cards made 108,654 draws in three seconds. `@johnmorrisdotca/fuda-cards/live-3d` is the focus policy that avoids it: **only one card is ever live, on one context for the whole page; every other card is a picture, and a page of pictures loads no 3D code at all.**
9
+
10
+ ## Use it
11
+
12
+ `three` is yours: an optional peer dependency (`>=0.160.0`), loaded by the function you give as `load` at the first focus.
13
+
14
+ ```ts no-check
15
+ import { createLiveCards } from '@johnmorrisdotca/fuda-cards/live-3d';
16
+
17
+ const live = createLiveCards({ load: () => import('three') }); // loads nothing yet
18
+
19
+ const rocket = {
20
+ key: 'rocket:starship', // cards with the same key share their pictures
21
+ async build({ three, assets, width, height }: any) {
22
+ const scene = new three.Scene();
23
+ const camera = new three.PerspectiveCamera(30, width / height, 0.01, 1000);
24
+ const object = new three.Mesh(new three.BoxGeometry(1, 2, 1), new three.MeshNormalMaterial());
25
+ scene.add(object);
26
+ camera.position.z = 5;
27
+ return { scene, camera, object, resize: (w: number, h: number) => { camera.aspect = w / h; camera.updateProjectionMatrix(); } };
28
+ },
29
+ };
30
+
31
+ const card = document.querySelector('fuda-card') as HTMLElement;
32
+ const off = live.add(card, rocket, { still: card.querySelector('img') as HTMLImageElement });
33
+ // later: off() takes the card out; live.dispose() lets go of the renderer
34
+ ```
35
+
36
+ `item.build` returns a scene, a camera and `object`, the thing that turns about its upright axis. Take every geometry, material, texture and model through `assets.acquire` when several cards share them, so one copy is kept ([the shared renderer's guide](https://github.com/johnmorrisdotca/kazoku-ui/blob/main/docs/renderer.md) explains it).
37
+
38
+ ## What `createLiveCards` gives back
39
+
40
+ | Member | What it does |
41
+ |---|---|
42
+ | `add(card, item, { still })` | Makes a card live on focus; gives back the function that takes it off. `still` is a picture the card already has: with one, the card costs no 3D code until it is in focus. |
43
+ | `focus(card)` | Puts this card in focus. False if it did not go live: another took it, reduced motion, or no WebGL. |
44
+ | `blur()` | No card in focus: the live one freezes to a picture and nothing draws. |
45
+ | `focused` | The card in focus, if any. |
46
+ | `stats` | The renderer's own figures; undefined until it has been needed. |
47
+ | `renderer` | The shared renderer; undefined until it has been needed. |
48
+ | `dispose()` | Takes every card off and lets go of the renderer. |
49
+
50
+ Options: `turnSeconds` (12 seconds for a turn; 0 does not turn it), `dwellMs` (150 ms the pointer must rest on a card), `lookAheadPx` (300 px outside the view where a card with no picture of its own gets its still made), and the renderer's own (`maxPixels`, `maxSide`, `stillSize`, `stillBytes`, `lingerMs`, `releaseMs`, `onContext`).
51
+
52
+ ## In a collection
53
+
54
+ ```ts no-check
55
+ import '@johnmorrisdotca/fuda-cards/collection-element';
56
+ import { createLiveCards } from '@johnmorrisdotca/fuda-cards/live-3d';
57
+
58
+ const live = createLiveCards({ load: () => import('three') });
59
+ const collection = document.querySelector('fuda-collection') as HTMLElement & { live: unknown };
60
+ collection.live = { cards: live, item: (card: { id: string }) => ({ key: card.id, build: async () => { throw new Error('make your scene here'); } }) };
61
+ ```
62
+
63
+ Every display then goes live on the card in focus.
64
+
65
+ ## The rules
66
+
67
+ - **One card live at a time.** The card under the pointer after a rest of `dwellMs`, the one holding keyboard focus, the one last pressed. A pointer passing over a page of cards starts nothing. Leaving the card, or pressing elsewhere, ends it.
68
+ - **The old card freezes at its last angle,** and its still is made from the same context at that angle (shared per 5 degrees), so it goes on from there when focused again.
69
+ - **Reduced motion: no live card.** The card stays its picture and no 3D code loads.
70
+ - **Nothing runs at rest.** No frame is asked for, and nothing is drawn, with no card in focus, out of sight or in a hidden tab.
71
+ - **No WebGL, or a lost context:** the card stays its picture, and draws again on a restored context.
72
+
73
+ ## Budgets, held by a test
74
+
75
+ `pnpm test:freeze` (`test/e2e/live-3d.e2e.mjs`) holds these: 1 WebGL context over 30 focus changes, never more than one canvas; 0 draws, 0 frame requests and 0 frame callbacks over 2 seconds at rest; none while out of sight or in a hidden tab; GPU objects that do not grow after the first round; a canvas within 6 megapixels and 4096 a side on a 5120 by 2880 screen at ratio 2; and no `three`, renderer or model fetched before the first focus. `dist/live-3d.js` is 7.5 KB, 2.3 KB gzipped. The tests draw in software, so they prove the counts and nothing about a real GPU: frame times, driver behaviour and GPU memory are not measured. Try it in the [live 3D demo](https://johnmorrisdotca.github.io/fuda-cards/demo/live-3d.html).
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: Materials and stacks
3
+ section: how-to
4
+ order: 3
5
+ description: Give a card the true thickness of real card stock, plastic or metal, and draw a whole deck as one stack, with a messiness and a seed you control.
6
+ ---
7
+
8
+ A Fuda card has a thickness, and a stack of cards is as high as its count times that thickness. Both are drawn to scale at the 63 mm wide card size, so a deck of 52 looks as tall as a deck of 52 is.
9
+
10
+ ![A card 4.5 mm thick, turned so its edge shows, on a phone](../images/thick-phone-light.webp)
11
+
12
+ ## Thickness
13
+
14
+ `thickness` is in millimetres. The default is `0.3` (about 12 pt stock); `0` is a flat card. A `material` takes the thickness, and the edge colour, of a real stock, and `thickness` still overrides it.
15
+
16
+ ```html
17
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
18
+ <fuda-card title="Thin" thickness="0.3"></fuda-card>
19
+ <fuda-card title="Trading card, 130 pt" material="card-130pt"></fuda-card>
20
+ <fuda-card title="Metal" material="steel-0.5"></fuda-card>
21
+ ```
22
+
23
+ Every material's thickness was read from a maker's page or a standard, and the table in [docs/materials.md](../materials.md) names the source and quotes what it says. The ids come in four groups: `paper-250`, `paper-310-black-core` and `paper-350` (card stock), `plastic-id1` (a bank-size card), `card-35pt` to `card-180pt` and `booklet-175pt` (thick trading cards) and `aluminium-0.8` and `steel-0.5` (metal). Read them in code:
24
+
25
+ ```ts
26
+ import { cardMaterials, mmPerPoint } from '@johnmorrisdotca/fuda-cards';
27
+
28
+ const thick = cardMaterials.filter((material) => material.group === 'thick-card');
29
+ console.log(thick.length, thick[0].id, thick[0].thicknessMm);
30
+ console.log(130 * mmPerPoint);
31
+ // 7 card-35pt 0.889
32
+ // 3.302
33
+ ```
34
+
35
+ The edge colour is a look, not a measurement. Set `--fuda-edge` on the card to any CSS background to use your own.
36
+
37
+ ## Stacks
38
+
39
+ `stack="52"` draws 52 cards: the top card is the live card and the block under it is one piece with a fine line for each card. The count is free, 1 to 1000.
40
+
41
+ ```html
42
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
43
+ <fuda-card title="Deck" material="paper-310-black-core" stack="52" stack-messiness="0.6" stack-seed="7" stack-depth="10"></fuda-card>
44
+ ```
45
+
46
+ | Attribute | Range | Default | Meaning |
47
+ |---|---|---|---|
48
+ | `stack` | 1 to 1000 | 1 | How many cards. |
49
+ | `stack-messiness` | 0 to 1 | 0.3 | 0 squared up, 1 very messy. |
50
+ | `stack-seed` | whole number | 1 | The same seed lays the same stack the same way. |
51
+ | `stack-depth` | 0 to 52 | 10 | How many cards under the top one are laid out nudged and turned. |
52
+
53
+ A card put on top of the stack moves none of those under it, because each card's place depends on its number from the bottom. The cards under the top one are flat stills with no text, and a stack of 52 draws no more than one of 11. A stack draws nothing while it is at rest, and a test checks that a 52-card stack requests no frames.
54
+
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
+
57
+ ```ts
58
+ import { cardMaterial, stackHeightMm, stackLayout, stackPresets } from '@johnmorrisdotca/fuda-cards';
59
+
60
+ const stock = cardMaterial('paper-310-black-core');
61
+ console.log(stackHeightMm(52, stock?.thicknessMm ?? 0.3));
62
+ console.log(stackPresets.map((preset) => preset.count).join(' '));
63
+ console.log(stackLayout(5, { messiness: 0, seed: 1 }).length);
64
+ // 16.9
65
+ // 52 54 60 10
66
+ // 4
67
+ ```
68
+
69
+ ![The Card Studio showing a deck of 52 cards, messiness slightly up](../images/stack-desk-light.webp)
70
+
71
+ ## Reading a stack from script
72
+
73
+ `card.stackCount` and `card.stackHeight` (in millimetres) are read-only. To spread a stack open or take a card off it, see [Binders and piles](binder-and-piles.md). The idea of a pile from neat to messy comes from [toranpu](https://github.com/johnmorrisdotca/toranpu).
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: Motion and rotation
3
+ section: how-to
4
+ order: 5
5
+ description: Pan a tall picture, start it by itself on the card in focus, spin the whole card, and drive the turn from your own controls.
6
+ ---
7
+
8
+ Three separate things move on a card, and none depends on another: the **art** can pan, the **card** can spin, and the card can be **turned over** (`flipped`, see [The card element](card-element.md)). All of them stop when the reader's system asks for reduced motion.
9
+
10
+ ## Moving artwork
11
+
12
+ `motion="pan"` on a card with a slotted `<img>` enables an Animate button on a tall image. The button is a small play or pause mark in the corner of the art, drawn at half strength until you point at it or focus it. Its hit target is 48 px square, its accessible name is "Animate the picture" and `aria-pressed` says whether the art is moving.
13
+
14
+ ```html
15
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
16
+ <fuda-card title="Starship" motion="pan" pan-direction="down" style="--fuda-pan-duration: 16s">
17
+ <img src="starship.jpg" alt="Starship">
18
+ </fuda-card>
19
+ ```
20
+
21
+ | Attribute or property | Meaning |
22
+ |---|---|
23
+ | `motion="pan"` | Allows the pan and shows the button. |
24
+ | `playing` | Start moving. A host can add or remove it; the button toggles it. |
25
+ | `pan-direction` | `down` (default) or `up`, which starts at the bottom. |
26
+ | `pan-loop` | `alternate` (default, back and forth) or `restart`. |
27
+ | `--fuda-pan-duration` | The time of each pass, a CSS duration such as `16s`. |
28
+ | `--fuda-focus-x`, `--fuda-focus-y` | The focal point of the still, such as `50%` and `20%`. |
29
+ | `moving` | Set by the card while the art moves, for styling. Read-only: set `playing` or `autoplay` instead. |
30
+
31
+ If the image is not taller than the card's window after it fills the width, there is no vertical distance and nothing pans.
32
+
33
+ ## Autoplay on focus
34
+
35
+ `autoplay="focus"` moves the art by itself while the card is the card in focus. One card is in focus at a time: the card under the mouse, the card holding keyboard focus (tab to its button), or, on a touch screen, the card you last tapped. When focus moves, the first card returns to its still, so in a row or a grid only one card ever moves. The button stays, and pressing it pauses the card until the next time it takes focus. Autoplay never starts with `prefers-reduced-motion: reduce`.
36
+
37
+ ```html
38
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
39
+ <fuda-card title="Starship" motion="pan" autoplay="focus">
40
+ <img src="starship.jpg" alt="Starship">
41
+ </fuda-card>
42
+ ```
43
+
44
+ ## Spinning the whole card
45
+
46
+ `card-spin="center"` turns the whole card slowly in 3D about its vertical centre; `card-spin="corner"` spins it like an ice skater, a full turn about the vertical axis through its bottom-left corner, which stays still at the middle of the element and shows the back half way round. The corner spin sweeps out to both sides of that point, so give it room: a stage about three times the card's width and twice its height.
47
+
48
+ ```html
49
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
50
+ <fuda-card title="Explorer" card-spin="center" style="--fuda-card-spin-duration: 30s"></fuda-card>
51
+ <fuda-card title="Skater" card-spin="corner" card-spin-direction="reverse" card-spin-paused></fuda-card>
52
+ ```
53
+
54
+ The default is one turn every 180 seconds; `--fuda-card-spin-duration` is any positive CSS duration. `card-spin-direction="reverse"` reverses it, `card-spin-paused` pauses at the current angle and removing it resumes, and removing `card-spin` stops and resets the card.
55
+
56
+ ## Driving the turn yourself
57
+
58
+ Add the boolean `card-view` attribute and the built-in animation is replaced by two CSS custom properties you set: `--fuda-yaw` and `--fuda-tilt`, as angles. The pivot is still the one chosen by `card-spin`. The Card Studio does this with the view controls of kazoku-ui, which also zoom and pan the whole stage so the full sweep can always be seen.
59
+
60
+ ```html
61
+ <script type="module">import '@johnmorrisdotca/fuda-cards/element';</script>
62
+ <fuda-card id="driven" title="By hand" card-view style="--fuda-yaw: 40deg; --fuda-tilt: 10deg"></fuda-card>
63
+ <script type="module">
64
+ const card = document.querySelector('#driven');
65
+ card.style.setProperty('--fuda-yaw', '-30deg');
66
+ </script>
67
+ ```
68
+
69
+ ![The Card Studio with the card turned about 24 degrees and the angle slider under it](../images/studio-desk-light.webp)
70
+
71
+ ## Reduced motion
72
+
73
+ With `prefers-reduced-motion: reduce` the rotation, the flip transition, the pan and autoplay are all disabled and the card keeps its focused still. The spin is decorative: use the `flipped` attribute, not a spin, to choose the face.
@@ -0,0 +1,60 @@
1
+ ---
2
+ title: Troubleshooting and FAQ
3
+ section: troubleshooting
4
+ order: 12
5
+ description: Fixes for a blank card, a picture that flashes, a collection that shows nothing, a missing zoom bar, a card that does not turn and the other things that go wrong.
6
+ ---
7
+
8
+ ## The picture flashes before the card appears
9
+
10
+ Until the script has defined `<fuda-card>`, a browser draws your `<img>` at its natural size, so the whole picture shows before it moves into the frame. Put this one line in the `<head>`, before the script and your own styles. The card then stays invisible while its box is already reserved at the card's size, so nothing moves when it appears:
11
+
12
+ ```html no-check
13
+ <style>fuda-card:where(:not(:defined)){display:inline-block;width:300px;aspect-ratio:2.5/3.5;overflow:hidden;visibility:hidden}fuda-collection:where(:not(:defined)){display:block;min-height:calc(var(--fuda-stage-height,clamp(300px,calc(100svh - 440px),620px)) + 380px)}</style>
14
+ ```
15
+
16
+ Once the card is defined it also keeps the art invisible until it has a size on screen and every slotted image has loaded, then fades it in (no fade with reduced motion). If scripts never run, the card stays blank; add `<noscript><style>fuda-card:not(:defined){visibility:visible}</style></noscript>` if you want the plain picture then.
17
+
18
+ ## The card stays blank
19
+
20
+ The element is not registered. Check that `@johnmorrisdotca/fuda-cards/element` is imported once in code that runs in the browser, that the path or import map resolves (the network panel shows a 404), and that the picture inside has loaded: the art is hidden until every slotted image has loaded. A failed picture leaves the frame empty.
21
+
22
+ ## "HTMLElement is not defined"
23
+
24
+ You imported `element` or `collection-element` on a server. They extend `HTMLElement` when evaluated. Import them only in the browser (see [Frameworks and bundlers](frameworks.md#server-rendering)). The main entry and `@johnmorrisdotca/fuda-cards/collection` are safe on a server.
25
+
26
+ ## The collection shows nothing
27
+
28
+ `cards` is a property. Writing `cards='[...]'` in HTML does nothing. Check the array in script, and run `parseCollection` on it: it throws an `Error` that names the first bad item (a missing `name` or `image`, a duplicate `id`, a `kind` other than `card` or `object`, an invalid `metadata`).
29
+
30
+ ## The zoom bar is missing, or the console says it cannot resolve `@johnmorrisdotca/kazoku-ui/view-controls/define`
31
+
32
+ On a page without a bundler the collection needs an import map for that name (see [Frameworks and bundlers](frameworks.md#plain-html-with-an-import-map)). The single `<fuda-card>` does not.
33
+
34
+ ## Angle, Tilt and Auto-turn are not there
35
+
36
+ A collection with no card in it (every item `kind: 'object'`) has nothing that turns, so it offers none of them, and an angle in the address is dropped. The flat displays (everything but the piles) do not turn either.
37
+
38
+ ## Nothing moves
39
+
40
+ Check `animate="off"` on the element, and the system's reduced-motion setting: with it on, the card's rotation, the pan, autoplay and a live 3D card are off by design. `autoplay="focus"` needs `motion="pan"`. A pan has no distance to travel if the image is not taller than the window after it fills the card's width.
41
+
42
+ ## A card taken off a pile has no room
43
+
44
+ `pile-controls` draws three buttons under the card: leave about 70 px below it. An open fan or a side pile reaches beyond the card: read `card.pileBounds`, or listen for `fuda-pile`, and fit your layout to it.
45
+
46
+ ## `wear` shows nothing
47
+
48
+ `perfect`, an empty value, an unknown name or all-zero levels draw nothing, deliberately. Check the spelling against `wearPresets`. Wear is not drawn on the images of a `<fuda-collection>` or on the cards under the top of a stack.
49
+
50
+ ## The edge looks wrong, or the shadow flattens the 3D
51
+
52
+ The drop shadow is a filter on the element itself. A `filter` on anything between the card and its faces flattens the 3D, so a back appears mirrored. Remove it, or set `--fuda-edge` to change the edge colour.
53
+
54
+ ## Live 3D never starts
55
+
56
+ The card stays its picture with reduced motion, with no WebGL, after a lost context, and while another card holds focus. `live.focus(card)` resolves to `false` in each case. Check `load` returns the `three` module and that your `item.build` returns a scene, a camera and an `object`.
57
+
58
+ ## Questions
59
+
60
+ **Does it need a framework?** No. **Does it fetch anything?** Only the image addresses you give it, in the reader's browser. **Does it store anything?** No; the demo saves named collections in the browser's local storage, and the package does not. **Is it accessible?** See [Accessibility and theming](accessibility-and-theming.md) for what is built in and what is tested.