/* ── THE CARD TURNS OVER WHEN YOU PRESS IT ──────────────────────────────── * * Taufik, 23 August 2026: "the card open popup transition, follow TCG POKEMON * style. its floating, fliping, 360 turn, just like a real card. for the back * you can just put NEUON AI logo for our website card. make it smooth, not * instant." * * So: press a card and it lifts off the page, turns a full circle — its back * passing the eye halfway round, with the NEUON logo on it — and settles. * The panel opens underneath while it turns, so the two read as one movement * rather than as a wait followed by a result. * * ── WHY THE BACK IS NOT A REAL BACK FACE ── * * The textbook way is two faces on a `preserve-3d` parent, each with * `backface-visibility: hidden`, which is what the Pokémon gallery does. It * cannot be done here, and the reason is one line in chapter.css: * * .acard { overflow: hidden; } * * A box that clips its content is flattened: the spec says `transform-style` * computes to `flat` whenever overflow is not visible, so a child at * `rotateY(180deg)` is drawn as a 2-D mirror rather than as the other side of * anything, and `backface-visibility` never comes into play. That clip is * what rounds the photograph off at the bottom of every chapter card, and * removing it to gain a flip would be trading something a visitor sees on * every page for something they see when they press. * * So the back is an opaque overlay that appears while the card is turned * away, counter-mirrored with `scaleX(-1)` so the logo reads the right way * round on a card that is itself mirrored at that moment. The eye cannot tell * the difference — it is the same picture at the same instant — and it works * inside a clipping box, which the honest version does not. * * ── AND WHY BOTH ANIMATIONS RUN AT `linear` ── * * The turn and the back's appearance are two animations that have to agree * about when the card is side-on. Under an eased curve, "half the time" is * not "half the rotation", and the logo appears while the front is still * facing you. They are both linear, and the float is shaped by the keyframes * rather than by the easing, so 25% of the way through is 90 degrees in both * of them by construction. */ (function () { var still = matchMedia('(prefers-reduced-motion: reduce)'); if (still.matches) return; /* Only things that actually open something. A card that is a heading or a photograph should not perform when it is brushed past. */ var WHAT = '.acard, .mobcard, .gcard, .ocard'; var MS = 900; var LOGO = '/assets/img/neuon-logo-white.png'; function backOf(card) { var back = card.querySelector(':scope > .cardback'); if (back) return back; back = document.createElement('span'); back.className = 'cardback'; back.setAttribute('aria-hidden', 'true'); var img = document.createElement('img'); img.src = LOGO; img.alt = ''; /* it is decoration on a card somebody just pressed — it must never be the reason the turn stutters */ img.decoding = 'async'; back.appendChild(img); card.appendChild(back); return back; } /* ── A CARD THAT FLIES DOES NOT ALSO TURN WHERE IT SITS ───────────────── * * Taufik, 23 August 2026: "make it have animation of the card spin and fly * into the middle … not sudden." * * The turn below is now only half the movement, and the other half belongs * to public/assets/js/arrive.js: a copy of the card leaves the page, turns, * and travels to the middle. If this ran as well, the card would turn twice * over — once in the air and once behind the panel it opened, in two * different places at the same time. * * So the turn stays for cards that open nothing (a card in a gallery, a game * tile) and stands down for every card that opens a box. The list lives in * arrive.js so there is one of it; the constant here is the fallback for a * page that does not load arrive.js at all, and must be kept the same. */ var FLIES = '[data-card], [data-pop], [data-mopen], [data-mitem]'; function flies(el) { if (window.NEUArrive && window.NEUArrive.flies) return window.NEUArrive.flies(el); return !!(el && el.closest && el.closest(FLIES)); } function turn(card) { if (flies(card)) return; if (card.classList.contains('is-turning')) return; backOf(card); card.classList.add('is-turning'); /* THE CLASS COMES OFF WHEN THE ANIMATION SAYS SO, and on a timer as well. `animationend` does not arrive in a tab that never painted, and a card left mid-turn for the life of the page is worse than a card that did not turn at all. */ var done = function () { card.classList.remove('is-turning'); card.removeEventListener('animationend', done); }; card.addEventListener('animationend', done); setTimeout(done, MS + 250); } /* ── ON `click`, AND THAT IS NOT THE OBVIOUS CHOICE ── * * `pointerdown` feels righter: a real card starts turning under the finger, * not when you let go. It was written that way and it was wrong here, for a * reason worth writing down. * * These cards sit in rails you can DRAG sideways, and rail.js marks the * track `is-dragging` the moment a pointer goes down on it — before this * would ever hear about it. So a guard against "they are dragging, not * pressing" is true on every press, and the turn never happened on any card * in a row. Which is most of them. * * `click` is the browser's own answer to that question: it does not fire * when a press turned into a drag, and it fires for Enter and Space with no * key handling of ours. It is also the same instant the panel opens, which * is what makes the turn and the drawer read as one movement rather than * two events that happen to be near each other. */ document.addEventListener('click', function (e) { var card = e.target.closest && e.target.closest(WHAT); if (card) turn(card); }, true); /* for the check suite, which has no frames to watch */ window.NEU_FLIP = { WHAT: WHAT, MS: MS, FLIES: FLIES, turn: turn, flies: flies }; })();