@johnmorrisdotca/fuda-cards 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE.md +14 -0
- package/README.md +89 -7
- package/dist/binder.d.ts +4 -6
- package/dist/binder.js +32 -23
- package/dist/card-markup.d.ts +2 -0
- package/dist/card-markup.js +59 -0
- package/dist/card-options.d.ts +131 -0
- package/dist/card-options.js +48 -0
- package/dist/card-styles.d.ts +2 -0
- package/dist/card-styles.js +314 -0
- package/dist/choice.d.ts +1 -1
- package/dist/choice.js +27 -23
- package/dist/collection-address.d.ts +8 -0
- package/dist/collection-address.js +52 -0
- package/dist/collection-binder-view.d.ts +9 -0
- package/dist/collection-binder-view.js +123 -0
- package/dist/collection-controls.d.ts +2 -0
- package/dist/collection-controls.js +143 -0
- package/dist/collection-deck.d.ts +11 -0
- package/dist/collection-deck.js +165 -0
- package/dist/collection-dialog.d.ts +2 -0
- package/dist/collection-dialog.js +28 -0
- package/dist/collection-element.d.ts +30 -65
- package/dist/collection-element.js +283 -484
- package/dist/collection-host.d.ts +5 -0
- package/dist/collection-host.js +1 -0
- package/dist/collection-icons.d.ts +3 -0
- package/dist/collection-icons.js +19 -0
- package/dist/collection-motion.d.ts +11 -0
- package/dist/collection-motion.js +72 -0
- package/dist/collection-styles.d.ts +4 -0
- package/dist/collection-styles.js +336 -0
- package/dist/collection-views.d.ts +8 -0
- package/dist/collection-views.js +8 -0
- package/dist/collection.d.ts +140 -11
- package/dist/collection.js +139 -33
- package/dist/element-define.d.ts +2 -0
- package/dist/element-define.js +3 -0
- package/dist/element.d.ts +20 -1
- package/dist/element.js +289 -98
- package/dist/index.d.ts +9 -52
- package/dist/index.js +5 -5
- package/dist/live-3d.d.ts +87 -4
- package/dist/live-3d.js +120 -52
- package/dist/materials.d.ts +117 -6
- package/dist/materials.js +191 -28
- package/dist/motion.d.ts +2 -0
- package/dist/motion.js +4 -0
- package/dist/pile-card.js +138 -91
- package/dist/pile.d.ts +61 -8
- package/dist/pile.js +89 -29
- package/dist/stack.d.ts +42 -6
- package/dist/stack.js +28 -3
- package/dist/version.d.ts +11 -0
- package/dist/version.js +11 -0
- package/dist/wear.d.ts +147 -9
- package/dist/wear.js +273 -89
- package/dist/zoom.d.ts +1 -1
- package/dist/zoom.js +73 -42
- package/docs/API.md +121 -131
- package/docs/guides/bundlers.md +60 -0
- package/docs/guides/card-element.md +2 -2
- package/docs/guides/embed-in-an-iframe.md +39 -0
- package/docs/guides/frameworks.md +93 -66
- package/docs/guides/getting-started.md +3 -1
- package/docs/guides/html-and-cdn.md +69 -0
- package/docs/guides/ja/bundlers.md +60 -0
- package/docs/guides/ja/card-element.md +2 -2
- package/docs/guides/ja/embed-in-an-iframe.md +39 -0
- package/docs/guides/ja/frameworks.md +93 -66
- package/docs/guides/ja/getting-started.md +3 -1
- package/docs/guides/ja/html-and-cdn.md +69 -0
- package/docs/guides/ja/materials-and-stacks.md +3 -3
- package/docs/guides/ja/troubleshooting.md +2 -2
- package/docs/guides/ja/typescript-and-node.md +45 -0
- package/docs/guides/ja/upgrading.md +1 -1
- package/docs/guides/materials-and-stacks.md +3 -3
- package/docs/guides/troubleshooting.md +2 -2
- package/docs/guides/typescript-and-node.md +45 -0
- package/docs/guides/upgrading.md +1 -1
- package/package.json +57 -10
package/dist/live-3d.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import type { BuildContext, RendererStats, Scene3D, SharedRenderer, SharedRendererOptions, ThreeLike } from
|
|
2
|
-
/**
|
|
1
|
+
import type { BuildContext, RendererStats, Scene3D, SharedRenderer, SharedRendererOptions, ThreeLike } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
2
|
+
/**
|
|
3
|
+
* A scene for a card: kazoku-ui's scene, with `object`, the thing that turns about its upright axis while the card is in focus.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts no-run
|
|
7
|
+
* import type { LiveScene } from "@johnmorrisdotca/fuda-cards/live-3d";
|
|
8
|
+
* import { BoxGeometry, Mesh, MeshNormalMaterial, PerspectiveCamera, Scene } from "three";
|
|
9
|
+
*
|
|
10
|
+
* const cube = new Mesh(new BoxGeometry(1, 1, 1), new MeshNormalMaterial());
|
|
11
|
+
* const scene = new Scene().add(cube);
|
|
12
|
+
* const live: LiveScene = { scene, camera: new PerspectiveCamera(40, 1, 0.1, 10), object: cube };
|
|
13
|
+
* console.log(live.object === cube);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
3
16
|
export interface LiveScene extends Scene3D {
|
|
4
17
|
object?: {
|
|
5
18
|
rotation: {
|
|
@@ -7,12 +20,40 @@ export interface LiveScene extends Scene3D {
|
|
|
7
20
|
};
|
|
8
21
|
};
|
|
9
22
|
}
|
|
10
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* What a card shows in 3D: a key (items with the same key share their pictures) and a scene made from shared assets (`assets.acquire`).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts no-run
|
|
28
|
+
* import type { LiveItem } from "@johnmorrisdotca/fuda-cards/live-3d";
|
|
29
|
+
* import { BoxGeometry, Mesh, MeshNormalMaterial, PerspectiveCamera, Scene } from "three";
|
|
30
|
+
*
|
|
31
|
+
* const cube: LiveItem = {
|
|
32
|
+
* key: "cube",
|
|
33
|
+
* build() {
|
|
34
|
+
* const object = new Mesh(new BoxGeometry(1, 1, 1), new MeshNormalMaterial());
|
|
35
|
+
* return { scene: new Scene().add(object), camera: new PerspectiveCamera(40, 1, 0.1, 10), object };
|
|
36
|
+
* },
|
|
37
|
+
* };
|
|
38
|
+
* console.log(cube.key);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
11
41
|
export interface LiveItem<T extends ThreeLike = ThreeLike> {
|
|
12
42
|
key: string;
|
|
13
43
|
build(context: BuildContext<T>): LiveScene | Promise<LiveScene>;
|
|
14
44
|
}
|
|
15
|
-
|
|
45
|
+
/**
|
|
46
|
+
* How the live cards behave: the shared renderer's options (kazoku-ui's), and how long a turn takes, how long the pointer rests before a card goes live and how far ahead a still is made.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts no-run
|
|
50
|
+
* import type { LiveCardsOptions } from "@johnmorrisdotca/fuda-cards/live-3d";
|
|
51
|
+
*
|
|
52
|
+
* const options: LiveCardsOptions = { load: () => import("three"), turnSeconds: 20, dwellMs: 250 };
|
|
53
|
+
* console.log(options.turnSeconds);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export interface LiveCardsOptions<T extends ThreeLike = ThreeLike> extends Omit<SharedRendererOptions<T>, "scheduler" | "assets" | "clock" | "document"> {
|
|
16
57
|
/** Seconds for one turn of the card in focus (12). 0 does not turn it. */
|
|
17
58
|
turnSeconds?: number;
|
|
18
59
|
/** How long the pointer has to rest on a card before it goes live, in milliseconds (150), so moving the pointer across a page of cards starts nothing. A press or the keyboard does not wait. */
|
|
@@ -20,10 +61,33 @@ export interface LiveCardsOptions<T extends ThreeLike = ThreeLike> extends Omit<
|
|
|
20
61
|
/** How far outside the view a card with no picture of its own gets its still made, in pixels (300). */
|
|
21
62
|
lookAheadPx?: number;
|
|
22
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* What a card brings when it is added: the picture it already has.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts no-run
|
|
69
|
+
* import type { AddOptions } from "@johnmorrisdotca/fuda-cards/live-3d";
|
|
70
|
+
*
|
|
71
|
+
* const withPicture = (still: HTMLImageElement): AddOptions => ({ still });
|
|
72
|
+
* console.log(typeof withPicture);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
23
75
|
export interface AddOptions {
|
|
24
76
|
/** A picture the card already has (an `<img>` of its own), kept until the card is in focus. With one, the card costs no 3D code until then. */
|
|
25
77
|
still?: HTMLImageElement;
|
|
26
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* The live cards of a page: add a card, put one in focus, let go. Only the card in focus turns in 3D, on the page's one WebGL context; the others stay pictures.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts no-run
|
|
84
|
+
* import { createLiveCards, type LiveCards } from "@johnmorrisdotca/fuda-cards/live-3d";
|
|
85
|
+
*
|
|
86
|
+
* const live: LiveCards = createLiveCards({ load: () => import("three") });
|
|
87
|
+
* live.blur();
|
|
88
|
+
* live.dispose();
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
27
91
|
export interface LiveCards<T extends ThreeLike = ThreeLike> {
|
|
28
92
|
/** Make a card live on focus: a `<fuda-card>` or any element with a size. Gives back the function that takes it off again. */
|
|
29
93
|
add(card: HTMLElement, item: LiveItem<T>, options?: AddOptions): () => void;
|
|
@@ -40,4 +104,23 @@ export interface LiveCards<T extends ThreeLike = ThreeLike> {
|
|
|
40
104
|
/** Take every card off and let go of the renderer. */
|
|
41
105
|
dispose(): void;
|
|
42
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Make the live cards of a page. Nothing 3D is loaded until a card is first in focus (or a card with no picture of its own comes near the view and needs its still made).
|
|
109
|
+
*
|
|
110
|
+
* @param options - How to load three.js (`load`), and optionally the turn, the dwell and the look-ahead; see {@link LiveCardsOptions}.
|
|
111
|
+
* @returns The live cards; call `add` for each card, and `dispose` when the page is done with them.
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts no-run
|
|
114
|
+
* import { createLiveCards } from "@johnmorrisdotca/fuda-cards/live-3d";
|
|
115
|
+
* import { PerspectiveCamera, Scene } from "three";
|
|
116
|
+
*
|
|
117
|
+
* const live = createLiveCards({ load: () => import("three") });
|
|
118
|
+
* const card = document.querySelector("fuda-card") as HTMLElement;
|
|
119
|
+
* const remove = live.add(card, {
|
|
120
|
+
* key: "cube",
|
|
121
|
+
* build: () => ({ scene: new Scene(), camera: new PerspectiveCamera(40, 1, 0.1, 10) }),
|
|
122
|
+
* });
|
|
123
|
+
* remove();
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
43
126
|
export declare function createLiveCards<T extends ThreeLike = ThreeLike>(options: LiveCardsOptions<T>): LiveCards<T>;
|
package/dist/live-3d.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
|
+
import { reducedMotion } from "./motion.js";
|
|
1
2
|
/** Stills are shared per this many degrees, so a card frozen at any angle shows a picture at its angle without one picture per degree. */
|
|
2
3
|
const STILL_STEP = 5;
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Make the live cards of a page. Nothing 3D is loaded until a card is first in focus (or a card with no picture of its own comes near the view and needs its still made).
|
|
6
|
+
*
|
|
7
|
+
* @param options - How to load three.js (`load`), and optionally the turn, the dwell and the look-ahead; see {@link LiveCardsOptions}.
|
|
8
|
+
* @returns The live cards; call `add` for each card, and `dispose` when the page is done with them.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts no-run
|
|
11
|
+
* import { createLiveCards } from "@johnmorrisdotca/fuda-cards/live-3d";
|
|
12
|
+
* import { PerspectiveCamera, Scene } from "three";
|
|
13
|
+
*
|
|
14
|
+
* const live = createLiveCards({ load: () => import("three") });
|
|
15
|
+
* const card = document.querySelector("fuda-card") as HTMLElement;
|
|
16
|
+
* const remove = live.add(card, {
|
|
17
|
+
* key: "cube",
|
|
18
|
+
* build: () => ({ scene: new Scene(), camera: new PerspectiveCamera(40, 1, 0.1, 10) }),
|
|
19
|
+
* });
|
|
20
|
+
* remove();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
4
23
|
export function createLiveCards(options) {
|
|
5
24
|
const { turnSeconds = 12, dwellMs = 150, lookAheadPx = 300, ...rendererOptions } = options;
|
|
6
25
|
const entries = new Map();
|
|
@@ -10,40 +29,51 @@ export function createLiveCards(options) {
|
|
|
10
29
|
let disposed = false;
|
|
11
30
|
let asked = 0;
|
|
12
31
|
/** The renderer's module comes in only when a card first needs it: a page of pictures never loads it. */
|
|
13
|
-
const needRenderer = () => (loading ??= import(
|
|
32
|
+
const needRenderer = () => (loading ??= import("@johnmorrisdotca/kazoku-ui/renderer").then(({ createSharedRenderer }) => (renderer = createSharedRenderer(rendererOptions))));
|
|
14
33
|
/** The view of a card, made when first needed. The item's key carries the card's angle, so its still shows the angle it stopped at. */
|
|
15
34
|
const viewOf = (entry) => {
|
|
16
35
|
if (entry.view)
|
|
17
36
|
return Promise.resolve(entry.view);
|
|
18
|
-
|
|
37
|
+
entry.making ??= needRenderer().then((shared) => {
|
|
19
38
|
if (disposed || !entries.has(entry.card))
|
|
20
39
|
return undefined;
|
|
21
40
|
const turning = {
|
|
22
|
-
get key() {
|
|
41
|
+
get key() {
|
|
42
|
+
return `${entry.item.key}@${(((Math.round(entry.angle / STILL_STEP) * STILL_STEP) % 360) + 360) % 360}`;
|
|
43
|
+
},
|
|
23
44
|
build: async (context) => {
|
|
24
45
|
const scene = await entry.item.build(context);
|
|
25
|
-
const turn = () => {
|
|
26
|
-
scene.object
|
|
46
|
+
const turn = () => {
|
|
47
|
+
if (scene.object)
|
|
48
|
+
scene.object.rotation.y = (entry.angle * Math.PI) / 180;
|
|
49
|
+
};
|
|
27
50
|
turn();
|
|
28
|
-
return {
|
|
51
|
+
return {
|
|
52
|
+
...scene,
|
|
53
|
+
update(dt, now) {
|
|
29
54
|
const more = scene.update?.(dt, now) === true;
|
|
30
55
|
if (!turnSeconds || !scene.object || reducedMotion())
|
|
31
56
|
return more;
|
|
32
57
|
entry.angle += (360 * dt) / turnSeconds;
|
|
33
58
|
turn();
|
|
34
59
|
return true;
|
|
35
|
-
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
36
62
|
},
|
|
37
63
|
};
|
|
38
|
-
|
|
39
|
-
|
|
64
|
+
entry.view = shared.view(entry.host, turning, entry.poster ? { still: entry.poster } : {});
|
|
65
|
+
return entry.view;
|
|
66
|
+
});
|
|
67
|
+
return entry.making;
|
|
68
|
+
};
|
|
69
|
+
const putPosterBack = (entry) => {
|
|
70
|
+
if (entry.poster && entry.posterSrc && !entry.poster.getAttribute("src"))
|
|
71
|
+
entry.poster.src = entry.posterSrc;
|
|
40
72
|
};
|
|
41
|
-
const putPosterBack = (entry) => { if (entry.poster && entry.posterSrc && !entry.poster.getAttribute('src'))
|
|
42
|
-
entry.poster.src = entry.posterSrc; };
|
|
43
73
|
/** A card near the view shows its picture. One with a picture of its own needs nothing; the renderer makes the others', one at a time. */
|
|
44
74
|
const prepare = (entry) => {
|
|
45
75
|
if (entry.view) {
|
|
46
|
-
if (entry.poster && !entry.poster.getAttribute(
|
|
76
|
+
if (entry.poster && !entry.poster.getAttribute("src") && !entry.view.live)
|
|
47
77
|
putPosterBack(entry);
|
|
48
78
|
if (!entry.poster)
|
|
49
79
|
void entry.view.showStill();
|
|
@@ -52,13 +82,15 @@ export function createLiveCards(options) {
|
|
|
52
82
|
if (!entry.poster)
|
|
53
83
|
void viewOf(entry).then((view) => view?.showStill());
|
|
54
84
|
};
|
|
55
|
-
const near = typeof IntersectionObserver ===
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
85
|
+
const near = typeof IntersectionObserver === "function"
|
|
86
|
+
? new IntersectionObserver((seen) => {
|
|
87
|
+
for (const { target, isIntersecting } of seen) {
|
|
88
|
+
const entry = entries.get(target);
|
|
89
|
+
if (entry && isIntersecting)
|
|
90
|
+
prepare(entry);
|
|
91
|
+
}
|
|
92
|
+
}, { rootMargin: `${lookAheadPx}px` })
|
|
93
|
+
: undefined;
|
|
62
94
|
async function focus(card) {
|
|
63
95
|
const entry = entries.get(card);
|
|
64
96
|
if (!entry || disposed || reducedMotion())
|
|
@@ -79,7 +111,7 @@ export function createLiveCards(options) {
|
|
|
79
111
|
entry?.view?.blur();
|
|
80
112
|
}
|
|
81
113
|
// Who is in focus: the card under the pointer after a short rest, the one holding keyboard focus, the one last pressed. A press elsewhere ends it.
|
|
82
|
-
document.addEventListener(
|
|
114
|
+
document.addEventListener("pointerdown", onPressAnywhere, true);
|
|
83
115
|
function onPressAnywhere(event) {
|
|
84
116
|
if (focusedEntry && !event.composedPath().includes(focusedEntry.card))
|
|
85
117
|
blur();
|
|
@@ -87,40 +119,70 @@ export function createLiveCards(options) {
|
|
|
87
119
|
function listen(entry) {
|
|
88
120
|
const { card } = entry;
|
|
89
121
|
let timer;
|
|
90
|
-
const wait = () => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
122
|
+
const wait = () => {
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
timer = undefined;
|
|
125
|
+
};
|
|
126
|
+
const enter = (e) => {
|
|
127
|
+
if (e.pointerType === "touch")
|
|
128
|
+
return;
|
|
129
|
+
wait();
|
|
130
|
+
timer = setTimeout(() => {
|
|
131
|
+
void focus(card);
|
|
132
|
+
}, dwellMs);
|
|
133
|
+
};
|
|
134
|
+
const leave = (e) => {
|
|
135
|
+
if (e.pointerType === "touch")
|
|
136
|
+
return;
|
|
137
|
+
wait();
|
|
138
|
+
if (focusedEntry === entry && !card.matches(":focus-within"))
|
|
139
|
+
blur();
|
|
140
|
+
};
|
|
141
|
+
const press = () => {
|
|
142
|
+
wait();
|
|
143
|
+
void focus(card);
|
|
144
|
+
};
|
|
145
|
+
const focusIn = () => {
|
|
146
|
+
wait();
|
|
147
|
+
void focus(card);
|
|
148
|
+
};
|
|
149
|
+
const focusOut = (e) => {
|
|
150
|
+
if (focusedEntry === entry && !card.contains(e.relatedTarget) && !card.matches(":hover"))
|
|
151
|
+
blur();
|
|
152
|
+
};
|
|
153
|
+
card.addEventListener("pointerenter", enter);
|
|
154
|
+
card.addEventListener("pointerleave", leave);
|
|
155
|
+
card.addEventListener("pointerdown", press);
|
|
156
|
+
card.addEventListener("focusin", focusIn);
|
|
157
|
+
card.addEventListener("focusout", focusOut);
|
|
105
158
|
return () => {
|
|
106
159
|
wait();
|
|
107
|
-
card.removeEventListener(
|
|
108
|
-
card.removeEventListener(
|
|
109
|
-
card.removeEventListener(
|
|
110
|
-
card.removeEventListener(
|
|
111
|
-
card.removeEventListener(
|
|
160
|
+
card.removeEventListener("pointerenter", enter);
|
|
161
|
+
card.removeEventListener("pointerleave", leave);
|
|
162
|
+
card.removeEventListener("pointerdown", press);
|
|
163
|
+
card.removeEventListener("focusin", focusIn);
|
|
164
|
+
card.removeEventListener("focusout", focusOut);
|
|
112
165
|
};
|
|
113
166
|
}
|
|
114
167
|
function add(card, item, addOptions = {}) {
|
|
115
168
|
entries.get(card)?.off();
|
|
116
|
-
const host = document.createElement(
|
|
117
|
-
host.className =
|
|
169
|
+
const host = document.createElement("div");
|
|
170
|
+
host.className = "fuda-live";
|
|
118
171
|
// It lies over the art and takes no press, so everything on the card still works. `.art ::slotted(*)` keeps it unseen until the card is ready.
|
|
119
|
-
host.style.cssText =
|
|
120
|
-
if (getComputedStyle(card).position ===
|
|
121
|
-
card.style.position =
|
|
172
|
+
host.style.cssText = "position:absolute;inset:0;pointer-events:none";
|
|
173
|
+
if (getComputedStyle(card).position === "static")
|
|
174
|
+
card.style.position = "relative";
|
|
122
175
|
card.append(host);
|
|
123
|
-
const entry = {
|
|
176
|
+
const entry = {
|
|
177
|
+
card,
|
|
178
|
+
item,
|
|
179
|
+
host,
|
|
180
|
+
angle: 0,
|
|
181
|
+
off: () => { },
|
|
182
|
+
...(addOptions.still
|
|
183
|
+
? { poster: addOptions.still, posterSrc: addOptions.still.getAttribute("src") ?? undefined }
|
|
184
|
+
: {}),
|
|
185
|
+
};
|
|
124
186
|
const unlisten = listen(entry);
|
|
125
187
|
entries.set(card, entry);
|
|
126
188
|
near?.observe(card);
|
|
@@ -137,7 +199,7 @@ export function createLiveCards(options) {
|
|
|
137
199
|
entry.view?.dispose();
|
|
138
200
|
putPosterBack(entry);
|
|
139
201
|
if (entry.poster)
|
|
140
|
-
entry.poster.style.visibility =
|
|
202
|
+
entry.poster.style.visibility = "";
|
|
141
203
|
host.remove();
|
|
142
204
|
};
|
|
143
205
|
return entry.off;
|
|
@@ -146,14 +208,20 @@ export function createLiveCards(options) {
|
|
|
146
208
|
add,
|
|
147
209
|
focus,
|
|
148
210
|
blur,
|
|
149
|
-
get focused() {
|
|
150
|
-
|
|
151
|
-
|
|
211
|
+
get focused() {
|
|
212
|
+
return focusedEntry?.card;
|
|
213
|
+
},
|
|
214
|
+
get stats() {
|
|
215
|
+
return renderer?.stats;
|
|
216
|
+
},
|
|
217
|
+
get renderer() {
|
|
218
|
+
return renderer;
|
|
219
|
+
},
|
|
152
220
|
dispose() {
|
|
153
221
|
disposed = true;
|
|
154
222
|
for (const entry of [...entries.values()])
|
|
155
223
|
entry.off();
|
|
156
|
-
document.removeEventListener(
|
|
224
|
+
document.removeEventListener("pointerdown", onPressAnywhere, true);
|
|
157
225
|
near?.disconnect();
|
|
158
226
|
renderer?.dispose();
|
|
159
227
|
},
|
package/dist/materials.d.ts
CHANGED
|
@@ -1,11 +1,43 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Where a number was read: the maker's or the standard's page, and what it says there.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { cardMaterial, type CardMaterialSource } from "@johnmorrisdotca/fuda-cards";
|
|
7
|
+
*
|
|
8
|
+
* const source: CardMaterialSource | undefined = cardMaterial("paper-310-black-core")?.source;
|
|
9
|
+
* console.log(source?.says); // Black Core Paper, 310gsm, 0.325mm, 13pt
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
2
12
|
export interface CardMaterialSource {
|
|
3
13
|
label: string;
|
|
4
14
|
url: string;
|
|
5
15
|
/** What the source says, in short. */
|
|
6
16
|
says: string;
|
|
7
17
|
}
|
|
8
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The kind of stock a material is: plain paper card, plastic, a thick trading-card stock or metal.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { cardMaterials, type CardMaterialGroup } from "@johnmorrisdotca/fuda-cards";
|
|
24
|
+
*
|
|
25
|
+
* const group: CardMaterialGroup = "metal";
|
|
26
|
+
* console.log(cardMaterials.filter((material) => material.group === group).map((material) => material.id)); // [ 'aluminium-0.8', 'steel-0.5' ]
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export type CardMaterialGroup = "paper" | "plastic" | "thick-card" | "metal";
|
|
30
|
+
/**
|
|
31
|
+
* A card material: a stock or a metal with a thickness read from a maker or a standard, and the colour its edge is drawn in.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { cardMaterial, type CardMaterial } from "@johnmorrisdotca/fuda-cards";
|
|
36
|
+
*
|
|
37
|
+
* const steel: CardMaterial | undefined = cardMaterial("steel-0.5");
|
|
38
|
+
* console.log(steel?.name, steel?.thicknessMm); // Stainless steel card, 0.5 mm 0.5
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
9
41
|
export interface CardMaterial {
|
|
10
42
|
id: string;
|
|
11
43
|
name: string;
|
|
@@ -16,18 +48,97 @@ export interface CardMaterial {
|
|
|
16
48
|
edge: string;
|
|
17
49
|
source: CardMaterialSource;
|
|
18
50
|
}
|
|
19
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* A count of cards for a stack, with where the number comes from: a deck of 52, a Pokémon deck of 60, a booster pack of about 10.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { stackPresets, type StackPreset } from "@johnmorrisdotca/fuda-cards";
|
|
57
|
+
*
|
|
58
|
+
* const first: StackPreset = stackPresets[0];
|
|
59
|
+
* console.log(first.name, first.count); // Playing cards, 52 52
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
20
62
|
export interface StackPreset {
|
|
21
63
|
id: string;
|
|
22
64
|
name: string;
|
|
23
65
|
count: number;
|
|
24
66
|
source: CardMaterialSource;
|
|
25
67
|
}
|
|
26
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* One thousandth of an inch ("pt" in card and paper trade talk) in millimetres, 0.0254: a 13 pt card is 13 × 0.0254 mm.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { mmPerPoint } from "@johnmorrisdotca/fuda-cards";
|
|
74
|
+
*
|
|
75
|
+
* console.log(Math.round(13 * mmPerPoint * 1000) / 1000); // 0.33
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
27
78
|
export declare const mmPerPoint = 0.0254;
|
|
79
|
+
/**
|
|
80
|
+
* The thickness of a card that names no material or thickness: a playing card's black-core stock, 13 pt, 0.325 mm
|
|
81
|
+
* (Qin Printing, Black Core Paper 310 gsm, 0.325 mm).
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { DEFAULT_CARD_THICKNESS_MM, stackHeightMm } from "@johnmorrisdotca/fuda-cards";
|
|
86
|
+
*
|
|
87
|
+
* console.log(stackHeightMm(52, DEFAULT_CARD_THICKNESS_MM)); // 16.9
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare const DEFAULT_CARD_THICKNESS_MM = 0.325;
|
|
91
|
+
/**
|
|
92
|
+
* Every material the package knows, each with a thickness and the page it was read from. `docs/materials.md` lists them with their sources.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { cardMaterials } from "@johnmorrisdotca/fuda-cards";
|
|
97
|
+
*
|
|
98
|
+
* for (const material of cardMaterials.slice(0, 3)) console.log(material.id, material.thicknessMm);
|
|
99
|
+
* // paper-250 0.28
|
|
100
|
+
* // paper-310-black-core 0.325
|
|
101
|
+
* // paper-350 0.405
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
28
104
|
export declare const cardMaterials: readonly CardMaterial[];
|
|
105
|
+
/**
|
|
106
|
+
* The usual sizes of a stack of cards, each with where the number comes from.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { stackPresets } from "@johnmorrisdotca/fuda-cards";
|
|
111
|
+
*
|
|
112
|
+
* console.log(stackPresets.map((preset) => preset.count)); // [ 52, 54, 60, 10 ]
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
29
115
|
export declare const stackPresets: readonly StackPreset[];
|
|
30
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* The material with this id.
|
|
118
|
+
*
|
|
119
|
+
* @param id - A material's id, such as `paper-310-black-core` (the `material` attribute's value).
|
|
120
|
+
* @returns The material, or `undefined` when there is none with that id (and for `null` and `undefined`).
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { cardMaterial } from "@johnmorrisdotca/fuda-cards";
|
|
124
|
+
*
|
|
125
|
+
* console.log(cardMaterial("aluminium-0.8")?.thicknessMm); // 0.8
|
|
126
|
+
* console.log(cardMaterial("nothing")); // undefined
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
31
129
|
export declare function cardMaterial(id: string | null | undefined): CardMaterial | undefined;
|
|
32
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* The height of a stack of cards, in millimetres: the count times the thickness of one, to a thousandth of a millimetre.
|
|
132
|
+
*
|
|
133
|
+
* @param count - How many cards; a count under one is one card.
|
|
134
|
+
* @param thicknessMm - The thickness of one card in millimetres.
|
|
135
|
+
* @returns The height of the stack in millimetres.
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { cardMaterial, stackHeightMm } from "@johnmorrisdotca/fuda-cards";
|
|
139
|
+
*
|
|
140
|
+
* const stock = cardMaterial("paper-310-black-core");
|
|
141
|
+
* console.log(stackHeightMm(52, stock?.thicknessMm ?? 0.325)); // 16.9
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
33
144
|
export declare function stackHeightMm(count: number, thicknessMm: number): number;
|