@johnmorrisdotca/fuda-cards 0.9.2 → 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 +18 -1
  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,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 [Frameworks and bundlers](frameworks.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/fuda-cards",
3
- "version": "0.9.2",
3
+ "version": "0.10.1",
4
4
  "description": "Fuda Cards: collectible card frames for images and interactive 3D content.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -19,6 +19,10 @@
19
19
  "import": "./dist/element.js"
20
20
  },
21
21
  "./package.json": "./package.json",
22
+ "./live-3d": {
23
+ "types": "./dist/live-3d.d.ts",
24
+ "import": "./dist/live-3d.js"
25
+ },
22
26
  "./collection": {
23
27
  "types": "./dist/collection.d.ts",
24
28
  "import": "./dist/collection.js"
@@ -34,9 +38,12 @@
34
38
  "docs/collection-displays.md",
35
39
  "docs/collection-input.md",
36
40
  "docs/framework-integration.md",
41
+ "docs/live-3d.md",
37
42
  "docs/materials.md",
38
43
  "docs/wear.md",
39
- "assets/README.md"
44
+ "assets/README.md",
45
+ "docs/API.md",
46
+ "docs/guides"
40
47
  ],
41
48
  "engines": {
42
49
  "node": ">=22"
@@ -44,16 +51,32 @@
44
51
  "scripts": {
45
52
  "build": "tsc -p tsconfig.json",
46
53
  "typecheck": "tsc -p tsconfig.json --noEmit",
47
- "test": "pnpm build && node --test test/*.test.mjs",
54
+ "test": "pnpm build && node --test test/*.test.mjs test/*.test.ts",
48
55
  "check": "pnpm typecheck && pnpm build && pnpm test",
49
- "test:e2e": "pnpm build && node --test test/e2e/*.e2e.mjs",
56
+ "test:e2e": "pnpm build && node scripts/e2e.mjs",
57
+ "test:freeze": "pnpm site && node scripts/e2e.mjs live-3d",
50
58
  "dev": "pnpm build && node scripts/dev.mjs",
51
- "site": "pnpm build && node scripts/site.mjs"
59
+ "site": "pnpm build && node scripts/site.mjs",
60
+ "screenshots:readme": "pnpm site && node scripts/readme-pictures.mjs",
61
+ "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"
52
64
  },
53
65
  "dependencies": {
54
- "@johnmorrisdotca/kazoku-ui": "^0.2.1"
66
+ "@johnmorrisdotca/kazoku-ui": "^0.10.0"
67
+ },
68
+ "peerDependencies": {
69
+ "three": ">=0.160.0"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "three": {
73
+ "optional": true
74
+ }
55
75
  },
56
76
  "devDependencies": {
77
+ "@johnmorrisdotca/uchusen-rockets": "0.2.2",
78
+ "playwright": "1.64.0",
79
+ "three": "0.186.1",
57
80
  "typescript": "5.9.3"
58
81
  },
59
82
  "publishConfig": {