/*! Fiesta 1.0.0 | MPL-2.0 | https://fiesta.rastrillo.org */ (function () { "use strict"; var root = document.documentElement; if (!window.matchMedia || !window.matchMedia("all").addEventListener) return; var reduce = matchMedia("(prefers-reduced-motion: reduce)"); var forced = matchMedia("(forced-colors: active)"); var FOLLOW = false; var WRITE_MS = 200; var BTN = "[rst-btn],.rst-btn"; var CARD = "[rst-box],.rst-box,[rst-card],.rst-card,[rst-stats],.rst-stats,[rst-list],.rst-list"; var LIGHT_T = 125, CARD_T = 320, LIT_T = 400; var on = false, tx = 0, ty = -1, lx = 0, ly = -1, wx = 0, wy = -1; var raf = 0, last = 0, pending = null, pointer = false, hold = false, force = false, wrote = 0; var cards = new WeakMap(), live = new Set(), timers = new Set(), clock = 0; function sun() { var d = new Date(), h = d.getHours() + d.getMinutes() / 60; var t = Math.max(-1, Math.min(1, (h - 12) / 6)); return [t * 0.8, -1 + Math.abs(t) * 0.35]; } function target() { if (hold || (pointer && FOLLOW)) return; var s = sun(); tx = s[0]; ty = s[1]; } function go() { if (!on || document.hidden) return; if (!raf) raf = requestAnimationFrame(step); } function ease(v, to, dt, T) { return v + (to - v) * (1 - Math.exp(-dt / T)); } function light(el, x, y) { var o = cards.get(el); if (!o) { o = { x: x, y: y, l: 0 }; cards.set(el, o); } o.tx = x; o.ty = y; o.tl = 1; live.add(el); } function dim(el) { var o = cards.get(el); if (o) { o.tl = 0; live.add(el); } } function step(now) { raf = 0; var dt = last ? Math.min(100, now - last) : 16; last = now; var moving = false; if (pending) { var e = pending; pending = null; var b = e.target.closest && e.target.closest(BTN); var c = e.target.closest && e.target.closest(CARD); var br = b && b.getBoundingClientRect(); var cr = c && c.getBoundingClientRect(); if (b) { b.style.setProperty("--rst-mx", (e.clientX - br.left).toFixed(0) + "px"); b.style.setProperty("--rst-my", (e.clientY - br.top).toFixed(0) + "px"); } live.forEach(function (k) { if (k !== c) dim(k); }); if (c) light(c, e.clientX - cr.left, e.clientY - cr.top); } if (!hold) { lx = ease(lx, tx, dt, LIGHT_T); ly = ease(ly, ty, dt, LIGHT_T); } if (force || ((Math.abs(lx - wx) > 0.01 || Math.abs(ly - wy) > 0.01) && now - wrote >= WRITE_MS)) { force = false; wx = lx; wy = ly; wrote = now; root.style.setProperty("--rst-light-x", lx.toFixed(3)); root.style.setProperty("--rst-light-y", ly.toFixed(3)); } if (Math.abs(tx - lx) > 0.002 || Math.abs(ty - ly) > 0.002) moving = true; live.forEach(function (el) { if (!el.isConnected) { live.delete(el); return; } var o = cards.get(el); o.x = ease(o.x, o.tx, dt, CARD_T); o.y = ease(o.y, o.ty, dt, CARD_T); o.l = ease(o.l, o.tl, dt, LIT_T); var done = Math.abs(o.tx - o.x) < 0.5 && Math.abs(o.ty - o.y) < 0.5 && Math.abs(o.tl - o.l) < 0.004; if (done) { o.x = o.tx; o.y = o.ty; o.l = o.tl; } if (!done || !o.still) { el.style.setProperty("--rst-card-x", o.x.toFixed(1) + "px"); el.style.setProperty("--rst-card-y", o.y.toFixed(1) + "px"); el.style.setProperty("--rst-card-lit", o.l.toFixed(3)); } o.still = done; if (!done) moving = true; else if (o.tl === 0) live.delete(el); }); if (moving) go(); else last = 0; } function onMove(e) { if (e.pointerType !== "mouse") return; if (FOLLOW && !hold) { pointer = true; tx = Math.max(-1, Math.min(1, (e.clientX / innerWidth - 0.5) * 2)); ty = Math.max(-1, Math.min(1, (e.clientY / innerHeight - 0.5) * 2)) * 0.6 - 0.4; } pending = e; go(); } function onDown(e) { var b = e.target.closest && e.target.closest(BTN); var c = e.pointerType !== "mouse" && e.target.closest && e.target.closest(CARD); var br = b && b.getBoundingClientRect(); var cr = c && c.getBoundingClientRect(); if (b) { b.style.setProperty("--rst-px", (e.clientX - br.left).toFixed(0) + "px"); b.style.setProperty("--rst-py", (e.clientY - br.top).toFixed(0) + "px"); } if (e.pointerType === "mouse") return; leavePointer(); if (c) { light(c, e.clientX - cr.left, e.clientY - cr.top); var id = setTimeout(function () { timers.delete(id); dim(c); go(); }, 1400); timers.add(id); go(); } } function leavePointer() { pointer = false; target(); go(); } function onLeave() { pending = null; live.forEach(dim); leavePointer(); } function onVisibility() { if (document.hidden) { if (raf) cancelAnimationFrame(raf); raf = 0; last = 0; } else { go(); } } function onHook(e) { var d = e.detail || {}; hold = !!d.hold; if (typeof d.x === "number") { tx = lx = d.x; } if (typeof d.y === "number") { ty = ly = d.y; } force = true; go(); } function start() { if (on) return; on = true; addEventListener("pointermove", onMove, { passive: true }); addEventListener("pointerdown", onDown, { passive: true }); addEventListener("keydown", leavePointer, { passive: true }); document.addEventListener("pointerleave", onLeave); document.addEventListener("visibilitychange", onVisibility); document.addEventListener("rst:light", onHook); clock = setInterval(function () { target(); go(); }, 5 * 60 * 1000); target(); lx = tx; ly = ty; force = true; go(); } function stop() { if (!on) return; on = false; removeEventListener("pointermove", onMove); removeEventListener("pointerdown", onDown); removeEventListener("keydown", leavePointer); document.removeEventListener("pointerleave", onLeave); document.removeEventListener("visibilitychange", onVisibility); document.removeEventListener("rst:light", onHook); clearInterval(clock); timers.forEach(clearTimeout); timers.clear(); if (raf) cancelAnimationFrame(raf); raf = 0; last = 0; pending = null; pointer = false; hold = false; force = false; wrote = 0; lx = wx = tx = 0; ly = wy = ty = -1; live.clear(); cards = new WeakMap(); root.style.removeProperty("--rst-light-x"); root.style.removeProperty("--rst-light-y"); var written = document.querySelectorAll('[style*="--rst-"]'); for (var i = 0; i < written.length; i++) { ["--rst-mx", "--rst-my", "--rst-px", "--rst-py", "--rst-card-x", "--rst-card-y", "--rst-card-lit"].forEach(function (p) { written[i].style.removeProperty(p); }); } } function settle() { if (reduce.matches || forced.matches) stop(); else start(); } reduce.addEventListener("change", settle); forced.addEventListener("change", settle); settle(); })();