/* OPERATION FACTORY — motion layer (no dependencies). Loaded with `defer` after app.js. Everything here is progressive: without JS, or with "reduce motion" on, the page is complete and static. */ (() => { "use strict"; const $$ = (s, r = document) => [...r.querySelectorAll(s)]; const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches; const fine = matchMedia("(hover: hover) and (pointer: fine)").matches; const vh = () => innerHeight; /* ---------- 1. intro curtain (home page, once per browser session) ---------- */ if (!reduce && document.querySelector(".hero")) { let seen = false; try { seen = sessionStorage.getItem("of-intro") === "1"; sessionStorage.setItem("of-intro", "1"); } catch (_) {} if (!seen) { const intro = document.createElement("div"); intro.className = "intro"; intro.setAttribute("aria-hidden", "true"); intro.innerHTML = '
Operation Factory
'; document.body.appendChild(intro); document.documentElement.style.setProperty("--start", "900ms"); setTimeout(() => intro.classList.add("out"), 1300); setTimeout(() => intro.remove(), 2300); } } /* ---------- 2. header hides on scroll down, returns on scroll up ---------- */ const header = document.querySelector(".site-header"); let lastY = scrollY, ticking = false; const onScroll = () => { const y = scrollY; if (header && !document.body.classList.contains("menu-open")) header.classList.toggle("is-hidden", y > 300 && y > lastY + 4); if (y < lastY - 4 && header) header.classList.remove("is-hidden"); lastY = y; if (!reduce) scrollEffects(); ticking = false; }; addEventListener("scroll", () => { if (!ticking) { ticking = true; requestAnimationFrame(onScroll); } }, { passive: true }); if (reduce) { $$("[data-count]").forEach(el => el.textContent = format(el, +el.dataset.count)); return; } /* ---------- 3. ember particles (canvas) ---------- */ $$("canvas[data-embers]").forEach(cv => { const ctx = cv.getContext("2d"); if (!ctx) return; const max = +cv.dataset.embers || 50; let w = 0, h = 0, dpr = Math.min(devicePixelRatio || 1, 2), parts = [], running = false, raf; const resize = () => { const r = cv.getBoundingClientRect(); w = r.width; h = r.height; cv.width = w * dpr; cv.height = h * dpr; ctx.setTransform(dpr, 0, 0, dpr, 0, 0); }; const spawn = (initial) => ({ x: Math.random() * w, y: initial ? Math.random() * h : h + 10, r: Math.random() * 1.8 + .4, vy: -(Math.random() * .6 + .25), vx: (Math.random() - .5) * .3, life: 0, ttl: 260 + Math.random() * 380, sway: Math.random() * Math.PI * 2, hue: 18 + Math.random() * 26 }); const count = () => Math.round(max * Math.min(1, (w * h) / (1400 * 800)) + max * .3); const tick = () => { ctx.clearRect(0, 0, w, h); ctx.globalCompositeOperation = "lighter"; while (parts.length < count()) parts.push(spawn(parts.length < count() * .8 && !running)); for (const p of parts) { p.life++; p.sway += .02; p.x += p.vx + Math.sin(p.sway) * .35; p.y += p.vy; const t = p.life / p.ttl, a = Math.sin(Math.PI * Math.min(t, 1)) * (0.55 + Math.random() * .45); const g = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, p.r * 4); g.addColorStop(0, `hsla(${p.hue}, 100%, 70%, ${a})`); g.addColorStop(1, `hsla(${p.hue}, 100%, 50%, 0)`); ctx.fillStyle = g; ctx.beginPath(); ctx.arc(p.x, p.y, p.r * 4, 0, Math.PI * 2); ctx.fill(); if (t >= 1 || p.y < -10) Object.assign(p, spawn(false)); } raf = requestAnimationFrame(tick); }; resize(); addEventListener("resize", resize); new IntersectionObserver(([e]) => { if (e.isIntersecting && !running) { running = true; tick(); } else if (!e.isIntersecting && running) { running = false; cancelAnimationFrame(raf); } }).observe(cv); document.addEventListener("visibilitychange", () => { if (document.hidden) { running = false; cancelAnimationFrame(raf); } }); }); /* ---------- 4. split headings into masked lines (split on
) ---------- */ $$(".split").forEach(el => { const parts = el.innerHTML.split(//i); el.innerHTML = parts.map((p, i) => `${p.trim()}`).join(""); }); /* ---------- 5. auto-tag common blocks for scroll reveal, with stagger ---------- */ const AUTO = [".sec-head > div > .eyebrow", ".sec-head .lead", ".svc li", ".collab article", ".timeline li", ".office", ".contact-card", ".profile tr", ".pay tbody tr", ".biz-section .intro h2", ".biz-section .intro p", ".page-head p", ".dish", ".values article", ".ledger > div"]; $$(AUTO.join(",")).forEach(el => el.classList.add("rv")); $$(".biz-section .intro figure, .collab figure").forEach(el => el.classList.add("rv", "rv-img")); const stagger = root => { const groups = new Map(); $$(".rv, .dish", root).forEach(el => { const p = el.parentElement; if (!groups.has(p)) groups.set(p, []); groups.get(p).push(el); }); groups.forEach(list => list.forEach((el, i) => el.style.setProperty("--i", i % 8))); }; stagger(document); /* ---------- 6. reveal on scroll — only things that start below the first screen get hidden ---------- */ const io = new IntersectionObserver(es => es.forEach(e => { if (!e.isIntersecting) return; const el = e.target; el.classList.remove("pre"); el.classList.add("on"); el.querySelectorAll("[data-count]").forEach(countUp); if (el.matches("[data-count]")) countUp(el); io.unobserve(el); }), { rootMargin: "0px 0px -10% 0px", threshold: .05 }); const arm = (root = document) => { $$(".rv:not(.armed), .split:not(.armed), .dish:not(.armed), .phone.play:not(.armed), .sales.play:not(.armed), .ledger:not(.armed), .recruit .facts:not(.armed)", root).forEach(el => { el.classList.add("armed"); const top = el.getBoundingClientRect().top; if (top > vh() * .92) el.classList.add("pre"); io.observe(el); }); }; arm(); // store cards are rendered by app.js after filtering — reveal those too new MutationObserver(ms => { let added = false; ms.forEach(m => m.addedNodes.forEach(n => { if (n.nodeType === 1 && n.classList.contains("store")) { n.classList.add("rv"); bindTilt(n); added = true; } })); if (added) { stagger(document); arm(); } }).observe(document.body, { childList: true, subtree: true }); $$(".store").forEach(n => n.classList.add("rv")); arm(); /* ---------- 7. count-up numbers ---------- */ function format(el, v) { const dec = +el.dataset.dec || 0; if (el.hasAttribute("data-plain")) return String(Math.round(v)); return v.toLocaleString((document.documentElement.lang || "ja") + "-u-nu-latn", { minimumFractionDigits: dec, maximumFractionDigits: dec }); } function countUp(el) { if (el.dataset.done) return; el.dataset.done = "1"; const to = +el.dataset.count, from = el.hasAttribute("data-plain") ? Math.round(to * .97) : 0, dur = 1800, t0 = performance.now(); const step = now => { const t = Math.min(1, (now - t0) / dur), e = 1 - Math.pow(1 - t, 4); el.textContent = format(el, from + (to - from) * e); if (t < 1) requestAnimationFrame(step); }; requestAnimationFrame(step); } // hero stats are on the first screen: count once the intro has lifted setTimeout(() => $$(".hero [data-count]").forEach(countUp), parseInt(getComputedStyle(document.documentElement).getPropertyValue("--start")) + 900 || 900); /* ---------- 8. scroll-linked effects: parallax, hero fade, timeline ---------- */ const para = $$("[data-parallax]"); const heroCopy = document.querySelector("[data-scroll-fade]"); const tl = document.querySelector(".timeline"); function scrollEffects() { for (const el of para) { const r = el.parentElement.getBoundingClientRect(); if (r.bottom < 0 || r.top > vh()) continue; const k = +el.dataset.parallax, c = (r.top + r.height / 2 - vh() / 2); el.style.transform = `translate3d(0, ${(-c * k).toFixed(1)}px, 0)`; } if (heroCopy) { const y = scrollY, k = Math.min(1, y / (vh() * .8)); heroCopy.style.transform = `translate3d(0, ${y * .25}px, 0)`; heroCopy.style.opacity = String(1 - k * .9); } if (tl) { const r = tl.getBoundingClientRect(), p = Math.max(0, Math.min(1, (vh() * .8 - r.top) / r.height)); tl.style.setProperty("--tl", p.toFixed(3)); } } scrollEffects(); /* ---------- 9. pointer effects (desktop only) ---------- */ if (fine) { // hero image drifts against the cursor const mp = document.querySelector("[data-mouse-parallax]"); if (mp) mp.closest(".hero, .r-hero").addEventListener("pointermove", e => { const x = e.clientX / innerWidth - .5, y = e.clientY / innerHeight - .5; mp.style.transform = `translate3d(${x * -22}px, ${y * -14}px, 0) scale(1.03)`; }); // magnetic buttons $$("[data-magnetic]").forEach(b => { b.addEventListener("pointermove", e => { const r = b.getBoundingClientRect(); b.style.transform = `translate(${(e.clientX - r.left - r.width / 2) * .18}px, ${(e.clientY - r.top - r.height / 2) * .3}px)`; }); b.addEventListener("pointerleave", () => { b.style.transform = ""; }); }); // spotlight that follows the cursor on business tiles $$(".biz").forEach(c => c.addEventListener("pointermove", e => { const r = c.getBoundingClientRect(); c.style.setProperty("--mx", `${e.clientX - r.left}px`); c.style.setProperty("--my", `${e.clientY - r.top}px`); })); $$(".store, .tilt").forEach(bindTilt); } function bindTilt(el) { if (!fine || el.dataset.tilt) return; el.dataset.tilt = "1"; el.addEventListener("pointermove", e => { const r = el.getBoundingClientRect(), x = (e.clientX - r.left) / r.width - .5, y = (e.clientY - r.top) / r.height - .5; el.style.transform = `perspective(900px) rotateX(${(-y * 6).toFixed(2)}deg) rotateY(${(x * 8).toFixed(2)}deg) translateY(-4px)`; }); el.addEventListener("pointerleave", () => { el.style.transform = ""; }); } /* ---------- 10. drag-to-scroll rails ---------- */ $$("[data-drag]").forEach(rail => { let down = false, sx = 0, sl = 0, moved = false; rail.addEventListener("pointerdown", e => { if (e.pointerType !== "mouse") return; down = true; moved = false; sx = e.clientX; sl = rail.scrollLeft; }); addEventListener("pointermove", e => { if (!down) return; const dx = e.clientX - sx; if (Math.abs(dx) > 4) { moved = true; rail.classList.add("dragging"); } rail.scrollLeft = sl - dx; }); addEventListener("pointerup", () => { down = false; rail.classList.remove("dragging"); }); rail.addEventListener("click", e => { if (moved) { e.preventDefault(); e.stopPropagation(); } }, true); }); })();