-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.html
542 lines (491 loc) · 20.9 KB
/
index.html
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="52 SVG playingcards in ONE Custom Element/Web Component <playing-card>">
<script defer src="https://hexedland.com/meisterbanner.js"></script>
<title>CardMeister <playing-card></title>
<link rel="icon"
href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 21 21'><rect width='100%' height='100%' fill='gold'/><text x='1' y='15'>cm</text></svg>"
type="image/svg+xml" />
<!-- this.index.html loads .min. or .full. javascript dynamically -->
<style id=theme_greenwhite>
body {
font-family: Arial, Helvetica, sans-serif;
visibility: hidden;
color: whitesmoke;
}
a:link,
a:visited,
a:hover,
a:active {
color: blue;
}
pre {
--size: 2.1em;
font-size: var(--size);
font-weight: bold;
margin-left: var(--size);
}
.footnote,
h1,
h3 {
text-shadow: 2px 2px 2px black;
margin-left: 1vw;
}
h3 {
text-shadow: 1px 1px 1px black;
}
h1 a,
h3 a {
text-shadow: 0 0;
}
.greencloth {
/* saves loading an image, looks better than a solid darkgreen background */
background-image: url('data:image/webp;base64,UklGRpgAAABXRUJQVlA4IIwAAAAwBACdASoeAB4APikSh0KhoQoCAAwBQllYz41AABFV/n8AItOaJepDavAA/vkKUe5BGtPR5aeKP/4hd7G2///gzv/f1X/gzv/BmUX9cJtST/Z9T/XsQq/MQV+1v8m2uukhu3nFYS/A5iTPpyXsMLAwk6xasWWFDPdx7OkWouLHKfqaoozRIW3R5D5MAA==');
background-size: cover;
}
</style>
<style>
.grid {
/* 13 ranks 4 suits */
display: grid;
grid-template-columns: repeat(13, 1fr);
grid-template-rows: 4fr;
grid-gap: 0.5vw;
margin: 5px;
}
iframe {
display: block;
width: 80vw;
height: 80vh;
margin: 0 auto;
}
#Usage {
grid-template-columns: 8fr 2fr 2fr 2fr;
grid-template-rows: 1;
}
#Straight {
grid-template-columns: 1fr 1fr;
grid-template-rows: 1;
}
#BigQueens {
grid-template-columns: repeat(4, 1fr);
margin: 0 10vw;
}
#DeckContainer {
/* BigCardt 3fr on the right */
grid-template-columns: 10fr 3fr;
grid-template-rows: 1;
}
.newrow {
/* force a new grid row in examples */
grid-column-start: 1;
}
/* playing-card {
width: 92px;
height: 134px;
} */
playing-card img {
/* can style IMG created by Custom Element */
border: 2px solid var(--cardborder, transparent);
border-radius: 8px;
/* filter: grayscale(); */
}
#Deck playing-card:hover {
--cardborder: yellowgreen;
}
[queen] {
transform: rotate(5deg);
}
[ace]+[two],
[two]+[three],
[three]+[four],
[four]+[five],
[five]+[six],
[six]+[seven],
[seven]+[eight],
[eight]+[nine],
[nine]+[ten],
[ten]+[jack],
[jack]+[queen],
[queen]+[king],
[king]+[ace] {
/* two follows ace, three follows two etc. */
/* testing card order and easy CSS selection */
--cardborder: darkgreen;
filter: unset;
}
.notfullversion {
/* margin: 10vh 0; */
}
.fullversion {
display: none;
}
</style>
<style id=fullversion onload="this.disabled=true">
.notfullversion {
display: none;
}
.fullversion {
display: block;
}
</style>
<style id=showAttributes onload="this.disabled=true">
/* display used playing-card attributes over card */
playing-card {
position: relative;
}
playing-card:after {
position: absolute;
top: -20;
left: 0;
box-sizing: border-box;
padding: 1px;
margin: 0 auto;
width: 100%;
background: orange;
color: black;
font-size: 13px;
border: 1px solid green;
white-space: pre-wrap;
content: attr(doc);
overflow: visible;
word-wrap: break-word;
z-index: 1;
}
</style>
</head>
<body class="greencloth">
<!-- <playing-card suit="" rank="" id=testcard style=width:30vw;display:none></playing-card> -->
<h2>Version #1 2018 (16 KB) - Version #2 2024 (reduced to 14 KB)</h2>
<h1>52 SVG playingcards in one <span id=ElementGZsize>14</span> KB<span class=notfullversion>¹</span> Custom
Element <playing-card>️</h1>
<h3>No Frameworks No Dependencies No external SVG files! All SVG is created by
the (Autonomous) Custom Element - <a href="https://github.com/cardmeister/cardmeister.github.io">Github &
Documentation</a> </h3>
<div id=DeckContainer class=grid>
<div id=Deck class=grid>
<!-- 52 cardts are injected here-->
</div>
<playing-card id=BigCardt cid=Kh></playing-card>
</div>
<hr>
<span class="footnote notfullversion">¹ raw SVG for 52 cards is 500 KB , <playing-card> GZipped is 14
KB</span>
<br>
<h1>GZip sizes</h1>
<div style="display:block;margin-left:3em;background:darkgrey;padding:5px">
<file-size src="https://cardmeister.github.io/elements.cardmeister.min.js"></file-size>
<file-size src="https://cardmeister.github.io/elements.cardmeister.full.js"></file-size>
</div>
<hr>
<h1>Using <playing-card>:</h1>
<div id=Usage class="grid">
<style>
.cardt1 {
color: yellow;
font-weight: bold;
text-shadow: 1px 1px 1px black;
}
.cardt2 {
color: white;
text-shadow: 2px 2px 1px black;
}
</style>
<pre style='color:lightgray;'> <head>
<script src<i>=</i><b class=cardt1>'elements.cardmeister.full.js'</b>></script>
</head>
<body>
<b class=cardt1><playing-card <i>cid=</i><span class=cardt2>As</span>></playing-card></b>
<b class=cardt1><playing-card <i>suit=</i><span class=cardt2>Hearts</span> <i>rank=</i><span
class=cardt2>10</span>></playing-card></b>
<b class=cardt1><playing-card <i>suit=</i><span class=cardt2>3</span> <i>rank=</i><span
class=cardt2>Queen</span>></playing-card></b>
</body>
</pre>
<playing-card cid=As></playing-card>
<playing-card suit=1 rank=10></playing-card>
<playing-card suit=Clubs rank=Queen></playing-card>
</div>
<br>
<hr>
<div class=notfullversion>
<h1>It is a card trick... How did I cheat to get the GZip size down to <b>14 KB</b> ?</h1>
<h1>The full version is 60 KB GZipped. See the difference: <a href='?#full'>index.html?full</a></h1>
</div>
<a id="full">
<!-- anchor for loading index.html#full version--></a>
<div class="fullversion">
<h1>60 KB for 12 different court images in the full version:</h1>
<div id=FullCourts class="grid">
</div>
<div>
<h1>In the <a href="index.html">14 KB version</a> all courts use the Hearts suit image:</h1>
<h3>Saves app. 70% of SVG data</h3>
</div>
<div id=MinCourts class="grid">
</div>
<div id=BigQueens class="grid">
<!-- <playing-card cid=Js suits=1111></playing-card>
<playing-card cid=Jh suits=1111></playing-card>
<playing-card cid=Jd suits=1111></playing-card>
<playing-card cid=Jc suits=1111></playing-card>
<playing-card cid=Qs suits=1111></playing-card>
<playing-card cid=Qh suits=1111></playing-card>
<playing-card cid=Qd suits=1111></playing-card>
<playing-card cid=Qc suits=1111></playing-card>
<playing-card cid=Ks suits=1111></playing-card>
<playing-card cid=Kh suits=1111></playing-card>
<playing-card cid=Kd suits=1111></playing-card>
<playing-card cid=Kc suits=1111></playing-card> -->
</div>
</div>
<hr>
<h1><playing-card attribute> configuration examples</h1>
<div class=fullversion>
<h3>click to see Element Attributes - Details at: <a
href='https://github.com/cardmeister/cardmeister.github.io'>GitHub
<playing-card> attribute/property
syntax</a>
</h3>
<h3>'play' an Ace card for some more advice</h3>
</div>
<div class=notfullversion>
<h3>See the <a href='?#full'>full version</a> for attribute examples on click</h3>
</div>
<div id=Configuration class="grid">
<!-- row -->
<playing-card suit=Hearts rank=Jack courts=201></playing-card>
<playing-card suit=Spades rank=Queen courts=201></playing-card>
<playing-card suit=Diamonds rank=King courts=201></playing-card>
<div></div>
<playing-card suit=0 rank=1 letters="CCCC"></playing-card>
<playing-card suit=1 rank=11 letters="AAAA"></playing-card>
<playing-card suit=3 rank=13 letters="RRRR"></playing-card>
<playing-card suit=2 rank=12 letters="DDDD"></playing-card>
<playing-card suit=0 rank=0></playing-card>
<playing-card suit=0 rank=13 letters="TTTT"></playing-card>
<div></div>
<playing-card rank=0 backcolor="green" backtext=" "></playing-card>
<playing-card rank=0 backcolor="#44F" backtext="YOURNAME" backtextcolor=#333></playing-card>
<!-- row -->
<playing-card rank=1 suit=0 suitcolor="#FFF," cardcolor="red" class="newrow"></playing-card>
<playing-card rank=1 suit=1 suitcolor=",yellow," cardcolor="darkgreen"></playing-card>
<playing-card rank=1 suit=2 suitcolor=",,black," cardcolor="dodgerblue" norank></playing-card>
<playing-card rank=1 suit=3 suitcolor=",,,red" cardcolor="yellow" norank=1></playing-card>
<div></div>
<!-- opacity -->
<playing-card rank=1 suit=0 opacity=1></playing-card>
<playing-card rank=1 suit=1 opacity=.75></playing-card>
<playing-card rank=1 suit=2 opacity=.5></playing-card>
<div></div>
<!-- destory court image colors -->
<playing-card suit=Hearts rank=Jack courtcolors=gold,red,blue,black,black,4></playing-card>
<playing-card suit=Spades rank=Queen courtcolors=#DB3,lightcoral,lightblue,slategray,#000,1></playing-card>
<playing-card suit=Diamonds rank=King courtcolors=green,green,green,green,black,4></playing-card>
<!-- row -->
<playing-card cid=F0 class="newrow"></playing-card>
<playing-card cid=FH></playing-card>
<playing-card cid=FD></playing-card>
<playing-card rank=1 suit=3 norank=1 cardcolor='transparent' opacity=.3 letters=' ' pips='3'></playing-card>
<div></div>
<!-- orignal Queen court images -->
<playing-card suit=S rank=Queen></playing-card>
<playing-card suit=H rank=Queen></playing-card>
<playing-card suit=D rank=Queen></playing-card>
<playing-card suit=C rank=Queen></playing-card>
<div></div>
<playing-card rank=1 suit=0 bordercolor=red borderradius=12 borderline=12></playing-card>
<playing-card rank=4 suit=0 bordercolor=hotpink borderradius=100% borderline=20></playing-card>
<playing-card rank=13 suit=H bordercolor=gold borderradius=12 borderline=38></playing-card>
</div>
<hr>
<h1>Extending <IMG> : creating 52 'Customized Built-In Elements'</h1>
<h3>Creates less DOM nodes but <i>is=</i> notation must be the full (Customized) Element name in
lowercase
<br>* requires a <a href="https://github.com/ungap/custom-elements-builtin"></a>polyfill</a> in Safari
</h3>
<h3 style="color: coral !important;">Update 2024: <i>Customized Built-In Elements</i> (not supported by APple/Safari)
are no longer created</h3>
<div id=Straight class=grid>
<div>
<pre><code><img is=ten-of-hearts>
<img is=jack-of-hearts>
<img is=queen-of-hearts>
<img is=king-of-hearts>
<img is=ace-of-spades suitcolor=darkred></code></pre>
</div>
<style>
.hand {
display: flex;
position: relative;
--cardwidth: 100%;
--cardheight: 100%;
/* --spread: 1; */
--spreaddeg: 20deg;
--spreaddistance: 40px;
--deg: calc(var(--spread)*var(--spreaddeg));
--distance: calc(var(--spread)*var(--spreaddistance));
--topoffset: calc(var(--spread)*15px);
margin-top: -8vh;
/* margin-left: calc(-0.5*var(--cardwidth)); */
}
.hand playing-card {
position: absolute;
transition: transform 2s;
}
.hand img{
height: calc( var(--cardheight) /2 );
width: calc( var(--cardwidth) /2 );
}
.hand playing-card:nth-child(1) {
left: calc(0*var(--distance));
top: calc(4*var(--topoffset));
transform: rotate(calc(-2*var(--deg)));
}
.hand playing-card:nth-child(2) {
left: calc(1*var(--distance));
top: calc(2*var(--topoffset));
transform: rotate(calc(-1*var(--deg)));
}
.hand playing-card:nth-child(3) {
left: calc(2*var(--distance));
top: calc(1*var(--topoffset));
}
.hand playing-card:nth-child(4) {
left: calc(3*var(--distance));
top: calc(2*var(--topoffset));
transform: rotate(calc(1*var(--deg)));
}
.hand playing-card:nth-child(5) {
left: calc(4*var(--distance));
top: calc(4*var(--topoffset));
transform: rotate(calc(2*var(--deg)));
}
</style>
<!-- <img is=ten-of-hearts>
<img is=jack-of-hearts>
<img is=queen-of-hearts>
<img is=king-of-hearts>
<img is=ace-of-spades suitcolor=darkred> -->
<div id=Hand1 class="hand">
<playing-card cid="TH"></playing-card>
<playing-card cid="JH"></playing-card>
<playing-card cid="QH"></playing-card>
<playing-card cid="KH"></playing-card>
<playing-card cid="AS" suitcolor=darkred></playing-card>
</div>
</div>
<div id=CardtUse></div>
<hr>
<h1><playing-card> is used in:</h1>
<h3><a href='https://card-ts.github.io/Solitaire/'>https://card-ts.github.io/Solitaire/</a> (click to open
in new
window, the IFrame version below has issues)</h3>
<style>
iframe {
pointer-events: none;
}
</style>
<iframe id=Solitaire title="playing-card Solitaire" src="https://card-ts.github.io/Solitaire/"></iframe>
<!-- executing after HTML/loaded -->
<script>
try {
//load min or full version dynamically in a script tag
var scriptTag = document.createElement('script');
var urlParams = new URLSearchParams(window.location.search);
//create single playing-card element
let createPlayingCard = (suitname, rankname) => {
let card = document.createElement('playing-card');// Custom Element is declare in elements.cardmeister.min/full.js
let setAttr = (x, v = '') => card.setAttribute(x, v);
setAttr('suit', suitname);
setAttr('rank', rankname);
try {
setAttr(rankname); // set rank and suitnames as attribute for easier CSS selectors
setAttr(suitname);
} catch (e) {
//disregard invalid attribute names
}
//setAttr((suitname == 'Spades' || suitname == 'Clubs') ? 'black' : 'red');// set black/red attributes for easier CSS selection
return card;
}
//dynamically load min or full version
scriptTag.type = 'text/javascript';
let element_version = 'min';
if (document.location.href.includes('full')) {
ElementGZsize.innerText = 60;//replace 14 KB in span text
element_version = 'full';
}
scriptTag.src = 'elements.cardmeister.' + element_version + '.js';
scriptTag.onload = () => {
console.log('loaded playing-card element', scriptTag.src);
let shuffle = x => x.sort(() => Math.random() - 0.5);// unused Yes, Fisher-Yates is better
//create 52 cards-t elements
let cards = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
.map(suit => 'Ace,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King'.split`,`
.map(rank => createPlayingCard(suit, rank)))
.flat();
//add cards to the DOM
Deck.append(...cards);// add 52 cards to DOM element Deck
//house keeping for showing full version
if (element_version == 'full') {
fullversion.disabled = false; // enable fullversion style
//inject cid cards in injectCardts array
let injectCardts = (element, settings = {}) => {
let cids = ['J', 'Q', 'K'].map(rank => ['s', 'h', 'd', 'c'].map(suit => rank + suit)).flat();
element.append(...cids.map(cid => {
let card = document.createElement("playing-card");
card.setAttribute('cid', cid);
Object.keys(settings).map(attr => card.setAttribute(attr, settings[attr]));
return card;
}));
}
injectCardts(FullCourts); // inject cardts in DOM element FullCourts
injectCardts(MinCourts, { suits: '1111' });
}
//if cid URL parameter defined show as bigcard
if (urlParams.has('cid')) BigCardt.cid = urlParams.get('cid');
//show big testcard
if (urlParams.has('testcard')) {
testcard.setAttribute('cid', urlParams.get('testcard'));
testcard.style.display = 'block';
}
//for every card in the Deck show the card big
[...document.querySelectorAll('#Deck playing-card')].forEach(cardt => {
cardt.addEventListener('mouseover', evt => {
BigCardt.firstChild.src = cardt.firstChild.src
});
});
//show body after all is done... FireFox does it different
document.body.style.visibility = 'initial';
// on every click show/hide attributes style
document.body.addEventListener('click', evt => {
let cardt = evt.target.parentNode;
if (element_version == 'full' && cardt.nodeName.includes('CARD')) showAttributes.disabled = !showAttributes.disabled;
if (cardt.getAttribute('rank') == 1 || cardt.cid == 'As') {
if (TheGambler.paused) TheGambler.play();
else TheGambler.pause();
}
});
setTimeout(() => {
TheGambler.setAttribute('src', 'thegambler.ogg');
TheGambler.pause();
}, 1000);
};
document.body.append(scriptTag);
new IntersectionObserver(entries => {
// console.log(entries[0].boundingClientRect, entries[0].target);
for (const entry of entries) {
if (entry.isIntersecting) {
Hand1.style.setProperty('--spread', 1);
}
}
}).observe(document.querySelector("#CardtUse"));
} catch (e) {
}
</script>
<audio src="" id="TheGambler" type="audio/ogg"></audio>
<script src="https://file-size.github.io/element.js"></script>
</body>
</html>