@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/collection.js
CHANGED
|
@@ -1,73 +1,179 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export { deckLandings, fanLayout, normalizeLanding } from "./pile.js";
|
|
2
|
+
/**
|
|
3
|
+
* The two kinds of item, `card` and `object`.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { collectionKinds } from "@johnmorrisdotca/fuda-cards/collection";
|
|
8
|
+
*
|
|
9
|
+
* console.log(collectionKinds); // [ 'card', 'object' ]
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const collectionKinds = ["card", "object"];
|
|
13
|
+
/**
|
|
14
|
+
* Whether an item is a card: anything that does not say it is an object. Only a card turns, has a back and lands turned over.
|
|
15
|
+
*
|
|
16
|
+
* @param card - The item, or anything with its `kind`.
|
|
17
|
+
* @returns `true` for a card, `false` for an object.
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { isCard } from "@johnmorrisdotca/fuda-cards/collection";
|
|
21
|
+
*
|
|
22
|
+
* console.log(isCard({}), isCard({ kind: "object" })); // true false
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const isCard = (card) => card.kind !== "object";
|
|
26
|
+
/**
|
|
27
|
+
* The ten displays, in the order the buttons show them, each with the label on its button. `jukebox` and `tower` were two more names for the deck's pile of cards (no real counterpart for cards, and the same drawing), so they are no longer offered; see {@link collectionViewAliases}.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { collectionViews } from "@johnmorrisdotca/fuda-cards/collection";
|
|
32
|
+
*
|
|
33
|
+
* console.log(collectionViews.length, collectionViews[0].label); // 10 Overlapping Deck
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
6
36
|
export const collectionViews = [
|
|
7
|
-
{ id:
|
|
8
|
-
{ id:
|
|
9
|
-
{ id:
|
|
10
|
-
{ id:
|
|
37
|
+
{ id: "deck", label: "Overlapping Deck" },
|
|
38
|
+
{ id: "rolodex", label: "Rolodex" },
|
|
39
|
+
{ id: "binder", label: "Binder Pages" },
|
|
40
|
+
{ id: "case", label: "Convention Display Case" },
|
|
41
|
+
{ id: "random", label: "Random Draw" },
|
|
42
|
+
{ id: "story", label: "Vertical Story Scroll" },
|
|
43
|
+
{ id: "wall", label: "Sliding Gallery Wall" },
|
|
44
|
+
{ id: "spotlight", label: "Spotlight Carousel" },
|
|
45
|
+
{ id: "atlas", label: "Card Table" },
|
|
46
|
+
{ id: "fan", label: "Fan of Cards" },
|
|
11
47
|
];
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Display names that earlier versions accepted and that now open another display, so a page that sets them keeps working.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { collectionViewAliases } from "@johnmorrisdotca/fuda-cards/collection";
|
|
54
|
+
*
|
|
55
|
+
* console.log(collectionViewAliases.jukebox); // deck
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export const collectionViewAliases = { jukebox: "deck", tower: "deck" };
|
|
59
|
+
/**
|
|
60
|
+
* Check a collection and make it the shape the element draws: an array of cards, or an object with a `cards` array. A card without an id is numbered by its place.
|
|
61
|
+
*
|
|
62
|
+
* @param input - An array of items, or `{ cards: [...] }` as an exported collection has it.
|
|
63
|
+
* @returns A new array of cards; the input is not changed.
|
|
64
|
+
* @throws Error saying which card is wrong (its number, and what is wrong with it) for an input that is not an array, a card that is not an object, a missing name or image, a repeated id, a back or kind of the wrong type, or invalid metadata.
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { parseCollection } from "@johnmorrisdotca/fuda-cards/collection";
|
|
68
|
+
*
|
|
69
|
+
* console.log(parseCollection([{ name: "Card", image: "front.jpg" }])); // [ { id: '0', name: 'Card', image: 'front.jpg' } ]
|
|
70
|
+
* try {
|
|
71
|
+
* parseCollection([{ name: "Card" }]);
|
|
72
|
+
* } catch (error) {
|
|
73
|
+
* console.log((error as Error).message); // Card 1 needs a name and image URL.
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function parseCollection(input) {
|
|
78
|
+
const value = input && typeof input === "object" && !Array.isArray(input) && "cards" in input
|
|
79
|
+
? input.cards
|
|
80
|
+
: input;
|
|
17
81
|
if (!Array.isArray(value))
|
|
18
|
-
throw new Error(
|
|
82
|
+
throw new Error("Collection must be an array or an object containing a cards array.");
|
|
19
83
|
const ids = new Set();
|
|
20
84
|
return value.map((item, i) => {
|
|
21
|
-
if (!item || typeof item !==
|
|
85
|
+
if (!item || typeof item !== "object")
|
|
22
86
|
throw new Error(`Card ${i + 1} must be an object.`);
|
|
23
87
|
const c = item;
|
|
24
|
-
if (typeof c.name !==
|
|
88
|
+
if (typeof c.name !== "string" || !c.name.trim() || typeof c.image !== "string" || !c.image.trim())
|
|
25
89
|
throw new Error(`Card ${i + 1} needs a name and image URL.`);
|
|
26
|
-
const id = typeof c.id ===
|
|
90
|
+
const id = typeof c.id === "string" && c.id ? c.id : String(i);
|
|
27
91
|
if (ids.has(id))
|
|
28
92
|
throw new Error(`Duplicate card id: ${id}`);
|
|
29
93
|
ids.add(id);
|
|
30
|
-
if (c.backImage !== undefined && typeof c.backImage !==
|
|
94
|
+
if (c.backImage !== undefined && typeof c.backImage !== "string")
|
|
31
95
|
throw new Error(`Card ${i + 1} backImage must be a URL.`);
|
|
32
96
|
if (c.kind !== undefined && !collectionKinds.includes(c.kind))
|
|
33
97
|
throw new Error(`Card ${i + 1} kind must be "card" or "object".`);
|
|
34
98
|
let metadata;
|
|
35
99
|
if (c.metadata !== undefined) {
|
|
36
|
-
if (!c.metadata || typeof c.metadata !==
|
|
100
|
+
if (!c.metadata || typeof c.metadata !== "object" || Array.isArray(c.metadata))
|
|
37
101
|
throw new Error(`Card ${i + 1} metadata must be an object.`);
|
|
38
102
|
const m = c.metadata;
|
|
39
|
-
for (const key of [
|
|
40
|
-
if (m[key] !== undefined && typeof m[key] !==
|
|
103
|
+
for (const key of ["set", "number", "edition", "condition", "grade", "notes"])
|
|
104
|
+
if (m[key] !== undefined && typeof m[key] !== "string")
|
|
41
105
|
throw new Error(`Card ${i + 1} metadata.${key} must be a string.`);
|
|
42
|
-
for (const key of [
|
|
43
|
-
if (m[key] !== undefined &&
|
|
106
|
+
for (const key of ["year", "quantity"])
|
|
107
|
+
if (m[key] !== undefined &&
|
|
108
|
+
(typeof m[key] !== "number" ||
|
|
109
|
+
!Number.isSafeInteger(m[key]) ||
|
|
110
|
+
m[key] < (key === "quantity" ? 1 : 0)))
|
|
44
111
|
throw new Error(`Card ${i + 1} metadata.${key} must be a valid integer.`);
|
|
45
112
|
metadata = {};
|
|
46
|
-
for (const key of [
|
|
47
|
-
if (typeof m[key] ===
|
|
113
|
+
for (const key of ["set", "number", "edition", "condition", "grade", "notes"])
|
|
114
|
+
if (typeof m[key] === "string")
|
|
48
115
|
metadata[key] = m[key];
|
|
49
|
-
for (const key of [
|
|
50
|
-
if (typeof m[key] ===
|
|
116
|
+
for (const key of ["year", "quantity"])
|
|
117
|
+
if (typeof m[key] === "number")
|
|
51
118
|
metadata[key] = m[key];
|
|
52
119
|
}
|
|
53
|
-
return {
|
|
120
|
+
return {
|
|
121
|
+
id,
|
|
122
|
+
name: c.name,
|
|
123
|
+
image: c.image,
|
|
124
|
+
...(c.backImage ? { backImage: c.backImage } : {}),
|
|
125
|
+
...(c.kind === "object" ? { kind: "object" } : {}),
|
|
126
|
+
...(metadata ? { metadata } : {}),
|
|
127
|
+
};
|
|
54
128
|
});
|
|
55
129
|
}
|
|
56
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* Choose a card whose name contains the filter, avoiding the current card when another match exists.
|
|
132
|
+
*
|
|
133
|
+
* @param cards - The collection.
|
|
134
|
+
* @param current - The index of the card now on top.
|
|
135
|
+
* @param filter - Text the name must contain, whatever its case; spaces round it are ignored. Empty matches every card.
|
|
136
|
+
* @param random - A source of numbers from 0 up to but not including 1. Unless said, `Math.random`.
|
|
137
|
+
* @returns The index of the card to draw, or `null` when no card matches.
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { randomDrawIndex } from "@johnmorrisdotca/fuda-cards/collection";
|
|
141
|
+
*
|
|
142
|
+
* const cards = ["Alpha", "Beta", "Gamma"].map((name, i) => ({ id: String(i), name, image: `${i}.jpg` }));
|
|
143
|
+
* console.log(randomDrawIndex(cards, 0, "", () => 0)); // 1
|
|
144
|
+
* console.log(randomDrawIndex(cards, 0, "zzz")); // null
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
57
147
|
export function randomDrawIndex(cards, current, filter, random = Math.random) {
|
|
58
148
|
const query = filter.trim().toLocaleLowerCase();
|
|
59
|
-
const matches = cards
|
|
149
|
+
const matches = cards
|
|
150
|
+
.map((card, index) => ({ card, index }))
|
|
151
|
+
.filter(({ card }) => card.name.toLocaleLowerCase().includes(query));
|
|
60
152
|
if (!matches.length)
|
|
61
153
|
return null;
|
|
62
154
|
const alternatives = matches.filter(({ index }) => index !== current);
|
|
63
155
|
const pool = alternatives.length ? alternatives : matches;
|
|
64
156
|
return pool[Math.floor(random() * pool.length)].index;
|
|
65
157
|
}
|
|
66
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* The first card of the page that is `delta` pages away, wrapping round at either end.
|
|
160
|
+
*
|
|
161
|
+
* @param index - The index of any card on the page now.
|
|
162
|
+
* @param length - How many cards the collection holds.
|
|
163
|
+
* @param pageSize - How many cards a page holds.
|
|
164
|
+
* @param delta - How many pages to move: 1 forward, -1 back.
|
|
165
|
+
* @returns The index of the first card of that page; 0 for an empty collection.
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* import { movePage } from "@johnmorrisdotca/fuda-cards/collection";
|
|
169
|
+
*
|
|
170
|
+
* console.log(movePage(6, 7, 3, 1), movePage(0, 7, 3, -1)); // 0 6
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
67
173
|
export function movePage(index, length, pageSize, delta) {
|
|
68
174
|
if (length === 0)
|
|
69
175
|
return 0;
|
|
70
176
|
const pages = Math.ceil(length / pageSize);
|
|
71
177
|
const page = Math.floor(index / pageSize);
|
|
72
|
-
return (((page + delta) % pages + pages) % pages) * pageSize;
|
|
178
|
+
return ((((page + delta) % pages) + pages) % pages) * pageSize;
|
|
73
179
|
}
|
package/dist/element.d.ts
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<fuda-card>`: a collectible card frame around a picture you give it (or a live 3D view), drawn with a true thickness, an edge, a back, foil or matte,
|
|
3
|
+
* a stack, wear and the three looks. Import this module once to register the element; the attributes are listed in the card guide and in
|
|
4
|
+
* [`CardOptions`](api:CardOptions), and `cardAttributes(options)` writes them from an object.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts no-run
|
|
8
|
+
* import "@johnmorrisdotca/fuda-cards/element";
|
|
9
|
+
* import { cardAttributes } from "@johnmorrisdotca/fuda-cards";
|
|
10
|
+
*
|
|
11
|
+
* const card = document.createElement("fuda-card");
|
|
12
|
+
* for (const [name, value] of Object.entries(cardAttributes({ title: "Explorer One", stack: 10, wear: "near-mint" }))) card.setAttribute(name, value);
|
|
13
|
+
* document.body.append(card);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
1
16
|
export declare class FudaCard extends HTMLElement {
|
|
2
17
|
static observedAttributes: string[];
|
|
3
18
|
private focused;
|
|
4
19
|
private hushed;
|
|
5
20
|
private focusedAtPress?;
|
|
6
21
|
constructor();
|
|
22
|
+
/** The light follows the pointer over the card: a foil card shows its sheen where the pointer is (see `--fuda-sheen-x` and `--fuda-sheen-y`). */
|
|
23
|
+
private watchLight;
|
|
7
24
|
/** With `autoplay="focus"` the card in focus animates its art; leaving it (pointer, keyboard or a tap elsewhere) stops it. */
|
|
8
25
|
private watchFocus;
|
|
9
26
|
/** Put this card in focus (or out of it); the card that had focus is put out, so only one is ever in focus. */
|
|
@@ -13,10 +30,12 @@ export declare class FudaCard extends HTMLElement {
|
|
|
13
30
|
private toggleMotion;
|
|
14
31
|
/** The art stays invisible until the card has a size on screen and every slotted image has loaded, so it never shows outside the frame. */
|
|
15
32
|
private watchArt;
|
|
33
|
+
/** The front is hidden while `--fuda-yaw` has turned the back toward the reader. */
|
|
34
|
+
private watchFacing;
|
|
16
35
|
connectedCallback(): void;
|
|
17
36
|
disconnectedCallback(): void;
|
|
18
37
|
attributeChangedCallback(name: string): void;
|
|
19
|
-
/** Millimetres thick: the `thickness` attribute, else the `material`'s, else 0.
|
|
38
|
+
/** Millimetres thick: the `thickness` attribute, else the `material`'s, else the playing-card stock's 0.325 (`DEFAULT_CARD_THICKNESS_MM`). */
|
|
20
39
|
get cardThicknessMm(): number;
|
|
21
40
|
/** How many cards the stack holds: the `stack` attribute as a whole number from 1 (one card) to 1000. */
|
|
22
41
|
get stackCount(): number;
|