/* Orbit — round nodes revolving around a central hub on a tilted ring. * The node nearest the viewer renders largest/brightest and on top; the * far side shrinks and dims, so the set reads as a 3D ball orbiting the * hub. Arrows (and drag/keys/wheel) rotate it one step at a time. */ (function () { 'use strict'; class Orbit { constructor(root) { this.root = root; this.nodes = Array.from(root.querySelectorAll('.orbit__node')); this.n = this.nodes.length; this.angle = 0; // current rotation, radians this.target = 0; // where we're easing to this.step = (Math.PI * 2) / this.n; this.reduced = matchMedia('(prefers-reduced-motion: reduce)').matches; this._raf = null; const prev = root.querySelector('.orbit__nav--prev'); const next = root.querySelector('.orbit__nav--next'); if (prev) prev.addEventListener('click', () => this.rotate(-1)); if (next) next.addEventListener('click', () => this.rotate(1)); root.setAttribute('tabindex', '0'); root.addEventListener('keydown', e => { if (e.key === 'ArrowLeft') { e.preventDefault(); this.rotate(-1); } if (e.key === 'ArrowRight') { e.preventDefault(); this.rotate(1); } }); // drag / swipe /* DEADZONE is why a press can still be a press. Every pixel of pointer movement here is multiplied — 1 px of hand wobble swings a card by about 2.4 px — so without a threshold, merely pressing a card slides it out from under the pointer and the press is lost. Nothing turns until the pointer has genuinely travelled. */ const DEADZONE = 10; let down = false, startX = 0, startAngle = 0, dragging = false; /* THE RING FOLLOWS THE FINGER. This had a minus in it, so dragging left swung the front card right — the ring moved against the hand, which is the one thing a dragged object must never do. It also disagreed with the arrows and the arrow keys, where Left has always meant left. A card's x is sin(angle + i·step), so at the front a bigger angle moves it right: drag right, angle up, card follows. */ const px2rad = dx => (dx / 320) * this.step * 1.6; const onDown = e => { down = true; dragging = false; startX = (e.touches ? e.touches[0].clientX : e.clientX); startAngle = this.target; /* a finger on a stopped ring has to start it, or the drag moves `target` and nothing ever draws it */ this._wake(); }; const onMove = e => { if (!down) return; const x = (e.touches ? e.touches[0].clientX : e.clientX); const d = x - startX; if (!dragging) { if (Math.abs(d) < DEADZONE) return; dragging = true; // re-base, so the ring doesn't jump the deadzone's worth on the // first frame of a real drag startX += Math.sign(d) * DEADZONE; } this.target = startAngle + px2rad(x - startX); this._tick(); }; const onUp = () => { if (!down) return; down = false; // no snapping — the drift picks up smoothly from wherever they let go }; root.addEventListener('mousedown', onDown); root.addEventListener('touchstart', onDown, { passive: true }); addEventListener('mousemove', onMove); root.addEventListener('touchmove', onMove, { passive: true }); addEventListener('mouseup', onUp); root.addEventListener('touchend', onUp); /* Auto-rotate. Dr. KC's rule: the section must present itself while nobody is touching it, and hold still the moment someone is. So it advances on its own, and any hover / focus / drag pauses it. */ /* Hover-to-hold is bound to the CARDS, not the whole section — moving the mouse across empty space in the section shouldn't freeze the ring, only pointing at a card should. */ this.hold = 0; const pause = () => { this.hold++; }; const resume = () => { this.hold = Math.max(0, this.hold - 1); this._wake(); }; /* Rings marked data-nohover keep turning under the cursor — the packs hold still only once one has actually been picked. */ if (!root.hasAttribute('data-nohover')) { this.nodes.forEach(node => { node.addEventListener('mouseenter', pause); node.addEventListener('mouseleave', resume); node.addEventListener('focusin', pause); node.addEventListener('focusout', resume); node.addEventListener('touchstart', pause, { passive: true }); node.addEventListener('touchend', resume); }); [prev, next].forEach(b => { if (!b) return; b.addEventListener('mouseenter', pause); b.addEventListener('mouseleave', resume); }); } /* held open by something other than a hover — a picked pack, a chosen logo. Balanced pairs, same counter. */ this.pin = pause; this.unpin = resume; // don't spin while the section is off screen — it would just burn battery this.onScreen = true; if ('IntersectionObserver' in window) { this.onScreen = false; new IntersectionObserver(es => { es.forEach(e => { this.onScreen = e.isIntersecting; /* coming back on screen is the commonest reason a stopped ring needs to start again */ if (e.isIntersecting) this._wake(); }); }, { threshold: 0.35 }).observe(root); } /* Continuous drift, in radians per second. One full revolution takes about 45s — slow enough to read a card as it passes, never so fast that it feels like a slideshow. */ /* ── AND A PHONE GETS A STILL RING ───────────────────────────────── * Taufik, 29 August 2026, relaying Dr KC: "for mobile we can do like the * NEU, putting the static cards, and swipe it, then when click will pop * up ... current one is quite laggy and too dependent of phone spec". * * A drifting ring is on screen and therefore animating for as long as * somebody is looking at it. Stopping the loop when it settles buys * nothing while it never settles, so on a phone the drift itself goes: * the ring stands still, the swipe already works, and the loop runs only * while a finger or an arrow is actually moving it. * * The drift stays on a desktop, where it costs nothing anybody can feel * and is a large part of how the page reads. */ /* a phone, or the NEUONBOX — nine rings asking for animation frames is the heaviest thing on this page, and the standing panel is the least able to pay for it. See public/assets/js/lowfi.js. */ const still = window.NEULowFi ? window.NEULowFi.quiet() : (window.matchMedia && window.matchMedia('(max-width: 820px)').matches); this.spin = still ? 0 : (parseFloat(root.dataset.spin) || (Math.PI * 2) / 45); this._isDown = () => down; this._debug = () => ({ hold: this.hold, onScreen: this.onScreen, reduced: this.reduced, spin: this.spin }); root._orbit = this; addEventListener('resize', () => { this.layout(true); this._wake(); }); this.layout(true); this._raf = null; this._dirty = false; if (!this.reduced) this._start(); } /* arrows still work — they add a step on top of the drift */ rotate(dir) { this.target += dir * this.step; this._wake(); } /* Turn node `i` to the front by the shortest way round, so clicking a logo or a pack brings it to the centre rather than spinning the long way about. */ bringToFront(i) { const wanted = -i * this.step; // angle that puts i at cos = 1 const turns = Math.round((this.target - wanted) / (Math.PI * 2)); this.target = wanted + turns * Math.PI * 2; } /* index currently nearest the viewer */ frontIndex() { let best = -2, at = 0; this.nodes.forEach((el, i) => { const d = Math.cos(this.angle + i * this.step); if (d > best) { best = d; at = i; } }); return at; } /* geometry read from CSS custom props so breakpoints control size */ _metrics() { const cs = getComputedStyle(this.root); return { rx: parseFloat(cs.getPropertyValue('--orbit-rx')) || 300, ry: parseFloat(cs.getPropertyValue('--orbit-ry')) || 84, minScale: parseFloat(cs.getPropertyValue('--orbit-min-scale')) || 0.42, }; } layout(snap) { if (snap) this.angle = this.target; const { rx, ry, minScale } = this._metrics(); /* Exactly one card is "front" at any moment — the nearest to the viewer. A threshold test would leave gaps mid-drift and make the pulse flicker. */ let front = 0, best = -2; this.nodes.forEach((el, i) => { const d = Math.cos(this.angle + i * this.step); if (d > best) { best = d; front = i; } }); this.nodes.forEach((el, i) => { const a = this.angle + i * this.step; const depth = Math.cos(a); // 1 = front, -1 = back const d01 = (depth + 1) / 2; // 0..1 const x = Math.sin(a) * rx; const y = depth * ry; const scale = minScale + (1 - minScale) * d01; el.style.transform = `translate(-50%, -50%) translate3d(${x.toFixed(1)}px, ${y.toFixed(1)}px, 0) scale(${scale.toFixed(3)})`; el.style.opacity = (0.30 + 0.70 * d01).toFixed(3); el.style.zIndex = String(Math.round(d01 * 100)); el.style.filter = d01 < 0.55 ? `blur(${((0.55 - d01) * 5).toFixed(1)}px)` : 'none'; // only the front-most node is clickable/tabbable const isFront = i === front; el.classList.toggle('is-front', isFront); const link = el.querySelector('a'); if (link) link.tabIndex = isFront ? 0 : -1; }); } /* One persistent loop drives everything. The ring drifts continuously and stops dead the moment a pointer is over it — the whole point of the section is that it presents itself, then holds still when someone wants to talk about one card. Arrow/drag nudges ease in on top of the drift. */ /* One frame's worth of motion — separate from the rAF loop so it can be driven directly when testing. NOT named `step`: `this.step` is already the angular distance between two nodes, and an own property would shadow the method. */ /* ── AND IT STOPS WHEN THERE IS NOTHING TO DO ──────────────────────── * * Dr KC, 29 August 2026, on the front page on his phone: it was "quite * laggy and too dependent of phone spec and connection". * * With the main thread throttled to a mid-range phone's speed, this file * alone was asking for 54 animation frames a SECOND across the whole page * — ten times everything else put together — and there are nine of these * rings on the front page. Each was laying out every one of its nodes on * every frame, for ever, whether or not it was on the screen. * * The answer was already written and thrown away: `frame()` worked out * whether it was paused and RETURNED that, and `_start()` ignored the * return value and scheduled the next frame unconditionally. On a desktop * nobody sees it. On a phone it is the whole complaint. * * Now the loop ends when the ring is off screen, held, or has come to * rest, and anything that should move it wakes it again. */ frame(dt) { const paused = this.hold > 0 || this._isDown() || !this.onScreen; if (!paused) this.target += this.spin * dt; const diff = this.target - this.angle; const moving = Math.abs(diff) > 0.00002; if (moving) this.angle += diff * 0.14; /* only paint when something actually changed — a paused ring that has settled is nine nodes' worth of transform writes for no picture */ if (moving || this._dirty) { this.layout(); this._dirty = false; } /* Keep going while it is DRIFTING, or while it is still easing to a target somebody asked for. `!paused` alone was not enough once a phone set `spin` to zero: an on-screen ring with nothing to move is not paused, so it would have looped for ever painting the same picture. */ return (!paused && this.spin !== 0) || moving; } _start() { cancelAnimationFrame(this._raf); this._last = performance.now(); const run = now => { const dt = Math.min(0.05, (now - this._last) / 1000); // clamp after a tab switch this._last = now; if (this.frame(dt)) { this._raf = requestAnimationFrame(run); } else { /* nothing to animate. Whatever should move it next calls _wake(). */ this._raf = null; } }; this._raf = requestAnimationFrame(run); } /* Start the loop again if it has stopped. Every event that changes what the ring should look like calls this; calling it while already running does nothing, so it is safe to call from anywhere. */ _wake() { if (this.reduced || this._raf !== null) return; this._dirty = true; this._start(); } _tick() { if (this.reduced) this.layout(true); } } document.querySelectorAll('.orbit').forEach(el => new Orbit(el)); /* The rings on the page are all here at load. The fan of films in Section 1 is not — it is built when somebody presses a chapter — so the class is handed out rather than kept private. Same component, same spin, same stop-on-hover; nothing about the behaviour is reimplemented. */ window.NEUOrbit = Orbit; })();