/* NEUON pack opening. * * Twelve packs ride the shared orbit ring, so they spin on their own and can be * dragged round to bring a different one to the front. Only the front pack can * be torn, and only by swiping its glowing strip — deliberately not a click, * so it feels like tearing foil rather than pressing a button. * * Self-contained: if the data block is missing or empty the section hides * itself rather than erroring. */ (function () { var stage = document.querySelector('[data-pack]'); var dataEl = document.getElementById('packData'); if (!stage || !dataEl) return; var cards = []; try { cards = JSON.parse(dataEl.textContent) || []; } catch (e) { cards = []; } var section = stage.closest('.pack'); if (!cards.length) { if (section) section.hidden = true; return; } var ring = stage.querySelector('[data-packring]'); var cardWrap = stage.querySelector('[data-card]'); var link = stage.querySelector('[data-cardlink]'); var img = stage.querySelector('[data-cardimg]'); var kindEl = stage.querySelector('[data-cardkind]'); var titleEl = stage.querySelector('[data-cardtitle]'); var lineEl = stage.querySelector('[data-cardline]'); var again = stage.querySelector('[data-again]'); var zoomer = document.getElementById('zoomer'); var reduced = matchMedia('(prefers-reduced-motion: reduce)').matches; var SWIPE = 90; // px of travel needed to tear it open var opening = false; var lastPick = -1; function pick() { if (cards.length === 1) return cards[0]; var i; do { i = Math.floor(Math.random() * cards.length); } while (i === lastPick); lastPick = i; return cards[i]; } /* ── THE CARD COMES OUT THE WAY EVERY OTHER CARD ON THIS SITE ARRIVES ──── * * Taufik, 23 August 2026: "this 'young innovator...' pack does not have the * same effect of the flip open popup card, make all cards same!" * * It did not. The ring faded, the card wrapper was unhidden, and `.is-in` * sprang the card up from scale(0.86) — a fifth entrance, on a site that * had just been given one. So the pack now hands itself to arrive.js like * the card popup, the graph stage, the film panel and the milestone box: * the torn pack turns, flies to the middle, stops, and only then does the * ring behind it go soft and the card take its place. * * The thing that flies is the PACK — what the reader was looking at and had * just torn — and it turns to show the NEUON back on the way, so what lands * in the middle is a NEUON card becoming the card that was inside it. * * `lock: false`, because this is the one box on the site that is not a * modal: it opens inside its own section with the page still readable and * scrollable around it. */ var flew = null; // the pack the copy has to fly home to function reveal(packNode) { if (opening) return; opening = true; var c = pick(); var fill = function () { img.src = c.img || ''; img.alt = ''; kindEl.textContent = c.kind || 'Chapter'; titleEl.textContent = c.title || ''; lineEl.textContent = c.line || ''; link.href = c.href || '/'; }; if (packNode) packNode.classList.add('is-torn'); flew = packNode ? packNode.querySelector('[data-packbody]') : null; /* the tear runs first and has its own 520ms; the flight starts from the pack as it is left, torn open */ setTimeout(function () { if (!window.NEUArrive) { fill(); ring.classList.add('is-gone'); cardWrap.hidden = false; cardWrap.classList.add('is-veiled', 'is-here'); return; } window.NEUArrive.open({ from: flew, root: cardWrap, panel: link, lock: false, fill: fill, /* the ring goes on the same beat as the blur, not before it — while the pack is still in the air the ring it came out of is part of what the reader is watching */ onVeil: function () { ring.classList.add('is-gone'); }, }); }, reduced ? 0 : 520); } function reset() { opening = false; ring.classList.remove('is-gone'); var back = function () { cardWrap.classList.remove('is-veiled', 'is-here'); stage.querySelectorAll('.is-torn').forEach(function (n) { n.classList.remove('is-torn'); }); flew = null; unpick(); }; /* THROUGH arrive.js, ALWAYS. It is holding the torn pack invisible while its copy is out — put the card away any other way and the pack the reader chose never comes back to the ring. */ if (!window.NEUArrive) { cardWrap.hidden = true; back(); return; } window.NEUArrive.close({ root: cardWrap, panel: link, from: flew, done: back }); } if (again) again.addEventListener('click', reset); /* ---- picking a pack ---- The ring keeps turning under the cursor. Clicking a pack picks it: the ring freezes, the rest blur back, and the chosen one comes to the centre, lifts, and starts pulsing — only then can it be swiped or spun by hand. */ var orbit = ring && ring._orbit; var picked = null; var flying = false; // a copy of the picked pack is in the air var hint = stage.querySelector('[data-pickhint]'); var swap = stage.querySelector('[data-swap]'); function unpick() { if (!picked) return; picked.classList.remove('is-picked', 'is-sizing'); var body = picked.querySelector('[data-packbody]'); body.style.removeProperty('--spin'); /* A pack dropped while its copy is still in the air would otherwise sit invisible in the ring until the flight remembered to put it back. */ flying = false; body.style.visibility = ''; picked = null; ring.classList.remove('has-pick'); if (section) section.classList.remove('has-pick'); if (orbit) orbit.unpin(); if (hint) hint.textContent = 'Tap a pack to pick it'; if (swap) swap.hidden = true; } /* ── PRESSING A PACK ──────────────────────────────────────────────────── * * Taufik, 23 August 2026: "when i press the pack, it directly popup, no * spin to center animation. create it to be same as others". * * It did. `pack-bounce` scaled it up where it stood, half a second, no turn * and no travel — the last pop left on the site. Now a copy of the pack * leaves the ring, turns a full circle, flies to the middle and stops, and * only then do the other packs go soft. Same five beats as every box on the * site; see public/assets/js/arrive.js. * * ── WHY IT IS NOT `open()` ── * * A picked pack is not a box that opens. It comes to the front and STAYS * there — still turnable by hand, still tearable — so there is no panel to * settle into and nothing to lock. `fly()` is the middle of the movement on * its own: the copy lands and hands back to the real pack, which by then is * sitting exactly where the copy stopped. * * ── AND WHY THE DESTINATION IS READ RATHER THAN CALCULATED ── * * The pack's final place is the front of the ring, times the picked state's * scale — and the ring is a 3-D carousel whose geometry comes out of CSS * custom properties that change at every breakpoint. Working it out in * arithmetic here would be a second copy of orbit.js's layout, and it would * be wrong the first time either of them was touched. * * So the ring is PUT where it is going, read, and put back, all inside one * block of script — the browser paints between blocks and not inside them, * so nothing of it is ever seen. The same trick arrive.js uses to find out * where a panel will be. */ function whereItLands(node, body) { if (!orbit) return null; var was = orbit.angle; orbit.bringToFront(orbit.nodes.indexOf(node)); orbit.angle = orbit.target; /* the ring, arrived */ orbit.layout(); /* NOT layout(true) — that would set angle FROM target */ node.classList.add('is-sizing'); /* the picked size, with nothing moving */ var box = body.getBoundingClientRect(); node.classList.remove('is-sizing'); orbit.angle = was; /* and back, unseen */ orbit.layout(); return box; } function pickNode(node) { if (opening || flying || picked === node) return; if (picked) unpick(); picked = node; var body = node.querySelector('[data-packbody]'); var to = whereItLands(node, body); node.classList.add('is-picked'); if (orbit) orbit.pin(); // hold the ring while a pack is out /* THE REST GO SOFT WHEN IT LANDS, NOT WHEN IT LEAVES. While the pack is still in the air the ring it came out of is part of what the reader is watching — blurring it at the press would be the "and then background blur" happening first, which is the whole thing being fixed. */ var settled = function () { flying = false; ring.classList.add('has-pick'); if (section) section.classList.add('has-pick'); if (hint) hint.textContent = 'Swipe the glowing strip — or drag the pack to turn it'; if (swap) swap.hidden = false; }; if (!window.NEUArrive || !to) { settled(); return; } flying = true; window.NEUArrive.fly({ from: body, to: to, done: settled }); } if (swap) swap.addEventListener('click', unpick); stage.querySelectorAll('[data-pack-node]').forEach(function (node) { node.addEventListener('click', function (e) { if (e.target.closest('[data-tear]')) return; // the strip has its own job pickNode(node); }); }); // Clicking away deliberately does NOT drop the pick — it was far too easy to // lose the pack you had just chosen. Escape stays, since that can't happen by // accident, and "I know this one, pull another" puts the whole ring back. document.addEventListener('keydown', function (e) { if (e.key === 'Escape') unpick(); }); /* ---- turning a picked pack by hand, like a real object ---- */ stage.querySelectorAll('[data-packbody]').forEach(function (body) { var node = body.closest('.orbit__node'); var from = null, base = 0; function down(e) { if (!node.classList.contains('is-picked') || opening) return; if (e.target.closest('[data-tear]')) return; e.stopPropagation(); from = (e.touches ? e.touches[0].clientX : e.clientX); base = parseFloat(body.style.getPropertyValue('--spin')) || 0; body.classList.add('is-turning'); } function move(e) { if (from === null) return; var x = (e.touches ? e.touches[0].clientX : e.clientX); body.style.setProperty('--spin', (base + (x - from) * 0.7) + 'deg'); } function up() { from = null; body.classList.remove('is-turning'); } body.addEventListener('mousedown', down); body.addEventListener('touchstart', down, { passive: true }); addEventListener('mousemove', move); body.addEventListener('touchmove', move, { passive: true }); addEventListener('mouseup', up); body.addEventListener('touchend', up); }); /* ---- swiping a tear strip ---- The strip swallows its own pointer events so dragging it tears the pack instead of turning it. */ stage.querySelectorAll('[data-tear]').forEach(function (strip) { var node = strip.closest('.orbit__node'); var startX = null; function down(e) { if (opening) return; if (!node.classList.contains('is-picked')) return; // pick it first e.stopPropagation(); startX = (e.touches ? e.touches[0].clientX : e.clientX); strip.classList.add('is-pulling'); } function move(e) { if (startX === null || opening) return; e.stopPropagation(); var x = (e.touches ? e.touches[0].clientX : e.clientX); var dx = Math.abs(x - startX); strip.style.setProperty('--pull', Math.min(1, dx / SWIPE)); if (dx >= SWIPE) { end(); reveal(node); } } function end(e) { if (e) e.stopPropagation(); startX = null; strip.classList.remove('is-pulling'); strip.style.removeProperty('--pull'); } strip.addEventListener('mousedown', down); strip.addEventListener('touchstart', down, { passive: true }); addEventListener('mousemove', move); strip.addEventListener('touchmove', move, { passive: true }); addEventListener('mouseup', end); strip.addEventListener('touchend', end); // keyboard equivalent — a swipe isn't reachable without a pointer strip.addEventListener('keydown', function (e) { if (e.key === 'Enter' && node.classList.contains('is-picked')) { e.preventDefault(); reveal(node); } }); }); // keep the front pack's strip reachable by keyboard as the ring turns if (ring) { setInterval(function () { stage.querySelectorAll('[data-tear]').forEach(function (s) { s.tabIndex = s.closest('.orbit__node').classList.contains('is-picked') ? 0 : -1; }); }, 400); } /* ---- opening the card: zoom through, then navigate ---- */ link.addEventListener('click', function (e) { // never navigate from a card that hasn't actually been pulled if (cardWrap.hidden) { e.preventDefault(); return; } if (reduced || !zoomer) return; e.preventDefault(); var href = link.getAttribute('href'); var r = link.getBoundingClientRect(); zoomer.style.setProperty('--zx', (r.left + r.width / 2) + 'px'); zoomer.style.setProperty('--zy', (r.top + r.height / 2) + 'px'); zoomer.hidden = false; requestAnimationFrame(function () { zoomer.classList.add('is-on'); }); setTimeout(function () { location.href = href; }, 460); }); })();