feat(tool-page): add dynamic support for before/after comparison animations and videos in alternating features

This commit is contained in:
2026-11-11 12:53:39 +05:30
parent e8307fd4bc
commit a372be4578
3 changed files with 56 additions and 33 deletions
+3 -19
View File
@@ -88,25 +88,9 @@
"en": "Dual-alias endpoint — /improver/ and /eye_fix/ call the same skin-enhancement pipeline that fixes puffy under-eye bags, redness, and overall skin smoothness. Applies the process_improver routine. secretKey validation: optional — invalid key is rejected, absent key is allowed.", "en": "Dual-alias endpoint — /improver/ and /eye_fix/ call the same skin-enhancement pipeline that fixes puffy under-eye bags, redness, and overall skin smoothness. Applies the process_improver routine. secretKey validation: optional — invalid key is rejected, absent key is allowed.",
"hi": "अत्याधुनिक डीप लर्निंग मॉडल। फोटो प्रोसेस होने के तुरंत बाद सुरक्षित रूप से हटा दी जाती है।" "hi": "अत्याधुनिक डीप लर्निंग मॉडल। फोटो प्रोसेस होने के तुरंत बाद सुरक्षित रूप से हटा दी जाती है।"
}, },
"image": "https://images.unsplash.com/photo-1517841905240-472988babdf9?w=800&auto=format&fit=crop&q=80", "mediaType": "comparison",
"badge": { "before": "https://images.unsplash.com/photo-1534528741775-53994a69daeb?w=800&auto=format&fit=crop&q=80",
"en": "Verified Model", "after": "https://images.unsplash.com/photo-1517841905240-472988babdf9?w=800&auto=format&fit=crop&q=80"
"hi": "सत्यापित मॉडल"
},
"caption": {
"en": "Blemish Remover — Skin Improver & Eye Fix output quality specimen",
"hi": "परिणाम नमूना"
},
"metrics": [
{
"label": "Service Group",
"value": "ML"
},
{
"label": "Latency",
"value": "350ms"
}
]
}, },
{ {
"title": { "title": {
@@ -3,6 +3,7 @@
import React from 'react'; import React from 'react';
import { AlternatingFeature, resolveLocalised } from '@/types'; import { AlternatingFeature, resolveLocalised } from '@/types';
import { KineticText } from '@/components/magicui/kinetic-text'; import { KineticText } from '@/components/magicui/kinetic-text';
import { CardBeforeAfterSlider } from '@/components/ui/CardBeforeAfterSlider';
interface AlternatingFeaturesSectionProps { interface AlternatingFeaturesSectionProps {
features?: AlternatingFeature[]; features?: AlternatingFeature[];
@@ -35,39 +36,72 @@ export function AlternatingFeaturesSection({
</p> </p>
</div> </div>
{/* Alternating Feature Items: Image at Left - Text at Right, then Text at Left - Image at Right (No cards, pure editorial) */} {/* Alternating Feature Items: Supports Image, Interactive Before/After Comparison, or Video */}
<div className="space-y-14 sm:space-y-20"> <div className="space-y-14 sm:space-y-20">
{features.map((feature, idx) => { {features.map((feature, idx) => {
const isEven = idx % 2 === 0; const isEven = idx % 2 === 0;
const title = resolveLocalised(feature.title, locale); const title = resolveLocalised(feature.title, locale);
const desc = resolveLocalised(feature.description, locale); const desc = resolveLocalised(feature.description, locale);
// Dynamically detect media format: comparison animation/slider, video, or image
const isComparison = feature.mediaType === 'comparison' || (Boolean(feature.before) && Boolean(feature.after));
const isVideo = feature.mediaType === 'video' || Boolean(feature.videoUrl) || (feature.image ? /\.(mp4|webm|mov)(\?.*)?$/i.test(feature.image) : false);
return ( return (
<div <div
key={idx} key={idx}
className="grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-14 items-center" className="grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-14 items-center"
> >
{/* Visual / Image Block */} {/* Visual / Media Block */}
<div <div
className={`lg:col-span-6 ${ className={`lg:col-span-6 ${
isEven ? 'order-1 lg:order-1' : 'order-1 lg:order-2' isEven ? 'order-1 lg:order-1' : 'order-1 lg:order-2'
}`} }`}
> >
<div className="group relative rounded-3xl overflow-hidden bg-paper-2 border border-rule shadow-md transition-all duration-300 hover:shadow-lg"> <div className="group relative rounded-3xl overflow-hidden bg-paper-2 border border-rule shadow-md transition-all duration-300 hover:shadow-lg">
<div className="aspect-[16/10] sm:aspect-[4/3] w-full overflow-hidden"> {/* 1. Comparison Interactive Slider / Animation */}
{/* eslint-disable-next-line @next/next/no-img-element */} {isComparison && feature.before && feature.after ? (
<img <div className="aspect-[16/10] sm:aspect-[4/3] w-full overflow-hidden">
src={feature.image} <CardBeforeAfterSlider
alt={title} beforeUrl={feature.before}
loading="lazy" afterUrl={feature.after}
decoding="async" title={title}
className="w-full h-full object-cover transition-transform duration-700 group-hover:scale-[1.02]" aspectRatio="aspect-auto h-full"
/> beforeLabel="Before"
</div> afterLabel="After"
/>
</div>
) : isVideo ? (
/* 2. Autoplay Looped Video Specimen */
<div className="aspect-[16/10] sm:aspect-[4/3] w-full overflow-hidden bg-paper-2">
<video
src={feature.videoUrl || feature.image}
poster={feature.poster}
muted
loop
autoPlay
playsInline
preload="metadata"
className="w-full h-full object-cover"
/>
</div>
) : (
/* 3. High-Resolution Single Specimen Image */
<div className="aspect-[16/10] sm:aspect-[4/3] w-full overflow-hidden">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={feature.image || '/management/pages/home/sections/our-tools/blemish-remover/after.jpg'}
alt={title}
loading="lazy"
decoding="async"
className="w-full h-full object-cover transition-transform duration-700 group-hover:scale-[1.02]"
/>
</div>
)}
</div> </div>
</div> </div>
{/* Text Paragraph Block: Clean Heading + Spacious Paragraph (No cards, no Feature labels, no pills) */} {/* Text Paragraph Block: Clean Heading + Spacious Paragraph */}
<div <div
className={`lg:col-span-6 space-y-4 ${ className={`lg:col-span-6 space-y-4 ${
isEven ? 'order-2 lg:order-2' : 'order-2 lg:order-1' isEven ? 'order-2 lg:order-2' : 'order-2 lg:order-1'
+6 -1
View File
@@ -212,7 +212,12 @@ export interface TextToImageConfig {
export interface AlternatingFeature { export interface AlternatingFeature {
title: Localised; title: Localised;
description: Localised; description: Localised;
image: string; mediaType?: 'image' | 'comparison' | 'video';
image?: string;
before?: string;
after?: string;
videoUrl?: string;
poster?: string;
badge?: Localised; badge?: Localised;
caption?: Localised; caption?: Localised;
metrics?: Array<{ label: string; value: string }>; metrics?: Array<{ label: string; value: string }>;