@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/materials.js
CHANGED
|
@@ -1,48 +1,211 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* 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.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { mmPerPoint } from "@johnmorrisdotca/fuda-cards";
|
|
7
|
+
*
|
|
8
|
+
* console.log(Math.round(13 * mmPerPoint * 1000) / 1000); // 0.33
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
2
11
|
export const mmPerPoint = 0.0254;
|
|
12
|
+
/**
|
|
13
|
+
* The thickness of a card that names no material or thickness: a playing card's black-core stock, 13 pt, 0.325 mm
|
|
14
|
+
* (Qin Printing, Black Core Paper 310 gsm, 0.325 mm).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { DEFAULT_CARD_THICKNESS_MM, stackHeightMm } from "@johnmorrisdotca/fuda-cards";
|
|
19
|
+
*
|
|
20
|
+
* console.log(stackHeightMm(52, DEFAULT_CARD_THICKNESS_MM)); // 16.9
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const DEFAULT_CARD_THICKNESS_MM = 0.325;
|
|
3
24
|
const pt = (points) => Math.round(points * mmPerPoint * 1000) / 1000;
|
|
4
|
-
const qin = {
|
|
25
|
+
const qin = {
|
|
26
|
+
label: "Qin Printing, Custom Playing Card Printing",
|
|
27
|
+
url: "https://www.qinprinting.com/poker-card-printing/",
|
|
28
|
+
};
|
|
5
29
|
const holder = (points, slug) => ({
|
|
6
30
|
label: `Ultra PRO, ${points}PT ONE-TOUCH Magnetic Holder`,
|
|
7
31
|
url: `https://ultrapro.com/products/${slug}`,
|
|
8
|
-
says: `holds standard cards (2-1/2" x 3-1/2") up to ${points}pt in thickness
|
|
32
|
+
says: `holds standard cards (2-1/2" x 3-1/2") up to ${points}pt in thickness`,
|
|
9
33
|
});
|
|
10
34
|
const thick = (points, slug) => ({
|
|
11
35
|
id: `card-${points}pt`,
|
|
12
36
|
name: `Thick trading card, ${points} pt`,
|
|
13
|
-
group:
|
|
37
|
+
group: "thick-card",
|
|
14
38
|
thicknessMm: pt(points),
|
|
15
|
-
edge:
|
|
16
|
-
source: holder(points, slug)
|
|
39
|
+
edge: "#e8dfca",
|
|
40
|
+
source: holder(points, slug),
|
|
17
41
|
});
|
|
42
|
+
/**
|
|
43
|
+
* Every material the package knows, each with a thickness and the page it was read from. `docs/materials.md` lists them with their sources.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { cardMaterials } from "@johnmorrisdotca/fuda-cards";
|
|
48
|
+
*
|
|
49
|
+
* for (const material of cardMaterials.slice(0, 3)) console.log(material.id, material.thicknessMm);
|
|
50
|
+
* // paper-250 0.28
|
|
51
|
+
* // paper-310-black-core 0.325
|
|
52
|
+
* // paper-350 0.405
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
18
55
|
export const cardMaterials = [
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
56
|
+
{
|
|
57
|
+
id: "paper-250",
|
|
58
|
+
name: "Card stock, 250 gsm (11 pt)",
|
|
59
|
+
group: "paper",
|
|
60
|
+
thicknessMm: 0.28,
|
|
61
|
+
edge: "#efe9da",
|
|
62
|
+
source: { ...qin, says: "Premium Cardstock, 250gsm, 0.28mm, 11pt" },
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "paper-310-black-core",
|
|
66
|
+
name: "Playing-card stock, black core, 310 gsm (13 pt)",
|
|
67
|
+
group: "paper",
|
|
68
|
+
thicknessMm: 0.325,
|
|
69
|
+
edge: "#2a2a2e",
|
|
70
|
+
source: { ...qin, says: "Black Core Paper, 310gsm, 0.325mm, 13pt" },
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "paper-350",
|
|
74
|
+
name: "Heavy card stock, 350 gsm (16 pt)",
|
|
75
|
+
group: "paper",
|
|
76
|
+
thicknessMm: 0.405,
|
|
77
|
+
edge: "#e9e1cd",
|
|
78
|
+
source: { ...qin, says: "Premium Cardstock, 350gsm, 0.405mm, 16pt" },
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "plastic-id1",
|
|
82
|
+
name: "Plastic bank-size card (ID-1, PVC)",
|
|
83
|
+
group: "plastic",
|
|
84
|
+
thicknessMm: 0.76,
|
|
85
|
+
edge: "#f2f2ef",
|
|
86
|
+
source: {
|
|
87
|
+
label: "ISO/IEC 7810 ID-1, as summarised on Wikipedia",
|
|
88
|
+
url: "https://en.wikipedia.org/wiki/ISO/IEC_7810",
|
|
89
|
+
says: '"All card sizes have a thickness of 760±80 μm." Payment cards are generally PVC (Wikipedia, Payment card).',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
thick(35, "35pt-uv-one-touch-magnetic-holders-5ct"),
|
|
93
|
+
thick(55, "55pt-uv-one-touch-magnetic-holder"),
|
|
94
|
+
thick(75, "75pt-uv-one-touch-magnetic-holder"),
|
|
95
|
+
thick(100, "100pt-uv-one-touch-magnetic-holder"),
|
|
96
|
+
thick(130, "130pt-uv-one-touch-magnetic-holder"),
|
|
97
|
+
thick(180, "180pt-uv-one-touch-magnetic-holder"),
|
|
98
|
+
{
|
|
99
|
+
id: "booklet-175pt",
|
|
100
|
+
name: "Booklet card, 175 pt",
|
|
101
|
+
group: "thick-card",
|
|
102
|
+
thicknessMm: pt(175),
|
|
103
|
+
edge: "#e8dfca",
|
|
104
|
+
source: {
|
|
105
|
+
label: "Ultra PRO, 175PT Vertical Booklet Card ONE-TOUCH Magnetic Holder",
|
|
106
|
+
url: "https://ultrapro.com/products/175pt-vertical-booklet-card-uv-one-touch-magnetic-holder",
|
|
107
|
+
says: '"Sized to fit Vertical Booklets up to 175pt thickness"',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: "aluminium-0.8",
|
|
112
|
+
name: "Anodised aluminium card, 0.8 mm",
|
|
113
|
+
group: "metal",
|
|
114
|
+
thicknessMm: 0.8,
|
|
115
|
+
edge: "#c9ced4",
|
|
116
|
+
source: {
|
|
117
|
+
label: "ebamaz anodised aluminium business card blank, 86 x 54 x 0.8 mm (Wood Art Supply listing)",
|
|
118
|
+
url: "https://woodartsupply.com/products/ebamaz-metal-business-cards-anodized-aluminum-plaque-plate-86x54x0-8mm-silver-blank-10pcs",
|
|
119
|
+
says: '"Material: Anodized Aluminum", "Size: 86X54X0.8mm"',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: "steel-0.5",
|
|
124
|
+
name: "Stainless steel card, 0.5 mm",
|
|
125
|
+
group: "metal",
|
|
126
|
+
thicknessMm: 0.5,
|
|
127
|
+
edge: "#aab0b6",
|
|
128
|
+
source: {
|
|
129
|
+
label: "My Metal Business Card, Metal Business Card Thickness Guide",
|
|
130
|
+
url: "https://mymetalbusinesscard.com/blog/metal-business-card-thickness-guide/",
|
|
131
|
+
says: '"our standard metal business card thickness is 0.5mm"; "A 0.5mm stainless steel business card"',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
32
134
|
];
|
|
33
|
-
const wikiDeck = { label:
|
|
34
|
-
const wikiPokemon = {
|
|
135
|
+
const wikiDeck = { label: "Wikipedia, Playing card", url: "https://en.wikipedia.org/wiki/Playing_card" };
|
|
136
|
+
const wikiPokemon = {
|
|
137
|
+
label: "Wikipedia, Pokémon Trading Card Game",
|
|
138
|
+
url: "https://en.wikipedia.org/wiki/Pok%C3%A9mon_Trading_Card_Game",
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* The usual sizes of a stack of cards, each with where the number comes from.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { stackPresets } from "@johnmorrisdotca/fuda-cards";
|
|
146
|
+
*
|
|
147
|
+
* console.log(stackPresets.map((preset) => preset.count)); // [ 52, 54, 60, 10 ]
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
35
150
|
export const stackPresets = [
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
151
|
+
{
|
|
152
|
+
id: "deck-52",
|
|
153
|
+
name: "Playing cards, 52",
|
|
154
|
+
count: 52,
|
|
155
|
+
source: { ...wikiDeck, says: '"The 52-card deck is the most popular deck"' },
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: "deck-54",
|
|
159
|
+
name: "Playing cards with two jokers, 54",
|
|
160
|
+
count: 54,
|
|
161
|
+
source: {
|
|
162
|
+
...wikiDeck,
|
|
163
|
+
says: 'commercial packs "often include between one and six jokers, most often two", so 52 + 2',
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: "pokemon-deck",
|
|
168
|
+
name: "Pokémon TCG deck, 60",
|
|
169
|
+
count: 60,
|
|
170
|
+
source: { ...wikiPokemon, says: 'players "play with 60-card decks"' },
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: "pokemon-booster",
|
|
174
|
+
name: "Booster pack, about 10",
|
|
175
|
+
count: 10,
|
|
176
|
+
source: { ...wikiPokemon, says: '"a collector can pull 10 cards in total" from a booster pack' },
|
|
177
|
+
},
|
|
40
178
|
];
|
|
41
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* The material with this id.
|
|
181
|
+
*
|
|
182
|
+
* @param id - A material's id, such as `paper-310-black-core` (the `material` attribute's value).
|
|
183
|
+
* @returns The material, or `undefined` when there is none with that id (and for `null` and `undefined`).
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* import { cardMaterial } from "@johnmorrisdotca/fuda-cards";
|
|
187
|
+
*
|
|
188
|
+
* console.log(cardMaterial("aluminium-0.8")?.thicknessMm); // 0.8
|
|
189
|
+
* console.log(cardMaterial("nothing")); // undefined
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
42
192
|
export function cardMaterial(id) {
|
|
43
|
-
return cardMaterials.find(material => material.id === id);
|
|
193
|
+
return cardMaterials.find((material) => material.id === id);
|
|
44
194
|
}
|
|
45
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* The height of a stack of cards, in millimetres: the count times the thickness of one, to a thousandth of a millimetre.
|
|
197
|
+
*
|
|
198
|
+
* @param count - How many cards; a count under one is one card.
|
|
199
|
+
* @param thicknessMm - The thickness of one card in millimetres.
|
|
200
|
+
* @returns The height of the stack in millimetres.
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* import { cardMaterial, stackHeightMm } from "@johnmorrisdotca/fuda-cards";
|
|
204
|
+
*
|
|
205
|
+
* const stock = cardMaterial("paper-310-black-core");
|
|
206
|
+
* console.log(stackHeightMm(52, stock?.thicknessMm ?? 0.325)); // 16.9
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
46
209
|
export function stackHeightMm(count, thicknessMm) {
|
|
47
210
|
return Math.round(Math.max(1, Math.floor(count)) * thicknessMm * 1000) / 1000;
|
|
48
211
|
}
|
package/dist/motion.d.ts
ADDED
package/dist/motion.js
ADDED
package/dist/pile-card.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* It shares everything with the collection's deck through `pile.js`: the fan's layout, how a card lands and how it flies.
|
|
7
7
|
*/
|
|
8
|
-
import { fanBounds, fanLayout, fanRelative, fanShift, flight, normalizeLanding, timing } from
|
|
9
|
-
import { stackLayout } from
|
|
8
|
+
import { fanBounds, fanLayout, fanRelative, fanShift, flight, normalizeLanding, timing } from "./pile.js";
|
|
9
|
+
import { stackLayout, stillsHtml } from "./stack.js";
|
|
10
10
|
const states = new WeakMap();
|
|
11
11
|
/** The gap between the stack and the pile at its side, in card widths (the collection's deck uses the same 0.28). */
|
|
12
12
|
const GAP = 0.28;
|
|
@@ -16,28 +16,35 @@ const PILE_CSS = `:host{position:relative}.rotation{position:relative}:host(:not
|
|
|
16
16
|
:host([flipped]) .card.fanned{transform:translate(calc(var(--fx,0) * 100cqw),0) rotate(calc(var(--fa,0) * 1deg)) rotateY(180deg)}
|
|
17
17
|
.still{transition:transform var(--fuda-move,.65s) cubic-bezier(.2,.8,.2,1),transform-origin var(--fuda-move,.65s) cubic-bezier(.2,.8,.2,1);transition-delay:calc(var(--j,0) * var(--stag,22ms))}
|
|
18
18
|
.card.fanned .still{transform-origin:50% 165%;transform:translate3d(calc(var(--rx,0) * 100cqw),calc(var(--ry,0) * 100cqw),calc(var(--t) / -2 - var(--j,1) * 1.5px)) rotate(calc(var(--ra,0) * 1deg));transition-delay:calc(var(--j,0) * var(--stag,28ms))}
|
|
19
|
-
.still.far{display:none}.still.faced{background:none;border:0;transform-style:preserve-3d}.still .face,.flyer .face,.discard .face{position:absolute;inset:0}
|
|
19
|
+
.still.far{display:none}.still.faced{background:none;border:0;padding:0;transform-style:preserve-3d}.still.faced>.inner,.still.faced>.shine{display:none}.still .face,.flyer .face,.discard .face{position:absolute;inset:0}
|
|
20
20
|
.art>img.copy{width:100%;height:100%;object-fit:contain;display:block}:host([motion="pan"]) .art>img.copy{object-fit:cover;object-position:var(--fuda-focus-x,50%) var(--fuda-focus-y,25%)}
|
|
21
21
|
.discard{position:absolute;left:0;top:0;width:100%;height:100%;transform-style:preserve-3d;translate:calc(var(--dx,1.28) * 100cqw) 0;transition:translate var(--fuda-move,.65s) cubic-bezier(.2,.8,.2,1);pointer-events:none}
|
|
22
22
|
.discard .card{transition:none}.discard[data-land=face-down] .card{transform:rotateY(180deg)}
|
|
23
|
-
.flyer{position:absolute;left:0;top:0;width:100%;height:100%;transform-style:preserve-3d;pointer-events:none;--t:calc(var(--mm,.
|
|
23
|
+
.flyer{position:absolute;left:0;top:0;width:100%;height:100%;transform-style:preserve-3d;pointer-events:none;--t:calc(var(--mm,.325) * 100cqw / 63)}.flyer .fly,.flyer .turn{position:absolute;inset:0;transform-style:preserve-3d}
|
|
24
24
|
.bar{position:absolute;left:50%;top:calc(100% + 14px);translate:-50% 0;display:flex;gap:.5rem;flex-wrap:wrap;justify-content:center;width:max-content;max-width:min(100vw - 24px,22rem);filter:none;font:600 .9rem system-ui,sans-serif}
|
|
25
25
|
.bar button{box-sizing:border-box;min-height:48px;min-width:48px;padding:.45rem .9rem;font:inherit;color:#f6f4f1;background:#2a2d3c;border:2px solid #8a8ca0;border-radius:.7rem;cursor:pointer}.bar button:hover{border-color:#ffd27e}.bar button[aria-pressed=true]{background:#ffd27e;border-color:#ffd27e;color:#241a05}.bar button:disabled{opacity:.45;cursor:default}.bar button:focus-visible{outline:3px solid #ffd27e;outline-offset:3px}
|
|
26
26
|
@media(prefers-reduced-motion:reduce){.card,.still,.discard{transition:none}}`;
|
|
27
|
-
function num(host, name, fallback) {
|
|
27
|
+
function num(host, name, fallback) {
|
|
28
|
+
const n = Number.parseFloat(host.getAttribute(name) ?? "");
|
|
29
|
+
return Number.isFinite(n) ? n : fallback;
|
|
30
|
+
}
|
|
28
31
|
/** Copies of the card's front and back faces for a card that is not the live one: the picture as an `img` copy (a 3D viewer is never copied), no ids, no Animate button. */
|
|
29
32
|
function faceCopies(host, root) {
|
|
30
|
-
const front = root.querySelector(
|
|
33
|
+
const front = root.querySelector(".card > .front").cloneNode(true);
|
|
34
|
+
const back = root.querySelector(".card > .back").cloneNode(true);
|
|
31
35
|
for (const el of [front, back]) {
|
|
32
|
-
el.querySelectorAll(
|
|
33
|
-
|
|
36
|
+
for (const marked of el.querySelectorAll("[id]"))
|
|
37
|
+
marked.removeAttribute("id");
|
|
38
|
+
for (const button of el.querySelectorAll(".motion-button"))
|
|
39
|
+
button.remove();
|
|
34
40
|
}
|
|
35
|
-
const slot = front.querySelector(
|
|
41
|
+
const slot = front.querySelector("slot");
|
|
42
|
+
const img = host.querySelector("img");
|
|
36
43
|
if (slot) {
|
|
37
44
|
if (img) {
|
|
38
45
|
const copy = img.cloneNode();
|
|
39
|
-
copy.removeAttribute(
|
|
40
|
-
copy.className =
|
|
46
|
+
copy.removeAttribute("id");
|
|
47
|
+
copy.className = "copy";
|
|
41
48
|
slot.replaceWith(copy);
|
|
42
49
|
}
|
|
43
50
|
else
|
|
@@ -46,15 +53,16 @@ function faceCopies(host, root) {
|
|
|
46
53
|
return [front, back];
|
|
47
54
|
}
|
|
48
55
|
function stillsMarkup(count, host) {
|
|
49
|
-
const messiness = num(host,
|
|
56
|
+
const messiness = num(host, "stack-messiness", 0.3);
|
|
57
|
+
const seed = num(host, "stack-seed", 1) + 7;
|
|
58
|
+
const depth = Math.min(52, Math.max(0, Math.floor(num(host, "stack-depth", 10))));
|
|
50
59
|
if (count < 2)
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
return places.map((p, at) => `<i class="still" style="--x:${p.x};--y:${p.y};--r:${p.rotate};--k:${count - places.length + at}"></i>`).join('');
|
|
60
|
+
return "";
|
|
61
|
+
return stillsHtml(stackLayout(count, { messiness, seed, depth }), count);
|
|
54
62
|
}
|
|
55
63
|
/** The pile of cards taken off: a thick block of `count` cards like the stack, its top card face up or turned over, at the stack's side. */
|
|
56
64
|
function drawDiscard(host, root, state, count, land, dx) {
|
|
57
|
-
const rotation = root.querySelector(
|
|
65
|
+
const rotation = root.querySelector(".rotation");
|
|
58
66
|
if (count < 1) {
|
|
59
67
|
state.discard?.remove();
|
|
60
68
|
state.discard = undefined;
|
|
@@ -62,53 +70,60 @@ function drawDiscard(host, root, state, count, land, dx) {
|
|
|
62
70
|
}
|
|
63
71
|
let box = state.discard;
|
|
64
72
|
if (!box) {
|
|
65
|
-
box = document.createElement(
|
|
66
|
-
box.className =
|
|
73
|
+
box = document.createElement("div");
|
|
74
|
+
box.className = "discard";
|
|
67
75
|
rotation.append(box);
|
|
68
76
|
state.discard = box;
|
|
69
77
|
}
|
|
70
78
|
box.dataset.land = land;
|
|
71
|
-
box.style.setProperty(
|
|
72
|
-
const live = root.querySelector(
|
|
73
|
-
copy
|
|
74
|
-
copy.
|
|
79
|
+
box.style.setProperty("--dx", String(dx));
|
|
80
|
+
const live = root.querySelector(".card");
|
|
81
|
+
const copy = live.cloneNode(true);
|
|
82
|
+
copy.className = "card";
|
|
83
|
+
copy.removeAttribute("style");
|
|
75
84
|
const [front, back] = faceCopies(host, root);
|
|
76
|
-
copy.querySelector(
|
|
77
|
-
copy.querySelector(
|
|
85
|
+
copy.querySelector(".front").replaceWith(front);
|
|
86
|
+
copy.querySelector(".back").replaceWith(back);
|
|
78
87
|
const mm = host.cardThicknessMm;
|
|
79
|
-
copy.style.setProperty(
|
|
80
|
-
copy.style.setProperty(
|
|
81
|
-
copy.classList.toggle(
|
|
82
|
-
copy.querySelector(
|
|
88
|
+
copy.style.setProperty("--mm", String(mm * count));
|
|
89
|
+
copy.style.setProperty("--mm1", String(mm));
|
|
90
|
+
copy.classList.toggle("stacked", count > 1);
|
|
91
|
+
copy.querySelector(".stills").innerHTML = stillsMarkup(count, host);
|
|
83
92
|
box.replaceChildren(copy);
|
|
84
93
|
}
|
|
85
94
|
function fanState(host, root, on) {
|
|
86
|
-
const card = root.querySelector(
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
const card = root.querySelector(".card");
|
|
96
|
+
const stills = Array.from(root.querySelectorAll(".card > .stills > .still"));
|
|
97
|
+
card.classList.toggle("fanned", on);
|
|
98
|
+
const n = Math.min(10, 1 + stills.length);
|
|
99
|
+
const places = fanLayout(n, num(host, "stack-seed", 1), 0.34);
|
|
100
|
+
const rel = fanRelative(places);
|
|
89
101
|
if (on) {
|
|
90
|
-
card.style.setProperty(
|
|
91
|
-
card.style.setProperty(
|
|
102
|
+
card.style.setProperty("--fx", String(places[0].x));
|
|
103
|
+
card.style.setProperty("--fa", String(places[0].angle));
|
|
92
104
|
const [front, back] = stills.length ? faceCopies(host, root) : [null, null];
|
|
93
105
|
stills.forEach((still, at) => {
|
|
94
106
|
const i = stills.length - at;
|
|
95
|
-
still.classList.toggle(
|
|
107
|
+
still.classList.toggle("far", i >= n);
|
|
96
108
|
if (i >= n)
|
|
97
109
|
return;
|
|
98
|
-
still.style.setProperty(
|
|
99
|
-
still.style.setProperty(
|
|
100
|
-
still.style.setProperty(
|
|
101
|
-
still.style.setProperty(
|
|
102
|
-
if (!still.classList.contains(
|
|
103
|
-
still.classList.add(
|
|
104
|
-
still.dataset.sig = host.innerHTML + host.getAttribute(
|
|
110
|
+
still.style.setProperty("--rx", String(rel[i].x));
|
|
111
|
+
still.style.setProperty("--ry", String(rel[i].y));
|
|
112
|
+
still.style.setProperty("--ra", String(rel[i].angle));
|
|
113
|
+
still.style.setProperty("--j", String(i));
|
|
114
|
+
if (!still.classList.contains("faced") || still.dataset.sig !== host.innerHTML + host.getAttribute("title")) {
|
|
115
|
+
still.classList.add("faced");
|
|
116
|
+
still.dataset.sig = host.innerHTML + host.getAttribute("title");
|
|
105
117
|
const [f, b] = [front.cloneNode(true), back.cloneNode(true)];
|
|
106
118
|
still.replaceChildren(f, b);
|
|
107
119
|
}
|
|
108
120
|
});
|
|
109
121
|
}
|
|
110
122
|
else {
|
|
111
|
-
stills.forEach((still, at) => {
|
|
123
|
+
stills.forEach((still, at) => {
|
|
124
|
+
still.style.setProperty("--j", String(stills.length - at));
|
|
125
|
+
still.classList.remove("far");
|
|
126
|
+
});
|
|
112
127
|
}
|
|
113
128
|
return { places, bounds: on ? fanBounds(places) : { left: 0, right: 0, top: 0, bottom: 0 } };
|
|
114
129
|
}
|
|
@@ -119,59 +134,83 @@ export function applyPile(host, root) {
|
|
|
119
134
|
state = { taken: 0, token: 0 };
|
|
120
135
|
states.set(host, state);
|
|
121
136
|
}
|
|
122
|
-
if (!root.querySelector(
|
|
123
|
-
const style = document.createElement(
|
|
124
|
-
style.dataset.pile =
|
|
137
|
+
if (!root.querySelector("style[data-pile]")) {
|
|
138
|
+
const style = document.createElement("style");
|
|
139
|
+
style.dataset.pile = "";
|
|
125
140
|
style.textContent = PILE_CSS;
|
|
126
141
|
root.append(style);
|
|
127
142
|
}
|
|
128
|
-
const t = timing(host, true)
|
|
129
|
-
host.
|
|
143
|
+
const t = timing(host, true);
|
|
144
|
+
const land = normalizeLanding(host.getAttribute("deck-land"));
|
|
145
|
+
host.style.setProperty("--fuda-move", t.on ? `${t.ms}ms` : "0s");
|
|
130
146
|
if (t.on)
|
|
131
|
-
host.style.removeProperty(
|
|
147
|
+
host.style.removeProperty("--stag");
|
|
132
148
|
else
|
|
133
|
-
host.style.setProperty(
|
|
134
|
-
const total = host.stackCount
|
|
135
|
-
const
|
|
149
|
+
host.style.setProperty("--stag", "0ms");
|
|
150
|
+
const total = host.stackCount;
|
|
151
|
+
const taken = Math.min(total - 1, Math.max(0, Math.floor(num(host, "taken-off", 0))));
|
|
152
|
+
const fan = host.fanOpen;
|
|
153
|
+
const was = state.taken;
|
|
154
|
+
const token = ++state.token;
|
|
136
155
|
const { places, bounds } = fanState(host, root, fan);
|
|
137
156
|
if (!fan) {
|
|
138
|
-
const faced = Array.from(root.querySelectorAll(
|
|
157
|
+
const faced = Array.from(root.querySelectorAll(".card > .stills > .still.faced"));
|
|
139
158
|
// The copies of the faces go once the cards have closed (at once when nothing is animated).
|
|
140
|
-
const clean = () => {
|
|
141
|
-
|
|
159
|
+
const clean = () => {
|
|
160
|
+
if (!host.fanOpen)
|
|
161
|
+
faced.forEach((s) => {
|
|
162
|
+
s.classList.remove("faced");
|
|
163
|
+
s.replaceChildren();
|
|
164
|
+
delete s.dataset.sig;
|
|
165
|
+
});
|
|
166
|
+
};
|
|
142
167
|
if (faced.length) {
|
|
143
168
|
if (t.on)
|
|
144
|
-
void Promise.all(root
|
|
169
|
+
void Promise.all(root
|
|
170
|
+
.querySelector(".card")
|
|
171
|
+
.getAnimations({ subtree: true })
|
|
172
|
+
.map((a) => a.finished.catch(() => undefined))).then(clean);
|
|
145
173
|
else
|
|
146
174
|
clean();
|
|
147
175
|
}
|
|
148
176
|
}
|
|
149
|
-
const dx = 1 + GAP + bounds.right
|
|
177
|
+
const dx = 1 + GAP + bounds.right;
|
|
178
|
+
const mmPx = (host.cardThicknessMm * host.offsetWidth) / 63;
|
|
150
179
|
// The pile at the side: where it is, how many cards and how its top card lies. While a card flies to it, it holds the cards that were there before.
|
|
151
180
|
const moving = taken !== was && t.on && host.offsetWidth > 0;
|
|
152
181
|
state.flyer?.remove();
|
|
153
182
|
state.flyer = undefined;
|
|
154
183
|
drawDiscard(host, root, state, moving && taken > was ? was : taken, land, dx);
|
|
155
184
|
if (moving) {
|
|
156
|
-
const off = taken > was
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
flyer.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
185
|
+
const off = taken > was;
|
|
186
|
+
const rotation = root.querySelector(".rotation");
|
|
187
|
+
const [front, back] = faceCopies(host, root);
|
|
188
|
+
const flyer = document.createElement("div");
|
|
189
|
+
flyer.className = "flyer";
|
|
190
|
+
flyer.style.setProperty("--mm", String(host.cardThicknessMm));
|
|
191
|
+
const fly = document.createElement("div");
|
|
192
|
+
fly.className = "fly";
|
|
193
|
+
const turn = document.createElement("div");
|
|
194
|
+
turn.className = "turn";
|
|
164
195
|
turn.append(front, back);
|
|
165
196
|
fly.append(turn);
|
|
166
197
|
flyer.append(fly);
|
|
167
198
|
rotation.append(flyer);
|
|
168
199
|
state.flyer = flyer;
|
|
169
|
-
const w = host.offsetWidth
|
|
170
|
-
const
|
|
200
|
+
const w = host.offsetWidth;
|
|
201
|
+
const heldBefore = off ? total - was : total - taken;
|
|
202
|
+
const zStack = (heldBefore * mmPx) / 2;
|
|
203
|
+
const zPile = (Math.max(1, off ? taken : was) * mmPx) / 2;
|
|
204
|
+
const lead = fan && places.length > 1 ? places[0] : null;
|
|
205
|
+
const shift = lead ? fanShift(lead) : { x: 0, y: 0 };
|
|
171
206
|
// The flyer sits at its landing place; it flies from (off) or to (back) the stack, where an open fan holds the top card.
|
|
172
|
-
flyer.style.transform = off
|
|
173
|
-
|
|
174
|
-
|
|
207
|
+
flyer.style.transform = off
|
|
208
|
+
? `translate3d(${dx * w}px,0,${zPile}px)`
|
|
209
|
+
: `translate3d(${shift.x * w}px,${shift.y * w}px,${zStack}px) rotate(${lead ? lead.angle : 0}deg)`;
|
|
210
|
+
const away = off
|
|
211
|
+
? { x: -dx * w + shift.x * w, y: shift.y * w, z: zStack - zPile }
|
|
212
|
+
: { x: dx * w - shift.x * w, y: -shift.y * w, z: zPile - zStack };
|
|
213
|
+
const anims = flight(fly, turn, away, land, off ? "off" : "back", Math.round(t.ms * 1.15), lead ? (off ? lead.angle : -lead.angle) : 0);
|
|
175
214
|
void Promise.all(anims.map((a) => a.finished)).then(() => {
|
|
176
215
|
if (token !== state.token)
|
|
177
216
|
return;
|
|
@@ -182,32 +221,40 @@ export function applyPile(host, root) {
|
|
|
182
221
|
}
|
|
183
222
|
state.taken = taken;
|
|
184
223
|
// The bar of three buttons, when asked for.
|
|
185
|
-
if (host.hasAttribute(
|
|
224
|
+
if (host.hasAttribute("pile-controls")) {
|
|
186
225
|
if (!state.bar) {
|
|
187
|
-
const bar = document.createElement(
|
|
188
|
-
bar.className =
|
|
189
|
-
bar.setAttribute(
|
|
190
|
-
bar.setAttribute(
|
|
191
|
-
const make = (label, run) => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
226
|
+
const bar = document.createElement("div");
|
|
227
|
+
bar.className = "bar";
|
|
228
|
+
bar.setAttribute("role", "group");
|
|
229
|
+
bar.setAttribute("aria-label", "Pile");
|
|
230
|
+
const make = (label, run) => {
|
|
231
|
+
const b = document.createElement("button");
|
|
232
|
+
b.type = "button";
|
|
233
|
+
b.textContent = label;
|
|
234
|
+
b.addEventListener("click", run);
|
|
235
|
+
return b;
|
|
236
|
+
};
|
|
237
|
+
const fanButton = make("Fan", () => {
|
|
238
|
+
if (host.getAttribute("fan") === "open")
|
|
239
|
+
host.removeAttribute("fan");
|
|
240
|
+
else
|
|
241
|
+
host.setAttribute("fan", "open");
|
|
242
|
+
});
|
|
243
|
+
fanButton.dataset.role = "fan";
|
|
244
|
+
fanButton.setAttribute("aria-pressed", "false");
|
|
245
|
+
const off = make("Take a card off", () => host.takeOff());
|
|
246
|
+
off.dataset.role = "off";
|
|
247
|
+
const back = make("Put it back", () => host.putBack());
|
|
248
|
+
back.dataset.role = "back";
|
|
202
249
|
bar.append(fanButton, off, back);
|
|
203
250
|
root.append(bar);
|
|
204
251
|
state.bar = bar;
|
|
205
252
|
}
|
|
206
253
|
const q = (role) => state.bar.querySelector(`[data-role=${role}]`);
|
|
207
|
-
q(
|
|
208
|
-
q(
|
|
209
|
-
q(
|
|
210
|
-
q(
|
|
254
|
+
q("fan").setAttribute("aria-pressed", String(fan));
|
|
255
|
+
q("fan").textContent = fan ? "Close the fan" : "Fan open";
|
|
256
|
+
q("off").disabled = taken >= total - 1;
|
|
257
|
+
q("back").disabled = taken < 1;
|
|
211
258
|
}
|
|
212
259
|
else if (state.bar) {
|
|
213
260
|
state.bar.remove();
|
|
@@ -217,7 +264,7 @@ export function applyPile(host, root) {
|
|
|
217
264
|
const next = { left: bounds.left, right, top: bounds.top, bottom: bounds.bottom };
|
|
218
265
|
const old = host.pileBounds;
|
|
219
266
|
host.pileBounds = next;
|
|
220
|
-
host.style.setProperty(
|
|
267
|
+
host.style.setProperty("--pivot", String((next.right - next.left) / 2));
|
|
221
268
|
if (old.left !== next.left || old.right !== next.right || old.top !== next.top || old.bottom !== next.bottom)
|
|
222
|
-
host.dispatchEvent(new CustomEvent(
|
|
269
|
+
host.dispatchEvent(new CustomEvent("fuda-pile", { detail: next }));
|
|
223
270
|
}
|