let cards;
if (this.words) {
- const formstyle = window.getComputedStyle(this.form)
- const gridsize = [
- formstyle['grid-template-rows'], formstyle['grid-template-columns']
- ].map(val => val.match(/ /g).length + 1).reduce((x, y) => x * y) / 2;
- cards = this.words.splice(0, gridsize || 6).map(row => row[2]);
+ const aspect = this.form.clientWidth / window.innerHeight;
+ //TODO image ratio
+ let count = 35;
+ let cols = Math.round(Math.sqrt(count) * aspect**.5);
+ count = cols * Math.ceil(count / cols);
+ this.form.style['grid-template-columns'] = `repeat(${cols}, 1fr)`;
+ cards = this.words.splice(0, count>>1).map(row => row[2]);
cards.push(...cards.map(val => -val));
}
else {
/* cards */
#quiz {
display: grid;
- grid: repeat(3, 1fr) / repeat(4, 1fr);
+ grid: auto / repeat(6, 1fr);
grid-gap: 1ex;
- min-height: calc(100vh - 11.5ex);
-}
-@media (orientation: portrait) {
- #quiz {
- grid: repeat(6, 1fr) / repeat(2, 1fr);
- }
}
html {
overflow: hidden; /* rotation overflow on celebration */
}
figure {
- display: inline-block;
background: #224;
border: 1px solid #888;
perspective: 100em;
- position: relative;
}
figure:not(.turn):hover {
cursor: pointer;
-webkit-backface-visibility: hidden;
transform: rotateY(180deg); /* back */
transform-style: preserve-3d;
- -float: left; /* ff workaround to prevent click selection */
+ float: left; /* ff workaround to prevent click selection */
+ height: 100%;
+ object-fit: contain; /* center */
}
figure.mirror img {
transform: rotateY(180deg) scaleX(-1);
</style>
EOT
});
-if (my $gridsize = $get{grid}) {
- printf "<style>#quiz {grid: repeat(%d, 1fr) / repeat(%d, 1fr)}</style>",
- reverse split /\D+/, $gridsize;
- say '';
-}
say '<h1>memory</h1><p id="quiz"></p>';
say "<script>new WordMemory('/$wordlistbase.json')</script>";