@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/element.js
CHANGED
|
@@ -1,37 +1,123 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const defaults = {
|
|
1
|
+
import { cardMarkup } from "./card-markup.js";
|
|
2
|
+
import { cardMaterial, DEFAULT_CARD_THICKNESS_MM, stackHeightMm } from "./materials.js";
|
|
3
|
+
import { reducedMotion } from "./motion.js";
|
|
4
|
+
import { stackLayout, stillsHtml } from "./stack.js";
|
|
5
|
+
const template = document.createElement("template");
|
|
6
|
+
template.innerHTML = cardMarkup();
|
|
7
|
+
const defaults = {
|
|
8
|
+
title: "Untitled",
|
|
9
|
+
category: "COLLECTIBLE",
|
|
10
|
+
subtitle: "An item worth collecting",
|
|
11
|
+
description: "Add a description to tell its story.",
|
|
12
|
+
number: "NO. 001",
|
|
13
|
+
rarity: "✦",
|
|
14
|
+
};
|
|
8
15
|
/** The one card in focus: the card under the pointer, holding keyboard focus or last tapped. Only it may autoplay. */
|
|
9
16
|
let focusedCard = null;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
document.addEventListener("pointerdown", (event) => {
|
|
18
|
+
if (focusedCard && !event.composedPath().includes(focusedCard))
|
|
19
|
+
focusedCard.setFocused(false);
|
|
20
|
+
}, true);
|
|
21
|
+
/**
|
|
22
|
+
* `<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,
|
|
23
|
+
* 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
|
|
24
|
+
* [`CardOptions`](api:CardOptions), and `cardAttributes(options)` writes them from an object.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts no-run
|
|
28
|
+
* import "@johnmorrisdotca/fuda-cards/element";
|
|
29
|
+
* import { cardAttributes } from "@johnmorrisdotca/fuda-cards";
|
|
30
|
+
*
|
|
31
|
+
* const card = document.createElement("fuda-card");
|
|
32
|
+
* for (const [name, value] of Object.entries(cardAttributes({ title: "Explorer One", stack: 10, wear: "near-mint" }))) card.setAttribute(name, value);
|
|
33
|
+
* document.body.append(card);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
13
36
|
export class FudaCard extends HTMLElement {
|
|
14
|
-
static observedAttributes = [
|
|
37
|
+
static observedAttributes = [
|
|
38
|
+
"title",
|
|
39
|
+
"category",
|
|
40
|
+
"subtitle",
|
|
41
|
+
"description",
|
|
42
|
+
"number",
|
|
43
|
+
"rarity",
|
|
44
|
+
"motion",
|
|
45
|
+
"playing",
|
|
46
|
+
"thickness",
|
|
47
|
+
"autoplay",
|
|
48
|
+
"material",
|
|
49
|
+
"stack",
|
|
50
|
+
"stack-messiness",
|
|
51
|
+
"stack-seed",
|
|
52
|
+
"stack-depth",
|
|
53
|
+
"wear",
|
|
54
|
+
"wear-seed",
|
|
55
|
+
"wear-corners",
|
|
56
|
+
"wear-edges",
|
|
57
|
+
"wear-surface",
|
|
58
|
+
"wear-creases",
|
|
59
|
+
"fan",
|
|
60
|
+
"taken-off",
|
|
61
|
+
"deck-land",
|
|
62
|
+
"animate",
|
|
63
|
+
"speed",
|
|
64
|
+
"pile-controls",
|
|
65
|
+
];
|
|
15
66
|
focused = false;
|
|
16
67
|
hushed = false;
|
|
17
68
|
focusedAtPress;
|
|
18
|
-
constructor() {
|
|
69
|
+
constructor() {
|
|
70
|
+
super();
|
|
71
|
+
const root = this.attachShadow({ mode: "open" });
|
|
72
|
+
root.append(template.content.cloneNode(true));
|
|
73
|
+
const button = root.querySelector("button");
|
|
74
|
+
button?.addEventListener("click", () => this.toggleMotion());
|
|
75
|
+
this.watchArt(root);
|
|
76
|
+
this.watchFacing();
|
|
77
|
+
this.watchFocus(button);
|
|
78
|
+
this.watchLight();
|
|
79
|
+
}
|
|
80
|
+
/** 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`). */
|
|
81
|
+
watchLight() {
|
|
82
|
+
this.addEventListener("pointermove", (e) => {
|
|
83
|
+
const box = this.getBoundingClientRect();
|
|
84
|
+
if (!box.width || !box.height)
|
|
85
|
+
return;
|
|
86
|
+
this.style.setProperty("--fuda-sheen-x", String(Math.round(((e.clientX - box.left) / box.width) * 100)));
|
|
87
|
+
this.style.setProperty("--fuda-sheen-y", String(Math.round(((e.clientY - box.top) / box.height) * 100)));
|
|
88
|
+
});
|
|
89
|
+
this.addEventListener("pointerleave", () => {
|
|
90
|
+
this.style.removeProperty("--fuda-sheen-x");
|
|
91
|
+
this.style.removeProperty("--fuda-sheen-y");
|
|
92
|
+
});
|
|
93
|
+
}
|
|
19
94
|
/** With `autoplay="focus"` the card in focus animates its art; leaving it (pointer, keyboard or a tap elsewhere) stops it. */
|
|
20
95
|
watchFocus(button) {
|
|
21
|
-
const auto = () => this.getAttribute(
|
|
22
|
-
this.addEventListener(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.addEventListener(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
96
|
+
const auto = () => this.getAttribute("autoplay") === "focus";
|
|
97
|
+
this.addEventListener("pointerenter", (e) => {
|
|
98
|
+
if (auto() && e.pointerType !== "touch")
|
|
99
|
+
this.setFocused(true);
|
|
100
|
+
});
|
|
101
|
+
this.addEventListener("pointerleave", (e) => {
|
|
102
|
+
if (e.pointerType !== "touch" && !this.matches(":focus-within"))
|
|
103
|
+
this.setFocused(false);
|
|
104
|
+
});
|
|
105
|
+
this.addEventListener("pointerdown", (e) => {
|
|
106
|
+
if (!auto())
|
|
107
|
+
return;
|
|
108
|
+
if (e.composedPath().includes(button))
|
|
109
|
+
this.focusedAtPress = this.focused;
|
|
110
|
+
else
|
|
111
|
+
this.setFocused(true);
|
|
112
|
+
});
|
|
113
|
+
this.addEventListener("focusin", () => {
|
|
114
|
+
if (auto())
|
|
115
|
+
this.setFocused(true);
|
|
116
|
+
});
|
|
117
|
+
this.addEventListener("focusout", (e) => {
|
|
118
|
+
if (!this.contains(e.relatedTarget) && !this.matches(":hover"))
|
|
119
|
+
this.setFocused(false);
|
|
120
|
+
});
|
|
35
121
|
}
|
|
36
122
|
/** Put this card in focus (or out of it); the card that had focus is put out, so only one is ever in focus. */
|
|
37
123
|
setFocused(on) {
|
|
@@ -49,9 +135,13 @@ export class FudaCard extends HTMLElement {
|
|
|
49
135
|
this.render();
|
|
50
136
|
}
|
|
51
137
|
/** True while the art moves: `playing` is set, or the card is in focus with `autoplay="focus"` and the person has not paused it. Never autoplays with reduced motion. */
|
|
52
|
-
get isMoving() {
|
|
138
|
+
get isMoving() {
|
|
139
|
+
return (this.getAttribute("motion") === "pan" &&
|
|
140
|
+
(this.hasAttribute("playing") ||
|
|
141
|
+
(this.getAttribute("autoplay") === "focus" && this.focused && !this.hushed && !reducedMotion())));
|
|
142
|
+
}
|
|
53
143
|
toggleMotion() {
|
|
54
|
-
const auto = this.getAttribute(
|
|
144
|
+
const auto = this.getAttribute("autoplay") === "focus";
|
|
55
145
|
const was = this.focusedAtPress ?? this.focused;
|
|
56
146
|
this.focusedAtPress = undefined;
|
|
57
147
|
if (auto && !was) {
|
|
@@ -62,129 +152,230 @@ export class FudaCard extends HTMLElement {
|
|
|
62
152
|
}
|
|
63
153
|
const held = auto;
|
|
64
154
|
if (this.isMoving) {
|
|
65
|
-
this.removeAttribute(
|
|
155
|
+
this.removeAttribute("playing");
|
|
66
156
|
if (held)
|
|
67
157
|
this.hushed = true;
|
|
68
158
|
}
|
|
69
159
|
else {
|
|
70
160
|
this.hushed = false;
|
|
71
161
|
if (!held || reducedMotion())
|
|
72
|
-
this.setAttribute(
|
|
162
|
+
this.setAttribute("playing", "");
|
|
73
163
|
}
|
|
74
164
|
this.render();
|
|
75
165
|
}
|
|
76
166
|
/** 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. */
|
|
77
167
|
watchArt(root) {
|
|
78
|
-
const art = root.querySelector(
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
168
|
+
const art = root.querySelector(".art");
|
|
169
|
+
const slot = root.querySelector("slot");
|
|
170
|
+
const update = () => {
|
|
171
|
+
const laid = this.offsetWidth > 0 && this.offsetHeight > 0;
|
|
172
|
+
const waiting = slot
|
|
173
|
+
.assignedElements({ flatten: true })
|
|
174
|
+
.some((el) => el instanceof HTMLImageElement && !el.complete);
|
|
175
|
+
art.classList.toggle("ready", laid && !waiting);
|
|
176
|
+
};
|
|
177
|
+
slot.addEventListener("slotchange", update);
|
|
178
|
+
slot.addEventListener("load", update, true);
|
|
179
|
+
slot.addEventListener("error", update, true);
|
|
180
|
+
if (typeof ResizeObserver !== "undefined")
|
|
84
181
|
new ResizeObserver(update).observe(this);
|
|
85
182
|
else
|
|
86
183
|
requestAnimationFrame(update);
|
|
87
184
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
185
|
+
/** The front is hidden while `--fuda-yaw` has turned the back toward the reader. */
|
|
186
|
+
watchFacing() {
|
|
187
|
+
const sync = () => {
|
|
188
|
+
const raw = this.style.getPropertyValue("--fuda-yaw");
|
|
189
|
+
const yaw = Number.parseFloat(raw);
|
|
190
|
+
const turned = ((yaw % 360) + 360) % 360;
|
|
191
|
+
const back = raw !== "" && Number.isFinite(yaw) && turned > 90 && turned < 270;
|
|
192
|
+
this.toggleAttribute("data-back", back);
|
|
193
|
+
const front = this.shadowRoot?.querySelector(".front");
|
|
194
|
+
if (front instanceof HTMLElement)
|
|
195
|
+
front.style.display = back ? "none" : "";
|
|
196
|
+
// The host's drop-shadow keeps a flattened copy of the front, so it is off while the back faces the reader.
|
|
197
|
+
if (back) {
|
|
198
|
+
if (this.style.getPropertyValue("filter") !== "none")
|
|
199
|
+
this.style.setProperty("filter", "none");
|
|
200
|
+
}
|
|
201
|
+
else if (this.style.getPropertyValue("filter") === "none")
|
|
202
|
+
this.style.removeProperty("filter");
|
|
203
|
+
};
|
|
204
|
+
new MutationObserver(sync).observe(this, { attributes: true, attributeFilter: ["style"] });
|
|
205
|
+
sync();
|
|
206
|
+
}
|
|
207
|
+
connectedCallback() {
|
|
208
|
+
this.render();
|
|
209
|
+
}
|
|
210
|
+
disconnectedCallback() {
|
|
211
|
+
this.setFocused(false);
|
|
212
|
+
}
|
|
213
|
+
attributeChangedCallback(name) {
|
|
214
|
+
if (name === "autoplay" && this.getAttribute("autoplay") !== "focus")
|
|
215
|
+
this.setFocused(false);
|
|
216
|
+
if (name === "motion" && this.getAttribute("motion") !== "pan" && this.hasAttribute("playing"))
|
|
217
|
+
this.removeAttribute("playing");
|
|
218
|
+
if (this.shadowRoot)
|
|
219
|
+
this.render();
|
|
220
|
+
}
|
|
221
|
+
/** Millimetres thick: the `thickness` attribute, else the `material`'s, else the playing-card stock's 0.325 (`DEFAULT_CARD_THICKNESS_MM`). */
|
|
222
|
+
get cardThicknessMm() {
|
|
223
|
+
const asked = Number.parseFloat(this.getAttribute("thickness") ?? "");
|
|
224
|
+
return asked >= 0 ? asked : (cardMaterial(this.getAttribute("material"))?.thicknessMm ?? DEFAULT_CARD_THICKNESS_MM);
|
|
225
|
+
}
|
|
96
226
|
/** How many cards the stack holds: the `stack` attribute as a whole number from 1 (one card) to 1000. */
|
|
97
|
-
get stackCount() {
|
|
227
|
+
get stackCount() {
|
|
228
|
+
const n = Math.floor(Number.parseFloat(this.getAttribute("stack") ?? ""));
|
|
229
|
+
return n >= 1 ? Math.min(1000, n) : 1;
|
|
230
|
+
}
|
|
98
231
|
/** Height of the stack in millimetres: the count times a card's thickness. */
|
|
99
|
-
get stackHeight() {
|
|
232
|
+
get stackHeight() {
|
|
233
|
+
return stackHeightMm(this.stackCount, this.cardThicknessMm);
|
|
234
|
+
}
|
|
100
235
|
/** How many cards are still in the stack: `stack` less the `taken-off` ones (at least one stays). */
|
|
101
|
-
get heldCount() {
|
|
236
|
+
get heldCount() {
|
|
237
|
+
const n = this.stackCount;
|
|
238
|
+
const t = Math.floor(Number.parseFloat(this.getAttribute("taken-off") ?? ""));
|
|
239
|
+
return t > 0 ? Math.max(1, n - t) : n;
|
|
240
|
+
}
|
|
102
241
|
/** True while the stack is fanned open (`fan="open"`, with more than one card). */
|
|
103
|
-
get fanOpen() {
|
|
242
|
+
get fanOpen() {
|
|
243
|
+
return this.getAttribute("fan") === "open" && this.heldCount > 1;
|
|
244
|
+
}
|
|
104
245
|
/** How far the pile reaches beyond the card's own box, in card widths: an open fan and the pile of cards taken off. It is zero until a pile feature is used. Pages use it to fit the view; `fuda-pile` is sent when it changes. */
|
|
105
246
|
pileBounds = { left: 0, right: 0, top: 0, bottom: 0 };
|
|
106
247
|
/** Take the top card (or `count` cards) off the stack: it flies to a pile at the stack's side and lands as `deck-land` says. At least one card stays. */
|
|
107
|
-
takeOff(count = 1) {
|
|
248
|
+
takeOff(count = 1) {
|
|
249
|
+
const t = Math.max(0, Math.floor(Number.parseFloat(this.getAttribute("taken-off") ?? "")) || 0);
|
|
250
|
+
this.setAttribute("taken-off", String(Math.min(this.stackCount - 1, t + Math.max(1, count))));
|
|
251
|
+
}
|
|
108
252
|
/** Bring the card (or `count` cards) back from the pile onto the stack. */
|
|
109
|
-
putBack(count = 1) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
253
|
+
putBack(count = 1) {
|
|
254
|
+
const t = Math.max(0, Math.floor(Number.parseFloat(this.getAttribute("taken-off") ?? "")) || 0);
|
|
255
|
+
if (t - Math.max(1, count) > 0)
|
|
256
|
+
this.setAttribute("taken-off", String(t - Math.max(1, count)));
|
|
257
|
+
else
|
|
258
|
+
this.removeAttribute("taken-off");
|
|
259
|
+
}
|
|
113
260
|
pileUsed = false;
|
|
114
261
|
pileModule;
|
|
115
262
|
/** Fanning, the pile of cards taken off and the controls are drawn by a module that is loaded only when a stack asks for them; a card without them never loads it. */
|
|
116
263
|
applyPile() {
|
|
117
|
-
const asked = this.stackCount > 1 &&
|
|
264
|
+
const asked = this.stackCount > 1 &&
|
|
265
|
+
(this.getAttribute("fan") === "open" || this.hasAttribute("taken-off") || this.hasAttribute("pile-controls"));
|
|
118
266
|
if (!asked && !this.pileModule)
|
|
119
267
|
return;
|
|
120
268
|
if (asked)
|
|
121
269
|
this.pileUsed = true;
|
|
122
|
-
const draw = (m) => {
|
|
123
|
-
|
|
270
|
+
const draw = (m) => {
|
|
271
|
+
if (!this.shadowRoot)
|
|
272
|
+
return;
|
|
273
|
+
this.pileModule = m;
|
|
274
|
+
m.applyPile(this, this.shadowRoot);
|
|
275
|
+
};
|
|
124
276
|
if (this.pileModule)
|
|
125
277
|
draw(this.pileModule);
|
|
126
278
|
else
|
|
127
|
-
void import(
|
|
279
|
+
void import("./pile-card.js").then(draw);
|
|
128
280
|
}
|
|
129
|
-
wearKey =
|
|
281
|
+
wearKey = "";
|
|
130
282
|
wearToken = 0;
|
|
131
283
|
wearModule;
|
|
132
284
|
/** Wear (an imperfect card) is drawn by a module that is loaded only when a card asks for it; a perfect card never loads it. */
|
|
133
285
|
applyWear() {
|
|
134
|
-
const num = (name) => {
|
|
135
|
-
|
|
136
|
-
|
|
286
|
+
const num = (name) => {
|
|
287
|
+
const v = this.getAttribute(name);
|
|
288
|
+
return v === null || v.trim() === "" ? undefined : Number(v);
|
|
289
|
+
};
|
|
290
|
+
const key = ["wear", "wear-seed", "wear-corners", "wear-edges", "wear-surface", "wear-creases"]
|
|
291
|
+
.map((n) => this.getAttribute(n) ?? "")
|
|
292
|
+
.join("|");
|
|
293
|
+
const w = this.getAttribute("wear") ?? "";
|
|
294
|
+
const asked = (w !== "" && w !== "perfect" && w !== "0") ||
|
|
295
|
+
["wear-corners", "wear-edges", "wear-surface", "wear-creases"].some((n) => this.hasAttribute(n));
|
|
137
296
|
if (key === this.wearKey || (!asked && !this.wearModule))
|
|
138
297
|
return;
|
|
139
298
|
this.wearKey = key;
|
|
140
299
|
const token = ++this.wearToken;
|
|
141
|
-
const draw = (m) => {
|
|
142
|
-
|
|
300
|
+
const draw = (m) => {
|
|
301
|
+
if (token !== this.wearToken || !this.shadowRoot)
|
|
302
|
+
return;
|
|
303
|
+
this.wearModule = m;
|
|
304
|
+
m.applyWear(this.shadowRoot, {
|
|
305
|
+
wear: this.getAttribute("wear"),
|
|
306
|
+
seed: num("wear-seed"),
|
|
307
|
+
corners: num("wear-corners"),
|
|
308
|
+
edges: num("wear-edges"),
|
|
309
|
+
surface: num("wear-surface"),
|
|
310
|
+
creases: num("wear-creases"),
|
|
311
|
+
});
|
|
312
|
+
this.dispatchEvent(new CustomEvent("fuda-wear", { detail: { key } }));
|
|
313
|
+
};
|
|
143
314
|
if (this.wearModule)
|
|
144
315
|
draw(this.wearModule);
|
|
145
316
|
else
|
|
146
|
-
void import(
|
|
317
|
+
void import("./wear.js").then(draw);
|
|
147
318
|
}
|
|
148
319
|
/** The wear the card is drawn with: a preset's id, a number, or an empty string when it is perfect. */
|
|
149
|
-
get wear() {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
320
|
+
get wear() {
|
|
321
|
+
return this.getAttribute("wear") ?? "";
|
|
322
|
+
}
|
|
323
|
+
set wear(value) {
|
|
324
|
+
if (value)
|
|
325
|
+
this.setAttribute("wear", value);
|
|
326
|
+
else
|
|
327
|
+
this.removeAttribute("wear");
|
|
328
|
+
}
|
|
329
|
+
stillsKey = "";
|
|
155
330
|
/** The cards under the top one that are laid out nudged and turned; the rest of the stack is one block with a line for each card on its edge. */
|
|
156
331
|
drawStills(card, count) {
|
|
157
|
-
const num = (name, fallback) => {
|
|
158
|
-
|
|
332
|
+
const num = (name, fallback) => {
|
|
333
|
+
const n = Number.parseFloat(this.getAttribute(name) ?? "");
|
|
334
|
+
return Number.isFinite(n) ? n : fallback;
|
|
335
|
+
};
|
|
336
|
+
const messiness = num("stack-messiness", 0.3);
|
|
337
|
+
const seed = num("stack-seed", 1);
|
|
338
|
+
const depth = Math.min(52, Math.max(0, Math.floor(num("stack-depth", 10))));
|
|
159
339
|
const places = count > 1 && (messiness > 0 || this.pileUsed) ? stackLayout(count, { messiness, seed, depth }) : [];
|
|
160
|
-
const key = places.length ? JSON.stringify([count, messiness, seed, depth]) :
|
|
340
|
+
const key = places.length ? JSON.stringify([count, messiness, seed, depth]) : "";
|
|
161
341
|
if (key === this.stillsKey)
|
|
162
342
|
return;
|
|
163
343
|
this.stillsKey = key;
|
|
164
|
-
const holder = card.querySelector(
|
|
344
|
+
const holder = card.querySelector(".stills");
|
|
165
345
|
if (holder)
|
|
166
|
-
holder.innerHTML = places
|
|
167
|
-
}
|
|
168
|
-
render() {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
card.style.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
346
|
+
holder.innerHTML = stillsHtml(places, count);
|
|
347
|
+
}
|
|
348
|
+
render() {
|
|
349
|
+
const card = this.shadowRoot?.querySelector(".card");
|
|
350
|
+
if (card) {
|
|
351
|
+
const mm = this.cardThicknessMm;
|
|
352
|
+
const count = this.heldCount;
|
|
353
|
+
const fan = this.fanOpen;
|
|
354
|
+
const material = cardMaterial(this.getAttribute("material"));
|
|
355
|
+
card.style.setProperty("--mm", String(fan ? mm : mm * count));
|
|
356
|
+
card.style.setProperty("--mm1", String(mm));
|
|
357
|
+
card.classList.toggle("stacked", count > 1 && !fan);
|
|
358
|
+
if (material)
|
|
359
|
+
card.style.setProperty("--edge-color", material.edge);
|
|
360
|
+
else
|
|
361
|
+
card.style.removeProperty("--edge-color");
|
|
362
|
+
this.drawStills(card, count);
|
|
363
|
+
}
|
|
364
|
+
this.applyWear();
|
|
365
|
+
this.applyPile();
|
|
366
|
+
const button = this.shadowRoot?.querySelector(".motion-button");
|
|
367
|
+
if (button) {
|
|
368
|
+
button.hidden = this.getAttribute("motion") !== "pan";
|
|
369
|
+
const active = this.isMoving;
|
|
370
|
+
this.toggleAttribute("moving", active);
|
|
371
|
+
button.setAttribute("aria-pressed", String(active));
|
|
372
|
+
}
|
|
373
|
+
for (const key of FudaCard.observedAttributes) {
|
|
374
|
+
const node = this.shadowRoot?.getElementById(key);
|
|
375
|
+
if (node)
|
|
376
|
+
node.textContent = this.getAttribute(key) || (defaults[key] ?? "");
|
|
377
|
+
}
|
|
378
|
+
}
|
|
188
379
|
}
|
|
189
|
-
if (typeof customElements !==
|
|
190
|
-
customElements.define(
|
|
380
|
+
if (typeof customElements !== "undefined" && !customElements.get("fuda-card"))
|
|
381
|
+
customElements.define("fuda-card", FudaCard);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,52 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export type
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
rarity?: string;
|
|
11
|
-
variant?: CardVariant;
|
|
12
|
-
finish?: CardFinish;
|
|
13
|
-
/** Card thickness in millimetres at the 63 mm wide card size; overrides the material's. Default 0.3, 0 for a flat card. */
|
|
14
|
-
thickness?: number;
|
|
15
|
-
/** A material's id (see `cardMaterials`): its sourced thickness and edge colour. */
|
|
16
|
-
material?: string;
|
|
17
|
-
/** How many cards the stack holds (1 to 1000); the stack is that many times the card's thickness high. Default 1, one card. */
|
|
18
|
-
stack?: number;
|
|
19
|
-
/** From 0 (squared up) to 1 (very messy) for the cards under the top one. Default 0.3. */
|
|
20
|
-
stackMessiness?: number;
|
|
21
|
-
/** The stack's seed: the same seed lays the same stack the same way. Default 1. */
|
|
22
|
-
stackSeed?: number;
|
|
23
|
-
/** How many cards under the top one are laid out nudged and turned, at most 52. Default 10. */
|
|
24
|
-
stackDepth?: number;
|
|
25
|
-
/** A card that is not perfect: a preset's id (`mint`, `near-mint`, `lightly-played`, `moderately-played`, `heavily-played`, `damaged`) or a number from 0 to 1. Default: perfect, nothing drawn. */
|
|
26
|
-
wear?: string | number;
|
|
27
|
-
/** The wear's seed: the same seed draws the same marks the same way. Default 1. */
|
|
28
|
-
wearSeed?: number;
|
|
29
|
-
/** One level of the wear on its own, from 0 to 1, over the preset's. */
|
|
30
|
-
wearCorners?: number;
|
|
31
|
-
wearEdges?: number;
|
|
32
|
-
wearSurface?: number;
|
|
33
|
-
wearCreases?: number;
|
|
34
|
-
flipped?: boolean;
|
|
35
|
-
motion?: 'still' | 'pan';
|
|
36
|
-
playing?: boolean;
|
|
37
|
-
/** `focus`: the card in focus animates its art (needs `motion: 'pan'`); never with reduced motion. */
|
|
38
|
-
autoplay?: 'focus';
|
|
39
|
-
panDirection?: 'down' | 'up';
|
|
40
|
-
panLoop?: 'alternate' | 'restart';
|
|
41
|
-
cardSpin?: 'center' | 'corner';
|
|
42
|
-
cardSpinDirection?: 'normal' | 'reverse';
|
|
43
|
-
cardSpinPaused?: boolean;
|
|
44
|
-
}
|
|
45
|
-
export declare const cardVariants: readonly CardVariant[];
|
|
46
|
-
export declare const cardFinishes: readonly CardFinish[];
|
|
47
|
-
export { cardMaterials, cardMaterial, stackPresets, stackHeightMm, mmPerPoint } from './materials.js';
|
|
48
|
-
export type { CardMaterial, CardMaterialGroup, CardMaterialSource, StackPreset } from './materials.js';
|
|
49
|
-
export { stackLayout } from './stack.js';
|
|
50
|
-
export type { StackPlace, StackLayoutOptions } from './stack.js';
|
|
51
|
-
export { wearPresets, wearPreset, wearLevels, wearLayout, wearOutline, wearOverlaySvg } from './wear.js';
|
|
52
|
-
export type { WearPreset, WearLevels, WearOptions, WearFeatures, WearCorner, CornerKind } from './wear.js';
|
|
1
|
+
export type { CardFinish, CardOptions, CardVariant } from "./card-options.js";
|
|
2
|
+
export { cardAttributes, cardFinishes, cardVariants } from "./card-options.js";
|
|
3
|
+
export type { CardMaterial, CardMaterialGroup, CardMaterialSource, StackPreset } from "./materials.js";
|
|
4
|
+
export { cardMaterial, cardMaterials, DEFAULT_CARD_THICKNESS_MM, mmPerPoint, stackHeightMm, stackPresets, } from "./materials.js";
|
|
5
|
+
export type { StackLayoutOptions, StackPlace } from "./stack.js";
|
|
6
|
+
export { stackLayout } from "./stack.js";
|
|
7
|
+
export { VERSION } from "./version.js";
|
|
8
|
+
export type { CornerKind, WearCorner, WearFeatures, WearLevels, WearOptions, WearPreset } from "./wear.js";
|
|
9
|
+
export { wearLayout, wearLevels, wearOutline, wearOverlaySvg, wearPreset, wearPresets } from "./wear.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export { cardAttributes, cardFinishes, cardVariants } from "./card-options.js";
|
|
2
|
+
export { cardMaterial, cardMaterials, DEFAULT_CARD_THICKNESS_MM, mmPerPoint, stackHeightMm, stackPresets, } from "./materials.js";
|
|
3
|
+
export { stackLayout } from "./stack.js";
|
|
4
|
+
export { VERSION } from "./version.js";
|
|
5
|
+
export { wearLayout, wearLevels, wearOutline, wearOverlaySvg, wearPreset, wearPresets } from "./wear.js";
|