(() => { 'use strict'; document.addEventListener('DOMContentLoaded', () => { const root = document.querySelector('.p-growth'); const nav = root?.querySelector('.p-growth-localnav'); const items = nav?.querySelector('.p-growth-localnav__items'); const links = Array.from(items?.querySelectorAll('a[href^="#"]') || []); const targets = links .map((link) => ({ link, section: document.querySelector(link.hash) })) .filter(({ section }) => section); if (!root || !nav || !items || !targets.length) return; const header = document.querySelector('.l-header'); let activeId = ''; let ticking = false; let headerTrackingFrame = 0; let headerTrackingUntil = 0; const getHeaderOffset = () => { if (!header || window.getComputedStyle(header).position !== 'fixed') return 0; const rect = header.getBoundingClientRect(); return Math.max(0, Math.min(rect.height, rect.bottom)); }; // Reserve the full fixed header for anchors; its hide/show animation must // not change the scroll destination or make the active item fall behind. const getAnchorHeaderHeight = () => { if (!header || window.getComputedStyle(header).position !== 'fixed') return 0; return header.offsetHeight; }; const syncGeometry = () => { const headerOffset = getHeaderOffset(); root.style.setProperty('--growth-sticky-offset', `${Math.round(headerOffset)}px`); root.style.setProperty('--growth-anchor-offset', `${Math.round(getAnchorHeaderHeight() + nav.offsetHeight + 16)}px`); }; const setActive = (id) => { if (!id || id === activeId) return; activeId = id; targets.forEach(({ link, section }) => { const current = section.id === id; link.classList.toggle('is-current', current); if (current) link.setAttribute('aria-current', 'location'); else link.removeAttribute('aria-current'); }); }; const updateActive = () => { syncGeometry(); const activationLine = getAnchorHeaderHeight() + nav.offsetHeight + Math.min(144, window.innerHeight * .18); let current = targets[0].section.id; targets.forEach(({ section }) => { if (section.getBoundingClientRect().top <= activationLine) current = section.id; }); const pageBottom = window.scrollY + window.innerHeight; const documentBottom = document.documentElement.scrollHeight; if (pageBottom >= documentBottom - 2) current = targets.at(-1).section.id; setActive(current); ticking = false; }; const requestUpdate = () => { if (ticking) return; ticking = true; window.requestAnimationFrame(updateActive); }; const trackHeaderMotion = () => { window.cancelAnimationFrame(headerTrackingFrame); headerTrackingUntil = window.performance.now() + 650; const frame = (time) => { syncGeometry(); requestUpdate(); if (time < headerTrackingUntil) headerTrackingFrame = window.requestAnimationFrame(frame); }; headerTrackingFrame = window.requestAnimationFrame(frame); }; links.forEach((link) => { link.addEventListener('click', () => { const section = document.querySelector(link.hash); if (section) setActive(section.id); }); }); window.addEventListener('scroll', requestUpdate, { passive: true }); window.addEventListener('resize', requestUpdate, { passive: true }); window.addEventListener('pageshow', requestUpdate); if ('ResizeObserver' in window) { const resizeObserver = new ResizeObserver(requestUpdate); resizeObserver.observe(nav); if (header) resizeObserver.observe(header); } if (header && 'MutationObserver' in window) { const headerObserver = new MutationObserver(trackHeaderMotion); headerObserver.observe(header, { attributes: true, attributeFilter: ['class'] }); } syncGeometry(); updateActive(); }); })(); /* Live projection of the existing CMS common text variables. */ (function (window, document) { 'use strict'; if (window.WitSubsidyCommon) return; function node(tag, text, className) { var e = document.createElement(tag); e.textContent = text; if (className) e.className = className; return e; } function render(e, value) { var mode=e.dataset.subsidyFormat, prefix=e.dataset.subsidyPrefix; var m=value.match(/^(\d{4}年)\s*(\d{1,2})(月)(?:(\d{1,2})(日))?(.*)$/); e.replaceChildren(); if (mode==='hero' && /^p-(?:mono-hero|growth-hero|labor-hero|column-mv)$/.test(prefix)) { if (m) { e.appendChild(node('p',m[1],prefix+'__fact-year')); var p=node('p','',prefix+'__fact-value'); p.appendChild(document.createTextNode(m[2]));p.appendChild(node('small',m[3])); if(m[4])p.appendChild(document.createTextNode(m[4])); p.appendChild(node('small',(m[5]||'')+m[6]));e.appendChild(p); } else { var fallback=node('p',value,prefix+'__support-date');e.appendChild(fallback); } } else if (mode==='support' && m) { e.appendChild(document.createTextNode(m[1]+' ')); e.appendChild(node('strong',m[2]+m[3]+(m[4]||'')+(m[5]||''))); e.appendChild(document.createTextNode(m[6])); } else e.textContent=value; } async function refresh() { var elements=Array.from(document.querySelectorAll('[data-subsidy-common]')); if(!elements.length)return; // Format the server-rendered common values even if the refresh is unavailable. elements.forEach(function(e){render(e,e.textContent.trim());}); var controller=new AbortController();var timeout=window.setTimeout(function(){controller.abort();},10000); try { var response=await window.fetch('https://svltd2.files.cmssv.awsv.jp/_api_/subsidy-schedule.json',{cache:'no-store',credentials:'omit',signal:controller.signal}); if(!response.ok)throw new Error('Unavailable schedule'); var data=await response.json();if(data.schemaVersion!==1||!data.values)throw new Error('Invalid schedule'); elements.forEach(function(e){var value=data.values[e.dataset.subsidyCommon];if(typeof value==='string')render(e,value);}); document.documentElement.dataset.subsidyCommonState='ready'; } catch (_) {document.documentElement.dataset.subsidyCommonState='unavailable';} finally {window.clearTimeout(timeout);} } window.WitSubsidyCommon={refresh:refresh}; if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',refresh);else refresh(); })(window,document);