import {t,tf,useLanguage,categoryLabel} from './i18n'; import {useEffect,useMemo,useRef,useState} from 'react'; import {ChevronLeft,ChevronRight,Search,X,ArrowUpRight} from 'lucide-react'; import presets from './idol-presets.json'; import editorials from '../../metadata/idol-examples.json'; import {createSearch} from './explorer/search'; export const EXAMPLE_REVISION='2fd68f6aaa69df7c178503a788ad8deb4c7d3117'; export const EXAMPLE_SOURCE='https://huggingface.co/spaces/speridlabs/idol'; export type Preset=typeof presets[number]; export const findPreset=(image:string)=>presets.find(p=>p.image===image)||null; export const exampleUrl=(p:Preset)=>`/${p.image}`; const quickNames=['obj-backpack','fur-chair-tulip-red','fig-axolotl','food-avocado','obj-watering-can','toy-robot-tin']; const quick=quickNames.map(id=>presets.find(p=>p.image===`examples/${id}.webp`)!); const editorialMap=editorials.examples as Record; const group=(p:Preset)=>editorialMap[p.image]?.category||'other'; const exampleLabel=(p:Preset)=>editorialMap[p.image]?.title||p.title; const searchExamples=createSearch(presets.map(p=>{const e=editorialMap[p.image];return {...p,id:p.image,name:exampleLabel(p),generator:'IDOL',description:e?.description,tags:e?.tags,category:e?.category};})); type Existing=Record; export default function Examples({disabled,selected,onSelect,onView}:{disabled:boolean;selected:Preset|null;onSelect:(p:Preset)=>Promise;onView:(id:string)=>void}){ useLanguage(); const [open,setOpen]=useState(false),[existing,setExisting]=useState({}); useEffect(()=>{const abort=new AbortController();void fetch('/api/catalogue',{signal:abort.signal,cache:'no-store'}).then(r=>r.ok?r.json():null).then(data=>{if(data?.assets)setExisting(Object.fromEntries(data.assets.filter((a:{demoExample?:string})=>a.demoExample).map((a:{demoExample:string;id:string;author:string})=>[a.demoExample,{id:a.id,author:a.author}])));}).catch(()=>{});return()=>abort.abort();},[open,selected?.image]); return <>
{t("Start from an IDOL example")}{t("Input images")}
{quick.map(p=>)}
{selected&&

{exampleLabel(selected)}{t("Original IDOL preset loaded. You can adjust it below.")}

} {selected&&existing[selected.image]&&

{t("This example is already in the collection. You can still generate and download a private variation.")}

} {open&&{setOpen(false);await onSelect(p);}} close={()=>setOpen(false)}/>} ; } function ExampleGallery({existing,disabled,selected,onSelect,close}:{existing:Existing;disabled:boolean;selected:Preset|null;onSelect:(p:Preset)=>Promise;close:()=>void}){ useLanguage(); const dialog=useRef(null),[search,setSearch]=useState(''),[category,setCategory]=useState('all'),[page,setPage]=useState(0); useEffect(()=>{const node=dialog.current,previous=document.activeElement as HTMLElement;node?.showModal();return()=>{node?.close();if(previous?.isConnected)previous.focus({preventScroll:true});};},[]); const filtered=useMemo(()=>searchExamples(search).filter(p=>category==='all'||group(p)===category),[search,category]); const perPage=12,pages=Math.max(1,Math.ceil(filtered.length/perPage)); return {e.preventDefault();close();}}>

{t("94 STARTING POINTS, YOUR NEXT CONTRIBUTION")}

{t("Try an original IDOL example.")}

{t("Choose an input image and its original generation settings. Inspect your own result before deciding whether to share it.")}

{filtered.slice(page*perPage,(page+1)*perPage).map(p=>)}
{!filtered.length&&

{t("No examples found. Try another name or category.")}

}
{filtered.length} {t(" examples · ")}{page+1} / {pages}

{t("Inputs and presets from ")}speridlabs / IDOL {t(". An example is a starting point, not permission to publish every depicted subject. Review rights and add source credits before sharing.")}

; }