@johnmorrisdotca/fuda-cards 0.9.2 → 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 (98) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +14 -0
  3. package/README.md +466 -60
  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 +41 -63
  25. package/dist/collection-element.js +288 -472
  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 +126 -0
  45. package/dist/live-3d.js +229 -0
  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 +783 -0
  62. package/docs/collection-displays.md +1 -1
  63. package/docs/guides/accessibility-and-theming.md +62 -0
  64. package/docs/guides/architecture.md +53 -0
  65. package/docs/guides/binder-and-piles.md +83 -0
  66. package/docs/guides/bundlers.md +60 -0
  67. package/docs/guides/card-element.md +65 -0
  68. package/docs/guides/collections.md +86 -0
  69. package/docs/guides/embed-in-an-iframe.md +39 -0
  70. package/docs/guides/frameworks.md +132 -0
  71. package/docs/guides/getting-started.md +96 -0
  72. package/docs/guides/html-and-cdn.md +69 -0
  73. package/docs/guides/ja/accessibility-and-theming.md +62 -0
  74. package/docs/guides/ja/architecture.md +53 -0
  75. package/docs/guides/ja/binder-and-piles.md +83 -0
  76. package/docs/guides/ja/bundlers.md +60 -0
  77. package/docs/guides/ja/card-element.md +65 -0
  78. package/docs/guides/ja/collections.md +86 -0
  79. package/docs/guides/ja/embed-in-an-iframe.md +39 -0
  80. package/docs/guides/ja/frameworks.md +132 -0
  81. package/docs/guides/ja/getting-started.md +96 -0
  82. package/docs/guides/ja/html-and-cdn.md +69 -0
  83. package/docs/guides/ja/live-3d.md +75 -0
  84. package/docs/guides/ja/materials-and-stacks.md +73 -0
  85. package/docs/guides/ja/motion-and-spin.md +73 -0
  86. package/docs/guides/ja/troubleshooting.md +60 -0
  87. package/docs/guides/ja/typescript-and-node.md +45 -0
  88. package/docs/guides/ja/upgrading.md +56 -0
  89. package/docs/guides/ja/wear.md +63 -0
  90. package/docs/guides/live-3d.md +75 -0
  91. package/docs/guides/materials-and-stacks.md +73 -0
  92. package/docs/guides/motion-and-spin.md +73 -0
  93. package/docs/guides/troubleshooting.md +60 -0
  94. package/docs/guides/typescript-and-node.md +45 -0
  95. package/docs/guides/upgrading.md +56 -0
  96. package/docs/guides/wear.md +63 -0
  97. package/docs/live-3d.md +59 -0
  98. package/package.json +81 -11
@@ -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`のインポートマップが要ります。[HTMLとCDN](html-and-cdn.md)と[バンドラー](bundlers.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.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
+
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, DEFAULT_CARD_THICKNESS_MM, stackHeightMm, stackLayout, stackPresets } from '@johnmorrisdotca/fuda-cards';
59
+
60
+ const stock = cardMaterial('paper-310-black-core');
61
+ console.log(stackHeightMm(52, stock?.thicknessMm ?? DEFAULT_CARD_THICKNESS_MM));
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 [TypeScript and Node](typescript-and-node.md#on-a-server)). 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 [HTML and CDN](html-and-cdn.md#the-collection-and-live-3d-from-a-cdn)). 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.
@@ -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.
@@ -0,0 +1,56 @@
1
+ ---
2
+ title: Upgrading
3
+ section: upgrading
4
+ order: 13
5
+ description: What changed in each version that you must act on, from 0.1 to 0.10, and what still works from earlier versions.
6
+ ---
7
+
8
+ The package is in early development (0.x), and each minor release can add to the interface. This page lists only what asks something of you. The complete record, dated, is in the [changelog](../../CHANGELOG.md).
9
+
10
+ ## To 0.10
11
+
12
+ - `@johnmorrisdotca/kazoku-ui` is `^0.10.0`. The zoom bar now shows one number, the true zoom (`1.3×`), where the old `2×` preset read like a number; a press on it goes back to Fit. The bar's basic level is angle, Auto-turn, zoom and Fit, and **More** adds tilt, Front and the arrow pad.
13
+ - Live 3D is new: `@johnmorrisdotca/fuda-cards/live-3d` and `collection.live`. `three` is an optional peer dependency. See [Live 3D in a card](live-3d.md).
14
+ - Tests: `playwright` 1.64.0 is a development dependency, and the browser tests run headless in software only.
15
+
16
+ ## To 0.9
17
+
18
+ - `kind` is new on an item: `"card"` (the default) or `"object"`. Every collection written before it is still cards. An object never turns over; mark a console or a trophy `kind: 'object'`. New exports: `collectionKinds`, `isCard`, `CollectionKind`.
19
+ - A card is never see-through while it flips: no change needed.
20
+
21
+ ## To 0.8
22
+
23
+ - **Jukebox Carousel and Flip Tower are gone** as displays. `view="jukebox"` and `view="tower"` still open the deck (`collectionViewAliases` says so) and `collectionViews` lists the ten displays. Infinite Card Atlas is now Card Table; `view="atlas"` is unchanged.
24
+ - The binder is now real sheets in a ring or zip binder. New options: `binder`, `cover`, `sheet`, `pockets`. The older `page-size` and `columns` still work.
25
+
26
+ ## To 0.7
27
+
28
+ - Every pile fans, turns and has a card taken off. New on `<fuda-card>`: `fan`, `taken-off`, `deck-land`, `pile-controls`, `takeOff()`, `putBack()`, `pileBounds` and the event `fuda-pile`.
29
+ - **`animate` is on when the attribute is missing.** Set `animate="off"` to keep the jumps of 0.6.0.
30
+ - `fan-size` is 2 to 10 (it was 2 to 20).
31
+
32
+ ## To 0.6
33
+
34
+ - `deck-land="upside-down"` was added, and in 0.6.1 it was found wrong (a card is not turned half way round in its plane). It still works and means `face-down`. `normalizeLanding` converts a value.
35
+ - **Update the one CSS line in your page's head**: an undefined `<fuda-collection>` now reserves its view plus 380 px (it was 200 px), because the display buttons make the component taller. The line is in [Troubleshooting](troubleshooting.md#the-picture-flashes-before-the-card-appears).
36
+ - The display is a row of buttons, not a drop-down; `theme="light|dark"` chooses the colours.
37
+
38
+ ## To 0.5 and 0.4
39
+
40
+ - `wear` (0.5) and `material` and `stack` (0.4) are new; a card without them is unchanged, and loads none of their code.
41
+
42
+ ## To 0.2
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 [HTML and CDN](html-and-cdn.md) and [Bundlers](bundlers.md).
45
+ - The `address` attribute on `<fuda-collection>` keeps the view's state in the page address.
46
+
47
+ ## Checking an upgrade
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: Wear
3
+ section: how-to
4
+ order: 4
5
+ description: Draw a card that has been played with, from mint to damaged, with presets, a seed and one dial for each kind of wear.
6
+ ---
7
+
8
+ `wear` draws a card the way it looks after use: soft, rounded, chipped or folded corners, whitening on the edges, creases, scratches, specks, staining, yellowing and a print that sits off centre. A card with no `wear` attribute is byte for byte what it was before, and the wear code is a separate module that is loaded only when a card asks for wear.
9
+
10
+ ![A heavily played card: a folded corner, chipped edges, scratches and a crease](../images/wear-desk-light.webp)
11
+
12
+ ## Use it
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` is a preset's id or a number from 0 to 1 that sets every level at once. The presets are the plain grading words: `mint`, `near-mint`, `lightly-played`, `moderately-played`, `heavily-played` and `damaged`. `perfect`, no attribute, or a name the package does not know draws nothing. `wear-corners`, `wear-edges`, `wear-surface` and `wear-creases` (each 0 to 1) change one kind on its own, over the preset's.
22
+
23
+ ## The seed
24
+
25
+ `wear-seed` (a whole number, default 1) fixes where the marks lie. A card looks the same every time and on every device: the same seed lays the same marks, another seed lays others. Nothing is random at draw time and nothing moves.
26
+
27
+ ## Wear as data
28
+
29
+ The package exports the whole machine without touching the page, so you can draw a worn card into something that is not a `<fuda-card>`: a poster, a PDF or a server-rendered image.
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` gives the levels a card asks for, or `null` when it asks for none, so `null` means "draw nothing". `wearLayout(levels, seed)` says where every mark lies, `wearOutline` gives the card's silhouette with its chipped and folded corners as a path, and `wearOverlaySvg` gives the marks as SVG text for the front or the back.
51
+
52
+ ## What is drawn
53
+
54
+ | Kind | What you see | From which level |
55
+ |---|---|---|
56
+ | Corners | Sharp, soft, rounded, chipped or folded (a dog-ear that shows the back); at most one folded and two chipped. | Any |
57
+ | Edges | Cream flecks of bare stock along the four edges. | Any |
58
+ | Surface | Thin light scratches and dark or light specks over the face. | Any |
59
+ | Creases | Curved lines with a light and a shadow side; a heavy one breaks the print. | `moderately-played` and up |
60
+ | Toning and staining | A yellow-brown darkening towards the edges, and from heavy wear a soft stain. | `lightly-played` and up |
61
+ | Centering | The print sits off centre by up to 7 px across and 5 px down, at 300 px wide. | Any |
62
+
63
+ The grading words come from secondary sources, because the grading companies' own pages did not answer; [docs/wear.md](../wear.md) lists them, with the level of every preset. The presets are this package's reading of those words, not a grade. Wear is not drawn on the images of a `<fuda-collection>` or on the cards under the top of a stack.
@@ -0,0 +1,59 @@
1
+ # Live 3D in a card
2
+
3
+ `@johnmorrisdotca/fuda-cards/live-3d`. Many cards on screen, one of them turning in 3D: the one in focus. This module is the focus policy. Everything underneath it (the one WebGL context, the shared assets, the stills, the frames, the pixel budget, context loss) is kazoku-ui's shared renderer (`@johnmorrisdotca/kazoku-ui/renderer`, its `docs/renderer.md`).
4
+
5
+ Why it exists: every card live was measured at 41 WebGL contexts (16 alive, the browser's limit), 24 cards dropped to a fallback and 108,654 draws in 3 s for 40 cards.
6
+
7
+ ## Use
8
+
9
+ ```js
10
+ import { createLiveCards } from '@johnmorrisdotca/fuda-cards/live-3d';
11
+
12
+ const live = createLiveCards({ load: () => import('three') }); // loads nothing yet
13
+
14
+ const rocket = {
15
+ key: 'rocket:starship', // cards with the same key share their pictures
16
+ async build({ three, assets, width, height }) {
17
+ const gltf = await assets.acquire('glb:starship', () => new GLTFLoader().loadAsync(url), (loading) => loading.then((g) => disposeDeep(g.scene)));
18
+ const object = gltf.scene.clone(true); // shares the geometry and the materials
19
+ const scene = new three.Scene(); scene.add(object /* and lights */);
20
+ const camera = new three.PerspectiveCamera(30, width / height, 0.01, 1000);
21
+ return { scene, camera, object, resize: (w, h) => { camera.aspect = w / h; camera.updateProjectionMatrix(); } };
22
+ },
23
+ };
24
+
25
+ const off = live.add(card, rocket, { still: card.querySelector('img') });
26
+ ```
27
+
28
+ - `add(card, item, { still })` works on a `<fuda-card>` or any element with a size, and 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. Without one, the renderer makes its picture when the card comes within `lookAheadPx` of the view, one at a time.
29
+ - `item.build` is a kazoku-ui item plus `object`, what turns about its upright axis. Take every geometry, material, texture and model through `assets.acquire`.
30
+ - `focus(card)`, `blur()`, `focused`, `stats` (the renderer's), `renderer`, `dispose()`.
31
+ - `<fuda-collection>`: `collection.live = { cards: live, item: (card) => itemFor(card) }`; every display then goes live on the card in focus.
32
+ - Options: `turnSeconds` (12), `dwellMs` (150), `lookAheadPx` (300), and the renderer's own (`maxPixels`, `maxSide`, `stillSize`, `stillBytes`, `lingerMs`, `releaseMs`, `onContext`, ...).
33
+
34
+ Dependencies: `@johnmorrisdotca/kazoku-ui` is already a dependency; `three` is an optional peer, yours, loaded by your `load`. A bundler makes a chunk of the renderer; an unbundled page lists `@johnmorrisdotca/kazoku-ui/renderer` and `three` in its import map (see `demo/live-3d.html`).
35
+
36
+ ## The rules
37
+
38
+ - **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.
39
+ - **The old card freezes at its last angle.** Its still is made from the same context at that angle (shared per 5 degrees) and it goes on from there when it is focused again. Until that still is ready, for a moment, the card shows its previous picture.
40
+ - **Reduced motion: no live card.** The card stays its picture, no 3D code loads.
41
+ - **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.
42
+ - **No WebGL, or a lost context:** the card stays its picture; on a restored context it draws again.
43
+
44
+ ## The budgets (`pnpm test:freeze`, `test/e2e/live-3d.e2e.mjs`)
45
+
46
+ | Budget | Held to |
47
+ |---|---|
48
+ | WebGL contexts over 30 focus changes | 1, at every moment, with at most one canvas |
49
+ | At rest, over 2 s | 0 draws, 0 frame requests, 0 frame callbacks |
50
+ | Out of sight and in a hidden tab, over 1.2 s | 0 draws, 0 frame requests; while seen, one frame at a time |
51
+ | GPU objects (made minus deleted) after the first round of focus changes | no growth over further rounds |
52
+ | Canvas on a 5120x2880 screen at ratio 2, with a card that fills it | within 6 MP and 4096 a side |
53
+ | A page of pictures | no `three`, no renderer, no model fetched before the first focus; `dist/live-3d.js` under 3 KB gzipped; `dist/element.js` and `dist/collection-element.js` do not reach for it |
54
+
55
+ Each budget also runs against a build broken on purpose (a module served with one line changed) and must fail, so a green budget means something. The release runs this test too (`freeze-command` in `.github/workflows/release.yml`).
56
+
57
+ ## What a test here cannot prove
58
+
59
+ The tests draw in software (ANGLE on SwiftShader), because a test run on a Mac's own GPU panicked its driver. So nothing here measures a real GPU: frame times, driver behaviour, GPU memory and how a Metal driver takes the context moving between cards are not checked. The counts (contexts, draws, frames, GPU objects, canvas size) do not depend on the GPU. WebKit has no software switch, so Safari is not run off CI.