'use strict'; document.addEventListener('DOMContentLoaded', () => { const STAGGER = 0.1; const HOLD = 0.3; const FIRST_VIEW = 'animate'; const reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches; const queued = new Set(); const showGroup = (targets) => { const sorted = Array.from(targets).sort((a, b) => { const r = a.getBoundingClientRect(); const s = b.getBoundingClientRect(); return (r.top - s.top) || (r.left - s.left); }); sorted.forEach((target, index) => { const delay = index * STAGGER; target.style.transitionDelay = delay + 's'; target.classList.add('is-show'); const curtain = target.querySelector('.curtain-box'); if (curtain) { curtain.style.animationDelay = (delay + 0.15) + 's'; curtain.classList.add('is-show'); } target.addEventListener('transitionend', () => { target.style.transitionDelay = ''; }, { once: true }); }); }; const showInstant = (targets) => { const list = Array.from(targets); list.forEach((target) => { target.style.transition = 'none'; target.style.transitionDelay = ''; target.classList.add('is-show'); const curtain = target.querySelector('.curtain-box'); if (curtain) { curtain.style.animation = 'none'; curtain.style.animationDelay = ''; curtain.classList.add('is-show'); } }); requestAnimationFrame(() => { list.forEach((target) => { target.style.transition = ''; const curtain = target.querySelector('.curtain-box'); if (curtain) curtain.style.animation = ''; }); }); }; const revealGroup = (targets) => { const list = Array.from(targets).filter((target) => !queued.has(target) && !target.classList.contains('is-show')); if (!list.length) return; list.forEach((target) => queued.add(target)); const wait = reduceMotion ? 0 : HOLD * 1000; window.setTimeout(() => { list.forEach((target) => queued.delete(target)); showGroup(list); }, wait); }; const initScrollAnimation = () => { const targets = Array.from(document.querySelectorAll('.anime')); if (!targets.length) return; const RATIO = 0.22; const lineOf = () => { const doc = document.documentElement; const bottom = window.innerHeight + window.pageYOffset; const atEnd = bottom >= doc.scrollHeight - 4; return atEnd ? window.innerHeight : window.innerHeight * (1 - RATIO); }; const observer = new IntersectionObserver((entries, obs) => { const shown = entries.filter((entry) => entry.isIntersecting); if (!shown.length) return; shown.forEach((entry) => obs.unobserve(entry.target)); revealGroup(shown.map((entry) => entry.target)); }, { root: null, rootMargin: `0px 0px -${RATIO * 100}% 0px`, threshold: 0 }); let ticking = false; const sweep = () => { ticking = false; const limit = lineOf(); const pending = []; targets.forEach((target) => { if (target.classList.contains('is-show')) return; if (queued.has(target)) return; if (target.getClientRects().length < 1) return; if (target.getBoundingClientRect().top < limit) pending.push(target); }); if (!pending.length) return; pending.forEach((target) => observer.unobserve(target)); revealGroup(pending); }; const requestSweep = () => { if (ticking) return; ticking = true; requestAnimationFrame(sweep); }; let started = false; const start = () => { if (started) return; started = true; const limit = lineOf(); const above = targets.filter((target) => target.getClientRects().length > 0 && target.getBoundingClientRect().top < limit); if (FIRST_VIEW === 'instant' && above.length) { showInstant(above); above.forEach((target) => observer.unobserve(target)); } targets.forEach((target) => observer.observe(target)); window.addEventListener('scroll', requestSweep, { passive: true }); window.addEventListener('resize', requestSweep); requestSweep(); }; const loader = document.getElementById('loader'); if (reduceMotion || !loader || document.body.classList.contains('is-ready')) { requestAnimationFrame(start); return; } let fired = false; let timer = 0; const mutationObserver = window.MutationObserver ? new MutationObserver(() => { if (document.body.classList.contains('is-ready')) fire(); }) : null; const fire = () => { if (fired) return; fired = true; if (mutationObserver) mutationObserver.disconnect(); clearTimeout(timer); window.setTimeout(start, 60); }; if (mutationObserver) { mutationObserver.observe(document.body, { attributes: true, attributeFilter: ['class'] }); } timer = window.setTimeout(fire, 5000); }; const initTextAnimation = () => { document.querySelectorAll('.text-animation').forEach((element) => { const characters = element.textContent.trim().split(''); const fragment = document.createDocumentFragment(); characters.forEach((char, index) => { const span = document.createElement('span'); span.textContent = char; span.style.setProperty('--delay', index + 1); fragment.appendChild(span); }); element.textContent = ''; element.appendChild(fragment); }); }; const initVideoModal = () => { const triggers = document.querySelectorAll('.js-modal-video'); if (!triggers.length) return; const modal = document.createElement('div'); modal.className = 'custom-video-modal'; modal.innerHTML = `
`; document.body.appendChild(modal); const videoContainer = modal.querySelector('.video-container'); const closeBtn = modal.querySelector('.custom-video-modal-close'); const closeModal = () => { modal.classList.remove('is-open'); videoContainer.innerHTML = ''; document.body.style.overflow = ''; }; closeBtn.addEventListener('click', closeModal); modal.addEventListener('click', (e) => { if (e.target === modal) closeModal(); }); document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && modal.classList.contains('is-open')) closeModal(); }); triggers.forEach((trigger) => { trigger.addEventListener('click', (e) => { e.preventDefault(); const videoId = trigger.getAttribute('data-video-id'); if (!videoId) return; videoContainer.innerHTML = ` `; modal.classList.add('is-open'); document.body.style.overflow = 'hidden'; }); }); }; const initTabs = () => { const tabButtons = document.querySelectorAll('.tab-btn'); if (!tabButtons.length) return; const tabPanels = document.querySelectorAll('.tab-panel'); tabButtons.forEach((button) => { button.addEventListener('click', () => { const targetTab = button.getAttribute('data-tab'); tabButtons.forEach((btn) => btn.classList.remove('is-active')); tabPanels.forEach((panel) => panel.classList.remove('is-active')); button.classList.add('is-active'); const activePanel = document.getElementById(`panel-${targetTab}`); if (!activePanel) return; activePanel.classList.add('is-active'); const panelTargets = activePanel.querySelectorAll('.anime'); panelTargets.forEach((target) => { target.classList.remove('is-show'); target.style.transitionDelay = ''; queued.delete(target); const curtain = target.querySelector('.curtain-box'); if (curtain) { curtain.classList.remove('is-show'); curtain.style.animationDelay = ''; } }); requestAnimationFrame(() => showGroup(panelTargets)); }); }); }; const initHamburger = () => { const btn = document.querySelector('.hamburger-btn'); const nav = document.getElementById('global-nav'); const overlay = document.getElementById('nav-overlay'); const target = document.querySelector('#target-button'); if (!btn || !nav || !overlay) return; const navLinks = document.querySelectorAll('.nav-list a'); const originalParent = target?.parentNode; const originalNext = target?.nextSibling; const toggleMenu = () => { const isOpen = btn.classList.toggle('active'); nav.classList.toggle('active'); overlay.classList.toggle('active'); document.body.classList.toggle('is-locked', isOpen); btn.setAttribute('aria-expanded', isOpen); btn.setAttribute( 'aria-label', isOpen ? 'メニューを閉じる' : 'メニューを開く' ); nav.setAttribute('aria-hidden', !isOpen); if (target) { target.classList.add('is-menu-moving'); if (isOpen) { nav.appendChild(target); target.classList.add('is-in-nav'); } else { if (originalNext && originalNext.parentNode === originalParent) { originalParent.insertBefore(target, originalNext); } else { originalParent.appendChild(target); } target.classList.remove('is-in-nav'); } } }; btn.addEventListener('click', toggleMenu); overlay.addEventListener('click', toggleMenu); navLinks.forEach((link) => { link.addEventListener('click', () => { if (btn.classList.contains('active')) { toggleMenu(); } }); }); }; const initHeaderLogo = () => { const header = document.querySelector('header'); if (!header) return; const logo = header.querySelector(':scope > h1 img') || header.querySelector('h1 img'); if (!logo) return; const srcLight = 'assets/img/logo-3.png'; const srcDark = 'assets/img/logo.png'; const isSubpage = document.body.classList.contains('subpage'); const sections = isSubpage ? document.querySelectorAll('#subpage-black-bg, [data-header-dark]') : document.querySelectorAll('[data-header-dark], #mv, #black-bg'); if (!sections.length) return; const nav = document.getElementById('global-nav'); const cache = new Image(); cache.src = srcDark; let isDark = false; let frame = 0; const setLogo = (dark) => { if (dark === isDark) return; isDark = dark; logo.setAttribute('src', dark ? srcDark : srcLight); header.classList.toggle('is-header-dark', dark); }; const check = (line) => { for (let i = 0; i < sections.length; i += 1) { const rect = sections[i].getBoundingClientRect(); if (rect.height > 0 && rect.top <= line && line < rect.bottom) return true; } return false; }; const update = () => { frame = 0; if (nav && nav.classList.contains('active')) return; const rect = header.getBoundingClientRect(); const line = Math.min(Math.max(rect.top + rect.height / 2, 0), window.innerHeight - 1); setLogo(check(line)); }; const request = () => { if (frame) return; frame = requestAnimationFrame(update); }; if (isSubpage) { logo.setAttribute('src', srcLight); header.classList.remove('is-header-dark'); } window.addEventListener('scroll', request, { passive: true }); window.addEventListener('resize', request); window.addEventListener('orientationchange', request); window.addEventListener('load', update); if (window.ResizeObserver) { const resizeObserver = new ResizeObserver(request); resizeObserver.observe(document.body); sections.forEach((section) => resizeObserver.observe(section)); } if (nav && window.MutationObserver) { const mutationObserver = new MutationObserver(request); mutationObserver.observe(nav, { attributes: true, attributeFilter: ['class'] }); } [100, 400, 1000].forEach((ms) => setTimeout(update, ms)); update(); }; const initAccordion = () => { document.querySelectorAll('.accordion-header').forEach((header) => { header.addEventListener('click', () => { const item = header.parentElement; const content = item.querySelector('.accordion-content'); const icon = item.querySelector('.accordion-icon'); const isOpen = item.classList.contains('active'); if (isOpen) { item.classList.remove('active'); content.style.maxHeight = null; icon.textContent = 'add'; } else { item.classList.add('active'); content.style.maxHeight = content.scrollHeight + 'px'; icon.textContent = 'maximize'; } }); }); }; const initLoader = () => { const loader = document.getElementById('loader'); if (!loader) return; if (sessionStorage.getItem('visited')) { loader.classList.add('is-hidden'); document.body.classList.add('is-ready'); return; } sessionStorage.setItem('visited', '1'); const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches; const imagesDone = Promise.all( Array.from(document.images).map((img) => img.complete ? Promise.resolve() : new Promise((resolve) => { img.addEventListener('load', resolve, { once: true }); img.addEventListener('error', resolve, { once: true }); })) ); const windowLoaded = new Promise((resolve) => { if (document.readyState === 'complete') resolve(); else window.addEventListener('load', resolve, { once: true }); }); const forceEnd = new Promise((resolve) => setTimeout(resolve, 8000)); Promise.race([Promise.all([imagesDone, windowLoaded]), forceEnd]).then(() => { setTimeout(() => { loader.classList.add('is-done'); document.body.classList.add('is-ready'); setTimeout(() => loader.classList.add('is-hidden'), reduced ? 60 : 1400); }, reduced ? 50 : 500); }); }; const initTopSlide = () => { const slider = document.querySelector('.topics-slider'); const track = document.querySelector('.topics-track'); if (!slider || !track) return; const prev = slider.querySelector('.topics-prev'); const next = slider.querySelector('.topics-next'); const bar = slider.querySelector('.topics-pagination__bar') || document.querySelector('.topics-pagination__bar'); const slides = Array.from(track.children); const count = slides.length; if (count < 2) return; track.prepend(slides[count - 1].cloneNode(true)); track.append(slides[0].cloneNode(true)); let current = 1; let moving = false; let timer; const setPosition = (animate = true) => { const slide = track.children[current]; const center = slide.offsetLeft + slide.offsetWidth / 2; track.style.transition = animate ? 'transform 0.6s ease' : 'none'; track.style.transform = `translateX(${slider.clientWidth / 2 - center}px)`; }; const updatePagination = () => { if (!bar) return; const index = (current - 1 + count) % count; bar.style.width = `${100 / count}%`; bar.style.transform = `translateX(${index * 100}%)`; }; const move = (direction) => { if (moving) return; moving = true; current += direction; setPosition(true); updatePagination(); }; const startAuto = () => { clearInterval(timer); timer = setInterval(() => move(1), 4000); }; prev?.addEventListener('click', () => { move(-1); startAuto(); }); next?.addEventListener('click', () => { move(1); startAuto(); }); track.addEventListener('transitionend', (e) => { if (e.target !== track || e.propertyName !== 'transform') return; if (current === count + 1) { current = 1; setPosition(false); } else if (current === 0) { current = count; setPosition(false); } moving = false; updatePagination(); }); let resizeTimer; window.addEventListener('resize', () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(() => setPosition(false), 100); }); setPosition(false); updatePagination(); // スワイプ操作 let startX = 0; let startY = 0; let isSwiping = false; track.addEventListener('touchstart', (e) => { if (e.touches.length !== 1) return; startX = e.touches[0].clientX; startY = e.touches[0].clientY; isSwiping = true; }, { passive: true }); track.addEventListener('touchend', (e) => { if (!isSwiping) return; isSwiping = false; const endX = e.changedTouches[0].clientX; const endY = e.changedTouches[0].clientY; const diffX = endX - startX; const diffY = endY - startY; // 横方向の移動が少ない場合や、縦スクロールが主体の場合は無視 if (Math.abs(diffX) < 50 || Math.abs(diffX) < Math.abs(diffY)) { return; } // 左スワイプで次へ、右スワイプで前へ move(diffX < 0 ? 1 : -1); startAuto(); }, { passive: true }); startAuto(); }; const initMvYoutube = () => { const playBtn = document.querySelector('.mv__play'); const soundBtn = document.querySelector('.mv__sound'); const container = document.getElementById('mv-youtube'); if (!container || !playBtn || !soundBtn) return; const playIcon = playBtn.querySelector('img'); const soundIcon = soundBtn.querySelector('img'); let player = null; let isReady = false; const updatePlayButton = (playing) => { playIcon.src = playing ? 'assets/img/pause.png' : 'assets/img/play.png'; playBtn.setAttribute('aria-label', playing ? '動画を一時停止' : '動画を再生'); }; const updateSoundButton = () => { if (!isReady) return; const muted = player.isMuted(); soundIcon.src = muted ? 'assets/img/mute.png' : 'assets/img/unmute.png'; soundBtn.setAttribute('aria-label', muted ? '音声をオンにする' : '音声をオフにする'); }; window.onYouTubeIframeAPIReady = function () { player = new YT.Player('mv-youtube', { videoId: 'sNWk9LDNJks', playerVars: { autoplay: 1, mute: 1, controls: 0, loop: 1, playlist: 'sNWk9LDNJks', playsinline: 1, rel: 0, fs: 0, cc_load_policy: 0 }, events: { onReady: (event) => { isReady = true; event.target.mute(); event.target.playVideo(); updateSoundButton(); }, onStateChange: (event) => { if (event.data === YT.PlayerState.PLAYING) { updatePlayButton(true); } else if (event.data === YT.PlayerState.PAUSED) { updatePlayButton(false); } else if (event.data === YT.PlayerState.ENDED) { event.target.seekTo(0); event.target.playVideo(); } }, onApiChange: function (event) { const player = event.target; if (player.getOptions().includes('captions')) { player.setOption('captions', 'track', {}); } } } }); }; playBtn.addEventListener('click', () => { if (!isReady) return; if (player.getPlayerState() === YT.PlayerState.PLAYING) { player.pauseVideo(); } else { player.playVideo(); } }); soundBtn.addEventListener('click', () => { if (!isReady) return; if (player.isMuted()) { player.unMute(); } else { player.mute(); } updateSoundButton(); }); updatePlayButton(false); const script = document.createElement('script'); script.src = 'https://www.youtube.com/iframe_api'; script.async = true; document.head.appendChild(script); }; const initLanguage = () => { const wrap = document.querySelector('.mv__languageWrap'); if (!wrap) return; const toggle = wrap.querySelector('.mv__language'); const menu = wrap.querySelector('.mv__languageMenu'); const closeMenu = () => { menu.hidden = true; toggle.setAttribute('aria-expanded', 'false'); }; toggle.addEventListener('click', () => { const opening = menu.hidden; menu.hidden = !opening; toggle.setAttribute('aria-expanded', String(opening)); }); menu.querySelectorAll('[data-lang]').forEach((button) => { button.addEventListener('click', () => { toggle.textContent = button.dataset.lang; closeMenu(); }); }); document.addEventListener('click', (event) => { if (!wrap.contains(event.target)) closeMenu(); }); document.addEventListener('keydown', (event) => { if (event.key === 'Escape') closeMenu(); }); }; const initBgVideo = () => { const video = document.querySelector('.bg-video'); if (!video) return; const tryPlay = () => { if (video.paused) video.play().catch(() => { }); }; tryPlay(); video.addEventListener('loadedmetadata', tryPlay, { once: true }); video.addEventListener('canplay', tryPlay, { once: true }); document.addEventListener('touchend', tryPlay, { once: true, passive: true }); document.addEventListener('click', tryPlay, { once: true, passive: true }); }; const runInits = (inits) => { Object.keys(inits).forEach((key) => { try { inits[key](); } catch (error) { console.warn(`[init:${key}]`, error); } }); }; runInits({ scrollAnimation: () => initScrollAnimation(), textAnimation: () => initTextAnimation(), videoModal: () => initVideoModal(), tabs: () => initTabs(), hamburger: () => initHamburger(), headerLogo: () => initHeaderLogo(), accordion: () => initAccordion(), loader: () => initLoader(), topSlide: () => initTopSlide(), mvYoutube: () => initMvYoutube(), language: () => initLanguage(), bgVideo: () => initBgVideo() }); });