/* OPERATION FACTORY — motion layer 2 ("encore"). No dependencies; loaded with `defer` after motion.js.
Progressive: with JS off or "reduce motion" on, nothing here runs and the page stays complete. */
(() => {
"use strict";
if (matchMedia("(prefers-reduced-motion: reduce)").matches) return;
const $$ = (s, r = document) => [...r.querySelectorAll(s)];
const fine = matchMedia("(hover: hover) and (pointer: fine)").matches;
const root = document.documentElement;
/* ---------- 1. scroll progress hairline + back-to-top ring ---------- */
const bar = document.createElement("div"); bar.className = "of-progress"; bar.setAttribute("aria-hidden", "true");
const top = document.createElement("button"); top.className = "of-top"; top.type = "button"; top.setAttribute("aria-label", (window.OF_T || (s => s))("ページの先頭へ"));
top.innerHTML = '↑';
top.addEventListener("click", () => scrollTo({ top: 0, behavior: "smooth" }));
document.body.append(bar, top);
/* ---------- 2. velocity skew on the marquee ---------- */
const marquee = document.querySelector(".marquee");
let lastY = scrollY, skew = 0, raf = 0;
const frame = () => {
const y = scrollY, max = root.scrollHeight - innerHeight, p = max > 0 ? Math.min(1, y / max) : 0;
bar.style.setProperty("--p", p.toFixed(4)); top.style.setProperty("--p", p.toFixed(4));
top.classList.toggle("show", y > innerHeight * .9);
const v = y - lastY; lastY = y;
skew += (Math.max(-8, Math.min(8, v * .25)) - skew) * .18;
if (marquee) marquee.style.setProperty("--skew", `${skew.toFixed(2)}deg`);
raf = Math.abs(skew) > .02 ? requestAnimationFrame(frame) : 0;
};
addEventListener("scroll", () => { if (!raf) raf = requestAnimationFrame(frame); }, { passive: true });
frame();
/* ---------- 3. per-character reveal for sub-page heads + restaurant names ---------- */
// Split into what a reader sees as one character (grapheme clusters keep Devanagari/Thai marks
// with their letter). Scripts whose letters join or reshape (Arabic, Indic, Thai, Burmese) are
// animated word by word instead, so the glyphs are never torn apart.
const lang = (root.lang || "ja").toLowerCase();
const byWord = /^(ar|hi|ne|th|my)/.test(lang);
const seg = typeof Intl !== "undefined" && Intl.Segmenter ? new Intl.Segmenter(lang, { granularity: byWord ? "word" : "grapheme" }) : null;
const pieces = t => seg ? [...seg.segment(t)].map(s => s.segment) : byWord ? t.split(/(\s+)/) : [...t];
const RTL_CH = /[-ࣿ]/;
const splitChars = el => {
let c = 0;
// a Latin wordmark inside a right-to-left page must stay left-to-right once split into boxes
if (root.dir === "rtl" && !RTL_CH.test(el.textContent)) el.setAttribute("dir", "ltr");
const walk = node => {
[...node.childNodes].forEach(n => {
if (n.nodeType === 3) {
const frag = document.createDocumentFragment();
for (const ch of pieces(n.textContent)) {
if (ch === "\n" || ch === "") continue;
const s = document.createElement("span");
s.className = ch.trim() ? "ch" : "ch sp"; s.textContent = ch.trim() ? ch : " "; s.style.setProperty("--c", c++);
frag.appendChild(s);
}
n.replaceWith(frag);
} else if (n.nodeType === 1 && !n.matches("br, svg, img")) walk(n);
});
};
el.setAttribute("aria-label", el.textContent.trim().replace(/\s+/g, " "));
walk(el);
$$(".ch", el).forEach(s => s.setAttribute("aria-hidden", "true"));
el.classList.add("of-chars");
return c;
};
const heads = $$(".page-head .wordmark, .page-head h1, .r-hero h1");
let delay = 120;
heads.forEach(el => {
el.style.setProperty("--d", `${delay}ms`);
delay += splitChars(el) * 38 * .5;
});
requestAnimationFrame(() => requestAnimationFrame(() => heads.forEach(el => el.classList.add("go"))));
/* ---------- 4. eyebrow labels decode from random glyphs when they scroll in ---------- */
const GLYPHS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789✦·/";
const scramble = el => {
const final = el.textContent, len = final.length, t0 = performance.now(), dur = 700 + len * 22;
el.style.minWidth = `${el.offsetWidth}px`;
const step = now => {
const k = Math.min(1, (now - t0) / dur), fixed = Math.floor(k * len);
el.textContent = final.slice(0, fixed) + [...final.slice(fixed)].map(ch => ch.trim() && /[A-Za-z0-9]/.test(ch) ? GLYPHS[(Math.random() * GLYPHS.length) | 0] : ch).join("");
if (k < 1) requestAnimationFrame(step); else { el.textContent = final; el.style.minWidth = ""; }
};
requestAnimationFrame(step);
};
const eyebrows = $$(".eyebrow").filter(el => el.children.length === 0 && /[A-Za-z]/.test(el.textContent) && el.textContent.length < 40);
const eio = new IntersectionObserver(es => es.forEach(e => { if (e.isIntersecting) { eio.unobserve(e.target); scramble(e.target); } }), { rootMargin: "0px 0px -12% 0px" });
eyebrows.forEach(el => eio.observe(el));
/* ---------- 5. photo reveal: gold bar wipes across, photo follows ---------- */
const SKIP = ".hero, .r-hero, .site-header, .site-footer, .rv-img, .store, .dish, .phone, .marquee, .intro, .recruit, .biz";
const frames = new Set();
$$("main img, main video, body > section img").forEach(m => {
const f = m.parentElement;
if (!f || f.closest(SKIP) || frames.has(f) || f.children.length > 3) return;
const r = m.getBoundingClientRect();
if (r.width < 160 || r.height < 120) return; // icons, logos, thumbnails
frames.add(f);
});
const iio = new IntersectionObserver(es => es.forEach(e => {
if (!e.isIntersecting) return;
e.target.classList.remove("pre"); e.target.classList.add("on"); iio.unobserve(e.target);
}), { rootMargin: "0px 0px -8% 0px", threshold: .08 });
frames.forEach(f => {
if (f.getBoundingClientRect().top < innerHeight * .9) return; // already on screen: leave it be
f.classList.add("of-img", "pre"); iio.observe(f);
});
/* ---------- 6. click ripple on buttons ---------- */
document.addEventListener("pointerdown", e => {
const b = e.target.closest(".btn"); if (!b) return;
const r = b.getBoundingClientRect(), size = Math.max(r.width, r.height) * 2.2;
const s = document.createElement("span"); s.className = "of-ripple";
Object.assign(s.style, { width: `${size}px`, height: `${size}px`, left: `${e.clientX - r.left - size / 2}px`, top: `${e.clientY - r.top - size / 2}px` });
b.appendChild(s); setTimeout(() => s.remove(), 800);
});
/* ---------- 7. page transitions where View Transitions are unavailable ---------- */
if (!("onpagereveal" in window)) {
const wipe = document.createElement("div"); wipe.className = "of-wipe"; document.body.appendChild(wipe);
document.addEventListener("click", e => {
const a = e.target.closest("a[href]");
if (!a || e.defaultPrevented || e.button || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || a.target === "_blank" || a.hasAttribute("download")) return;
const u = new URL(a.href, location.href);
if (u.origin !== location.origin || (u.pathname === location.pathname && u.search === location.search) || a.matches("[data-concierge], [data-book], [role=button]")) return;
e.preventDefault(); wipe.classList.add("go");
setTimeout(() => { location.href = u.href; }, 480);
});
addEventListener("pageshow", ev => { if (ev.persisted) wipe.classList.remove("go"); });
}
/* ---------- 8. custom cursor (mouse only) ---------- */
if (fine) {
const ring = document.createElement("div"); ring.className = "of-cursor hide"; ring.innerHTML = "VIEW";
const dot = document.createElement("div"); dot.className = "of-dot hide";
document.body.append(ring, dot); root.classList.add("has-cursor");
let x = -100, y = -100, rx = x, ry = y, moving = false;
addEventListener("pointermove", e => {
if (e.pointerType !== "mouse") return;
x = e.clientX; y = e.clientY; dot.style.transform = `translate3d(${x}px, ${y}px, 0)`;
ring.classList.remove("hide"); dot.classList.remove("hide");
const t = e.target;
const view = t.closest && t.closest(".store, .dish, .biz, .collab figure, .rail a, .of-img");
const link = !view && t.closest && t.closest("a, button, [role=button], label, select, summary");
ring.classList.toggle("view", !!view); ring.classList.toggle("link", !!link);
if (!moving) { moving = true; requestAnimationFrame(follow); }
});
const follow = () => {
rx += (x - rx) * .2; ry += (y - ry) * .2;
ring.style.transform = `translate3d(${rx.toFixed(1)}px, ${ry.toFixed(1)}px, 0)`;
if (Math.abs(x - rx) + Math.abs(y - ry) > .3) requestAnimationFrame(follow); else moving = false;
};
document.addEventListener("pointerleave", () => { ring.classList.add("hide"); dot.classList.add("hide"); });
// over text fields the native caret is clearer
document.addEventListener("focusin", e => { if (e.target.matches("input, textarea, select")) ring.classList.add("hide"); });
}
})();