@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
@@ -1,73 +1,179 @@
1
- export { fanLayout, deckLandings, normalizeLanding } from './pile.js';
2
- export const collectionKinds = ['card', 'object'];
3
- /** True for an item that is a card: anything that does not say it is an object. Only a card turns, has a back and lands turned over. */
4
- export const isCard = (card) => card.kind !== 'object';
5
- /** The displays, in the order the buttons show them. `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 `collectionViewAliases`. */
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: 'deck', label: 'Overlapping Deck' }, { id: 'rolodex', label: 'Rolodex' }, { id: 'binder', label: 'Binder Pages' },
8
- { id: 'case', label: 'Convention Display Case' }, { id: 'random', label: 'Random Draw' },
9
- { id: 'story', label: 'Vertical Story Scroll' }, { id: 'wall', label: 'Sliding Gallery Wall' },
10
- { id: 'spotlight', label: 'Spotlight Carousel' }, { id: 'atlas', label: 'Card Table' }, { id: 'fan', label: 'Fan of Cards' }
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
- /** Display names that earlier versions accepted and that now open another display, so a page that sets them keeps working. */
13
- export const collectionViewAliases = { jukebox: 'deck', tower: 'deck' };
14
- export function parseCollection(value) {
15
- if (value && typeof value === 'object' && !Array.isArray(value) && 'cards' in value)
16
- value = value.cards;
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('Collection must be an array or an object containing a cards array.');
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 !== 'object')
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 !== 'string' || !c.name.trim() || typeof c.image !== 'string' || !c.image.trim())
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 === 'string' && c.id ? c.id : String(i);
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 !== 'string')
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 !== 'object' || Array.isArray(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 ['set', 'number', 'edition', 'condition', 'grade', 'notes'])
40
- if (m[key] !== undefined && typeof m[key] !== 'string')
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 ['year', 'quantity'])
43
- if (m[key] !== undefined && (typeof m[key] !== 'number' || !Number.isSafeInteger(m[key]) || m[key] < (key === 'quantity' ? 1 : 0)))
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 ['set', 'number', 'edition', 'condition', 'grade', 'notes'])
47
- if (typeof m[key] === 'string')
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 ['year', 'quantity'])
50
- if (typeof m[key] === 'number')
116
+ for (const key of ["year", "quantity"])
117
+ if (typeof m[key] === "number")
51
118
  metadata[key] = m[key];
52
119
  }
53
- return { id, name: c.name, image: c.image, ...(c.backImage ? { backImage: c.backImage } : {}), ...(c.kind === 'object' ? { kind: 'object' } : {}), ...(metadata ? { metadata } : {}) };
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
- /** Choose a matching card, avoiding the current card when another match exists. */
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.map((card, index) => ({ card, index })).filter(({ card }) => card.name.toLocaleLowerCase().includes(query));
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
- /** Return the first card index of a wrapped page. */
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
  }
@@ -0,0 +1,2 @@
1
+ import "./element.js";
2
+ import "./collection-element.js";
@@ -0,0 +1,3 @@
1
+ // Importing this module registers both elements, `<fuda-card>` and `<fuda-collection>`: the one line a page needs.
2
+ import "./element.js";
3
+ import "./collection-element.js";
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.3. */
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;