word/memory: manual grid size override option
[sheet.git] / word / memory.plp
index 8847713d0bfbcbb44a3388f30ca12002a317efc7..11520b19b483d3a6860742e62b6ca151db83b39f 100644 (file)
@@ -1,18 +1,34 @@
 <(../common.inc.plp)><:
 
+our $wordlistbase;
+
 Html({
        raw => <<'EOT',
 <script src="/word/put.min.js"></script>
+<script src="/word/quiz.js"></script>
 <script src="/word/memory.js"></script>
 <style>
 /* cards */
+#quiz {
+       display: grid;
+       grid: repeat(3, 1fr) / repeat(4, 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;
-       margin: 2px;
        perspective: 100em;
-       height: 300px;
        position: relative;
 }
 figure:not(.turn):hover {
@@ -24,25 +40,48 @@ figure, img {
 
 /* card faces */
 figure img {
-       height: 100%;
-       width: auto;
        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 */
+}
+figure.mirror img {
+       transform: rotateY(180deg) scaleX(-1);
 }
 
 /* turn results */
 figure.turn img {
        transform: rotateY(0deg);
 }
+figure.mirror.turn img {
+       transform: rotateY(0deg) scaleX(-1);
+}
 figure.bad img {
        filter: sepia(.5) hue-rotate(-45deg) saturate(2); /* red tint */
 }
 figure.good {
        opacity: .8;
 }
+
+.good figure {
+       animation: celebration 7s linear infinite;
+       background: none;
+       border: 0;
+       opacity: 1;
+}
+@keyframes celebration {
+       0% { filter: hue-rotate(0deg); transform: rotate(0deg) }
+       33% { filter: hue-rotate(180deg); transform: rotate(180deg) }
+       66% { filter: hue-rotate(360deg); transform: rotate(360deg) }
+       100% { filter: hue-rotate(360deg); transform: rotate(360deg) }
+}
 </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>";