11<script setup lang="ts">
22import { useElementSize } from ' @vueuse/core'
3- import { AnimatePresence , motion , MotionConfig } from ' motion-v'
3+ import { motion , MotionConfig } from ' motion-v'
44// @ts-expect-error yaml is not typed
55import hero from ' ./hero.yml'
66
@@ -10,8 +10,7 @@ const { height } = useElementSize(contentRef)
1010
1111const tabs = hero .tabs as { name: string , code: string }[]
1212
13- const currentCode = computed (() => tabs [currentTab .value ]?.code .trim () ?? ' ' )
14- const lineCount = computed (() => currentCode .value .split (' \n ' ).length )
13+ const lineCounts = computed (() => tabs .map (tab => tab .code .trim ().split (' \n ' ).length ))
1514
1615function getLang(filename : string ) {
1716 if (filename .endsWith (' .ts' ))
@@ -168,32 +167,31 @@ function getCodeBlock(tab: { name: string, code: string }) {
168167
169168 <!-- Code content area -->
170169 <div class =" flex flex-col items-start px-1 text-sm mt-6" >
171- <div class =" w-full overflow-x-auto" >
172- <AnimatePresence mode =" wait" >
173- <motion .div
174- :key =" currentTab"
175- :initial =" { opacity: 0, y: 4 }"
176- :animate =" { opacity: 1, y: 0 }"
177- :exit =" { opacity: 0, y: -4 }"
178- :transition =" { duration: 0.25, ease: 'easeOut' }"
179- class =" relative flex items-start px-1 text-sm min-w-max"
170+ <div class =" w-full overflow-hidden" >
171+ <!-- All tabs rendered for SSR, animated with CSS -->
172+ <div class =" relative" >
173+ <div
174+ v-for =" (tab, index) in tabs"
175+ :key =" tab.name"
176+ class =" flex items-start px-1 text-sm min-w-max transition-all duration-250 ease-out"
177+ :class =" index === currentTab ? 'opacity-100 relative' : 'opacity-0 absolute inset-0 pointer-events-none'"
180178 >
181179 <!-- Line numbers gutter -->
182180 <div
183181 aria-hidden =" true"
184182 class =" text-slate-600 select-none pl-2 pr-4 font-mono text-xs sm:text-sm leading-6"
185183 >
186- <div v-for =" i in lineCount " :key =" i" >
184+ <div v-for =" i in lineCounts[index] " :key =" i" >
187185 {{ String(i).padStart(2, '0') }}
188186 </div >
189187 </div >
190188
191- <!-- Code via MDC -->
189+ <!-- Code via MDC - all rendered during SSR - ->
192190 <div class =" hero-code" >
193- <MDC :value =" getCodeBlock(tabs[currentTab]! )" tag =" div" />
191+ <MDC :value =" getCodeBlock(tab )" tag =" div" />
194192 </div >
195- </motion . div >
196- </AnimatePresence >
193+ </div >
194+ </div >
197195 </div >
198196
199197 <!-- Demo CTA (bottom-right) -->
0 commit comments