@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,126 @@
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
+ */
16
+ export interface LiveScene extends Scene3D {
17
+ object?: {
18
+ rotation: {
19
+ y: number;
20
+ };
21
+ };
22
+ }
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
+ */
41
+ export interface LiveItem<T extends ThreeLike = ThreeLike> {
42
+ key: string;
43
+ build(context: BuildContext<T>): LiveScene | Promise<LiveScene>;
44
+ }
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"> {
57
+ /** Seconds for one turn of the card in focus (12). 0 does not turn it. */
58
+ turnSeconds?: number;
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. */
60
+ dwellMs?: number;
61
+ /** How far outside the view a card with no picture of its own gets its still made, in pixels (300). */
62
+ lookAheadPx?: number;
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
+ */
75
+ export interface AddOptions {
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. */
77
+ still?: HTMLImageElement;
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
+ */
91
+ export interface LiveCards<T extends ThreeLike = ThreeLike> {
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. */
93
+ add(card: HTMLElement, item: LiveItem<T>, options?: AddOptions): () => void;
94
+ /** Put this card in focus: it takes the context, and the card that had it freezes to a picture at its last angle. False if it did not go live (another took it, reduced motion, no WebGL). */
95
+ focus(card: HTMLElement): Promise<boolean>;
96
+ /** No card in focus: the live one freezes to a picture and nothing draws. */
97
+ blur(): void;
98
+ /** The card in focus, if any. */
99
+ readonly focused: HTMLElement | undefined;
100
+ /** The shared renderer's own figures; undefined until it has been needed. */
101
+ readonly stats: RendererStats | undefined;
102
+ /** The shared renderer; undefined until it has been needed. */
103
+ readonly renderer: SharedRenderer<T> | undefined;
104
+ /** Take every card off and let go of the renderer. */
105
+ dispose(): void;
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
+ */
126
+ export declare function createLiveCards<T extends ThreeLike = ThreeLike>(options: LiveCardsOptions<T>): LiveCards<T>;
@@ -0,0 +1,229 @@
1
+ import { reducedMotion } from "./motion.js";
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. */
3
+ const STILL_STEP = 5;
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
+ */
23
+ export function createLiveCards(options) {
24
+ const { turnSeconds = 12, dwellMs = 150, lookAheadPx = 300, ...rendererOptions } = options;
25
+ const entries = new Map();
26
+ let renderer;
27
+ let loading;
28
+ let focusedEntry;
29
+ let disposed = false;
30
+ let asked = 0;
31
+ /** The renderer's module comes in only when a card first needs it: a page of pictures never loads it. */
32
+ const needRenderer = () => (loading ??= import("@johnmorrisdotca/kazoku-ui/renderer").then(({ createSharedRenderer }) => (renderer = createSharedRenderer(rendererOptions))));
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. */
34
+ const viewOf = (entry) => {
35
+ if (entry.view)
36
+ return Promise.resolve(entry.view);
37
+ entry.making ??= needRenderer().then((shared) => {
38
+ if (disposed || !entries.has(entry.card))
39
+ return undefined;
40
+ const turning = {
41
+ get key() {
42
+ return `${entry.item.key}@${(((Math.round(entry.angle / STILL_STEP) * STILL_STEP) % 360) + 360) % 360}`;
43
+ },
44
+ build: async (context) => {
45
+ const scene = await entry.item.build(context);
46
+ const turn = () => {
47
+ if (scene.object)
48
+ scene.object.rotation.y = (entry.angle * Math.PI) / 180;
49
+ };
50
+ turn();
51
+ return {
52
+ ...scene,
53
+ update(dt, now) {
54
+ const more = scene.update?.(dt, now) === true;
55
+ if (!turnSeconds || !scene.object || reducedMotion())
56
+ return more;
57
+ entry.angle += (360 * dt) / turnSeconds;
58
+ turn();
59
+ return true;
60
+ },
61
+ };
62
+ },
63
+ };
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;
72
+ };
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. */
74
+ const prepare = (entry) => {
75
+ if (entry.view) {
76
+ if (entry.poster && !entry.poster.getAttribute("src") && !entry.view.live)
77
+ putPosterBack(entry);
78
+ if (!entry.poster)
79
+ void entry.view.showStill();
80
+ return;
81
+ }
82
+ if (!entry.poster)
83
+ void viewOf(entry).then((view) => view?.showStill());
84
+ };
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;
94
+ async function focus(card) {
95
+ const entry = entries.get(card);
96
+ if (!entry || disposed || reducedMotion())
97
+ return false;
98
+ const mine = ++asked;
99
+ if (focusedEntry === entry && entry.view?.live)
100
+ return true;
101
+ focusedEntry = entry;
102
+ const view = await viewOf(entry);
103
+ if (!view || mine !== asked)
104
+ return false;
105
+ return view.focus();
106
+ }
107
+ function blur() {
108
+ asked += 1;
109
+ const entry = focusedEntry;
110
+ focusedEntry = undefined;
111
+ entry?.view?.blur();
112
+ }
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.
114
+ document.addEventListener("pointerdown", onPressAnywhere, true);
115
+ function onPressAnywhere(event) {
116
+ if (focusedEntry && !event.composedPath().includes(focusedEntry.card))
117
+ blur();
118
+ }
119
+ function listen(entry) {
120
+ const { card } = entry;
121
+ let timer;
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);
158
+ return () => {
159
+ wait();
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);
165
+ };
166
+ }
167
+ function add(card, item, addOptions = {}) {
168
+ entries.get(card)?.off();
169
+ const host = document.createElement("div");
170
+ host.className = "fuda-live";
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.
172
+ host.style.cssText = "position:absolute;inset:0;pointer-events:none";
173
+ if (getComputedStyle(card).position === "static")
174
+ card.style.position = "relative";
175
+ card.append(host);
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
+ };
186
+ const unlisten = listen(entry);
187
+ entries.set(card, entry);
188
+ near?.observe(card);
189
+ if (!near)
190
+ prepare(entry);
191
+ entry.off = () => {
192
+ if (entries.get(card) !== entry)
193
+ return;
194
+ if (focusedEntry === entry)
195
+ focusedEntry = undefined;
196
+ unlisten();
197
+ near?.unobserve(card);
198
+ entries.delete(card);
199
+ entry.view?.dispose();
200
+ putPosterBack(entry);
201
+ if (entry.poster)
202
+ entry.poster.style.visibility = "";
203
+ host.remove();
204
+ };
205
+ return entry.off;
206
+ }
207
+ return {
208
+ add,
209
+ focus,
210
+ blur,
211
+ get focused() {
212
+ return focusedEntry?.card;
213
+ },
214
+ get stats() {
215
+ return renderer?.stats;
216
+ },
217
+ get renderer() {
218
+ return renderer;
219
+ },
220
+ dispose() {
221
+ disposed = true;
222
+ for (const entry of [...entries.values()])
223
+ entry.off();
224
+ document.removeEventListener("pointerdown", onPressAnywhere, true);
225
+ near?.disconnect();
226
+ renderer?.dispose();
227
+ },
228
+ };
229
+ }
@@ -1,11 +1,43 @@
1
- /** A card material with a thickness taken from a maker or a standard, and where it was read. */
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
- export type CardMaterialGroup = 'paper' | 'plastic' | 'thick-card' | 'metal';
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
- /** A count of cards for a stack, with where the number comes from. */
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
- /** One thousandth of an inch ("pt" in card and paper trade talk) in millimetres. */
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
- /** The material with this id, or undefined. */
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
- /** Height of a stack of `count` cards `thicknessMm` thick, in millimetres. */
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;