-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhmcards.js
339 lines (324 loc) · 10.3 KB
/
hmcards.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// hmcards.js - Harmelin Media Cards made w/ CSS
const flipCard = (targetCardId) => {
// return // just forget it
// One function to rule them (cards) all
let targetCard = targetCardId;
if (typeof(targetCardId) === "string") {
targetCard = document.getElementById(targetCardId);
}
// TODO: Consider resetting all the other cards
// const cards = document.getElementsByClassName('card')
// for (let i = 0; i < cards.length; i++) {
// cards[i].dataset.flipped = '0'; // reset everyone
// }
targetCard.dataset.flipped = targetCard.dataset?.flipped === '0' ? '1' : '0'
}
/*
TODO: Establish Card interaction basics
- mobile friendly
- touch friendly
- focus in on 1 card
- disable animations
-
*/
/* Mouse Interaction Code
transform: rotateY(var(--wobble-x)) rotateX(var(--wobble-y));
transform: rotateY(var(--wobble-x)) rotateX(var(--wobble-y));
background-position: var(--x) var(--y);
transition: transform 0.76s;
animation: shine 3s ease-in-out alternate infinite;
-- On devices with a mouse, let the relative position of the cursor wobble all the cards
@media (pointer: fine) {
.card[data-flipped="1"] {
transform: rotateY(var(--wobble-x)) rotateX(var(--wobble-y));
transition: transform 0.1s;
}
.shiny1 {
background-position: var(--x) var(--y);
}
*/
const styleString = `
.cardHolder {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100vw;
justify-content: center;
align-items: center;
}
.card:hover {
cursor: pointer;
}
.card {
position: relative;
margin: 3em;
height: 20rem;
width: 12rem;
transform-style: preserve-3d;
-webkit-perspective: 1000px;
perspective: 1000px;
transform: rotateY(0deg) rotateX(0deg);
backface-visibility: visible;
}
.cardInner {
border: 2px solid grey;
transform: rotateY(0deg);
transform-style: preserve-3d;
backface-visibility: visible;
position: absolute;
height: 100%;
width: 100%;
}
.cardFront, .cardBack {
transform: rotateY(0deg);
transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
}
.cardFront {
transform: rotateY(0deg);
position: absolute;
height: 100%;
width: 100%;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
color: black;
}
.cardBack {
transform: rotateY(180deg);
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
background-color: red;
}
.cardBackCircle {
border-radius: 100%;
background-color: firebrick;
border: 2px inset crimson;
height: 50%;
width: 50%;
}
.cardFrontName {
font-size: 1.25em;
padding: 0.25rem;
font-weight: 600;
}
.cardFrontPillarTeam {
font-size: 0.75rem;
padding: 0.25rem;
letter-spacing: 0.2rem;
}
.rookie {
border: 1px outset green;
background-color: limegreen;
font-size: 0.75rem;
float: right;
padding: 0.2rem;
margin: 0.2rem;
border-radius: 0.5rem;
position: absolute;
right: 0;
}
.cardFrontImage {
width: 100%;
min-height: 1rem;
aspect-ratio: 1 / 1;
}
.cardFrontNotes {
padding: 0.25rem;
font-size: 0.976rem;
font-style: italic;
font-weight: 300;
}
.shiny1, .shiny2 {
position: absolute;
height: 100%;
width: 100%;
}
@keyframes shineBig {
from {
background-position: 20% 40%;
} to {
background-position: 80% 60%;
}
}
@keyframes shine {
from {
background-position: 0% 50%;
} to {
background-position: 100% 50%;
}
}
@keyframes wobble {
from {
transform: rotateY(-30deg) scale(1);
} to {
transform: rotateY(30deg) scale(1);
}
}
@keyframes flipOnce {
from {
transform: rotateX(30deg);
} to {
transform: rotateX(360deg);
}
}
@keyframes flipOnce2 {
from {
transform: scale(1.25);
} to {
transform: scale(1);
}
}
@keyframes wobbleBig {
from {
transform: rotateY(-30deg) scale(1.25);
} to {
transform: rotateY(30deg) scale(1.25);
}
}
@keyframes wobble2 {
from {
transform: rotateY(-30deg) rotateX(-2deg) scale(1.5);
} to {
transform: rotateY(30deg) rotateX(2deg) scale(1.5);
}
}
.shiny1 { /* Specular */
background-image: linear-gradient(98.6deg ,black, green, blue, orange, black);
background-image: linear-gradient(98.6deg ,black, grey, black);
mix-blend-mode: color-dodge;
background-attachment: fixed;
background-size: 200%;
opacity: 0.46;
}
.shiny2 { /* Mask */
mix-blend-mode: multiply;
/*mix-blend-mode: color;
mix-blend-mode: luminosity;*/
background-image: url('images/fabric.jpeg');
background-size: cover;
background-position: center;
background-clip: border-box;
opacity: 0.46;
}
.link {
background-image: url('https://harmelin.com/wp-content/uploads/2019/09/HM_CorporateLogo_RGB.png');
background-size: contain;
}
.card[data-flipped="1"] {
transform: scale(1);
}
.card[data-flipped="1"] .cardInner {
animation: flipOnce2 1s ease-in-out;
}
.card[data-flipped="0"] {
animation: wobbleBig 3s ease-in-out alternate infinite;
}
.card[data-flipped="0"] .cardInner {
animation: flipOnce 1s ease-in-out;
}
.card[data-flipped="0"] .shiny1 {
animation: shineBig 3s ease-in-out alternate infinite;
}
`;
class HMCard extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
const cardName = this.getAttribute('name');
const cardId = `card${cardName}`.replaceAll(' ', '');
let cardClasses = `cardFront`;
// if (this.hasAttribute('cardbg') && this.getAttribute('cardbg') !== 'undefined') {
// cardClasses = `cardFront ${this.getAttribute('cardbg')}`;
// }
let rookieCard = '';
if (this.hasAttribute('rookie') && this.getAttribute('rookie') !== 'undefined') {
rookieCard = `<div class='rookie'>- Rookie Card -</div>`;
}
let shinyStuff = `<div id='${cardId}Shiny2' class='shiny2'></div><div id='${cardId}Shiny1' class='shiny1'></div>`;
let shinyColor = `white`;
if (this.hasAttribute('shinyColor') && this.getAttribute('shinyColor') !== 'undefined') {
shinyColor = this.getAttribute('shinyColor');
}
// if (this.hasAttribute('shiny') && this.getAttribute('shiny') !== 'undefined') {
// const curShiny = this.getAttribute('shiny');
// shinyStuff = `<div id='${cardId}Shiny2' class='shiny2 ${curShiny}'></div><div id='${cardId}Shiny1' class='shiny1 ${shinyColor}'></div>`;
// }
let imgUrl = 'avatar.png'
if (this.hasAttribute('img') && this.getAttribute('img') !== "undefined") {
imgUrl = this.getAttribute('img');
}
const bgColor = this.hasAttribute('backgroundcolor') && this.getAttribute('backgroundcolor') !== "undefined"
? this.getAttribute('backgroundcolor')
: false;
const bgImage = this.hasAttribute('backgroundimage') && this.getAttribute('backgroundimage') !== "undefined"
? this.getAttribute('backgroundimage')
: false;
const bgSize = this.hasAttribute('backgroundsize') && this.getAttribute('backgroundsize') !== "undefined"
? this.getAttribute('backgroundsize')
: false;
const bgPosition = this.hasAttribute('backgroundposition') && this.getAttribute('backgroundposition') !== "undefined"
? this.getAttribute('backgroundposition')
: false;
const bgOpacity = this.hasAttribute('opacity') && this.getAttribute('opacity') !== "undefined"
? this.getAttribute('opacity')
: 'center';
const shinyGradientColors = this.hasAttribute('shinycolor') && this.getAttribute('shinycolor') !== "undefined"
? this.getAttribute('shinycolor')
: 'gray';
// TODO: tabindex='0' and keyup listeners for enter/space
// https://developer.mozilla.org/en-US/docs/Web/API/Element/keyup_event
this.innerHTML = `<div>
<!-- TODO: styles one day -->
<style type='text/css'>
${styleString}
#${cardId}Front {
${bgColor ? `background-color: ${bgColor};` : ''}
background-color: ${bgColor ? bgColor : 'coral'};
}
#${cardId}Shiny2 {
background-clip: border-box;
${bgImage ? `background-image: url(${bgImage});` : ''}
${bgSize ? `background-size: ${bgSize};` : ''}
background-position: ${bgPosition};
opacity: ${bgOpacity ? bgOpacity : 0.5};
}
#${cardId}Shiny1 {
background-image: linear-gradient(98.6deg, black, ${shinyGradientColors}, black);
mix-blend-mode: color-dodge;
background-attachment: fixed;
background-size: 200%;
opacity: 0.5;
}
</style>
<div id=${cardId} class='card' data-flipped='1' onclick="flipCard(${cardId})">
<div class='cardInner'>
<div id=${cardId}Front class='${cardClasses}'>
${shinyStuff}
<div class='cardFrontName'>
${cardName}
${rookieCard}
</div>
<img class='cardFrontImage' src='images/${imgUrl}' alt='A photo of ${cardName}' />
<div class='cardFrontPillarTeam'>
${this.getAttribute('pillar')} - ${this.getAttribute('team')}
</div>
<div class='cardFrontNotes'>
${this.getAttribute('notes')}
</div>
</div>
<div class='cardBack'>
<div class='cardBackCircle'></div>
</div>
</div>
</div>
</div>`;
}
}
customElements.define('hm-card', HMCard);