|
3 | 3 |
|
4 | 4 | const body = document.body; |
5 | 5 | const base = (body?.getAttribute('data-base') || '.').trim(); |
6 | | - const assetVersion = '20260320a'; |
| 6 | + const assetVersion = '20260320b'; |
7 | 7 | const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches; |
8 | 8 |
|
9 | 9 | const projects = [ |
|
108 | 108 | return window.matchMedia('(max-width:900px) and (orientation:portrait)').matches; |
109 | 109 | } |
110 | 110 |
|
| 111 | + function clearPortraitMenuLayoutVars(){ |
| 112 | + const root = document.documentElement; |
| 113 | + root.style.removeProperty('--mobile-vv-top'); |
| 114 | + root.style.removeProperty('--mobile-vv-height'); |
| 115 | + root.style.removeProperty('--mobile-menu-top'); |
| 116 | + root.style.removeProperty('--mobile-brand-shift-x'); |
| 117 | + root.style.removeProperty('--mobile-brand-shift-y'); |
| 118 | + root.style.removeProperty('--mobile-wordmark-font-size'); |
| 119 | + root.style.removeProperty('--mobile-wordmark-right'); |
| 120 | + root.style.removeProperty('--mobile-wordmark-bottom'); |
| 121 | + } |
| 122 | + |
| 123 | + function syncPortraitMobileMenuLayout(nav){ |
| 124 | + const root = document.documentElement; |
| 125 | + if (!nav || !isPortraitMobile()){ |
| 126 | + clearPortraitMenuLayoutVars(); |
| 127 | + return; |
| 128 | + } |
| 129 | + |
| 130 | + const vv = window.visualViewport; |
| 131 | + const viewportTop = Math.round(vv?.offsetTop ?? 0); |
| 132 | + const viewportHeight = Math.round(vv?.height ?? window.innerHeight); |
| 133 | + const viewportWidth = Math.round(vv?.width ?? window.innerWidth); |
| 134 | + |
| 135 | + root.style.setProperty('--mobile-vv-top', `${viewportTop}px`); |
| 136 | + root.style.setProperty('--mobile-vv-height', `${Math.max(0, viewportHeight)}px`); |
| 137 | + |
| 138 | + const menuTop = Math.round(Math.min(Math.max(viewportHeight * 0.3, 228), 286)); |
| 139 | + root.style.setProperty('--mobile-menu-top', `${menuTop}px`); |
| 140 | + |
| 141 | + const wordmarkFontSize = Math.round(Math.min(Math.max(viewportHeight * 0.112, 94), 122)); |
| 142 | + const wordmarkRight = Math.round(Math.max(-18, Math.min(-8, viewportWidth * -0.018))); |
| 143 | + const wordmarkBottom = Math.round(Math.min(Math.max(viewportHeight * 0.165, 84), 122)); |
| 144 | + |
| 145 | + root.style.setProperty('--mobile-wordmark-font-size', `${wordmarkFontSize}px`); |
| 146 | + root.style.setProperty('--mobile-wordmark-right', `${wordmarkRight}px`); |
| 147 | + root.style.setProperty('--mobile-wordmark-bottom', `${wordmarkBottom}px`); |
| 148 | + |
| 149 | + const shouldAlignBrand = |
| 150 | + nav.classList.contains('nav--open') || |
| 151 | + nav.classList.contains('nav--opening') || |
| 152 | + body.classList.contains('nav-menu-closing'); |
| 153 | + |
| 154 | + if (!shouldAlignBrand) return; |
| 155 | + |
| 156 | + const brand = nav.querySelector('.brand'); |
| 157 | + const firstLink = nav.querySelector('.mobile-menu a'); |
| 158 | + if (!brand || !firstLink) return; |
| 159 | + |
| 160 | + const brandRect = brand.getBoundingClientRect(); |
| 161 | + const firstLinkRect = firstLink.getBoundingClientRect(); |
| 162 | + const gapAbove = Math.round(Math.min(Math.max(viewportHeight * 0.024, 18), 24)); |
| 163 | + const targetTop = firstLinkRect.top - brandRect.height - gapAbove; |
| 164 | + const shiftX = Math.round(firstLinkRect.left - brandRect.left); |
| 165 | + const shiftY = Math.round(targetTop - brandRect.top); |
| 166 | + |
| 167 | + root.style.setProperty('--mobile-brand-shift-x', `${shiftX}px`); |
| 168 | + root.style.setProperty('--mobile-brand-shift-y', `${shiftY}px`); |
| 169 | + } |
| 170 | + |
111 | 171 | function clearTransientMobileMenuState(nav){ |
112 | 172 | if (nav?.classList.contains('nav--open')) return; |
113 | 173 | nav?.classList.remove('nav--opening'); |
114 | 174 | body.classList.remove('nav-menu-open'); |
115 | 175 | body.classList.remove('nav-menu-closing'); |
116 | 176 | body.classList.remove('no-scroll'); |
| 177 | + syncPortraitMobileMenuLayout(nav || document.querySelector('.nav')); |
117 | 178 | } |
118 | 179 |
|
119 | 180 |
|
|
131 | 192 | body.classList.add('nav-menu-open'); |
132 | 193 | body.classList.remove('nav-menu-closing'); |
133 | 194 | body.classList.add('no-scroll'); |
| 195 | + syncPortraitMobileMenuLayout(nav); |
| 196 | + requestAnimationFrame(() => { |
| 197 | + syncPortraitMobileMenuLayout(nav); |
| 198 | + requestAnimationFrame(() => syncPortraitMobileMenuLayout(nav)); |
| 199 | + }); |
134 | 200 | }else{ |
135 | 201 | nav.classList.remove('nav--open'); |
136 | 202 | nav.classList.remove('nav--opening'); |
137 | 203 | body.classList.remove('nav-menu-open'); |
138 | 204 | body.classList.add('nav-menu-closing'); |
139 | 205 | body.classList.remove('no-scroll'); |
| 206 | + syncPortraitMobileMenuLayout(nav); |
140 | 207 | } |
141 | 208 |
|
142 | 209 | toggle.setAttribute('aria-expanded', open ? 'true' : 'false'); |
|
172 | 239 |
|
173 | 240 | if (!nav.classList.contains('nav--open')){ |
174 | 241 | clearTransientMobileMenuState(nav); |
| 242 | + return; |
175 | 243 | } |
| 244 | + |
| 245 | + syncPortraitMobileMenuLayout(nav); |
176 | 246 | } |
177 | 247 |
|
178 | 248 | function initMobileMenuDelays(){ |
|
464 | 534 | window.addEventListener('resize', syncMobileNavState); |
465 | 535 | window.addEventListener('orientationchange', syncMobileNavState); |
466 | 536 | window.addEventListener('pageshow', syncMobileNavState); |
| 537 | + if (window.visualViewport){ |
| 538 | + window.visualViewport.addEventListener('resize', () => syncPortraitMobileMenuLayout(nav)); |
| 539 | + window.visualViewport.addEventListener('scroll', () => syncPortraitMobileMenuLayout(nav)); |
| 540 | + } |
467 | 541 | } |
468 | 542 |
|
469 | 543 | const brand = document.querySelector('.brand'); |
|
486 | 560 | initMenuThumb(); |
487 | 561 | initMobileMenuDelays(); |
488 | 562 | initNavBackdrop(); |
| 563 | + syncPortraitMobileMenuLayout(nav); |
489 | 564 | } |
490 | 565 |
|
491 | 566 | function initSectionSpy() { |
|
0 commit comments