CLOVIS / index.html
sunyoung00's picture
Rename index (51).html to index.html
9ea2d9b verified
Raw History Blame Contribute Delete
65.4 kB
<!DOCTYPE html>
<html lang="ko" class="dark">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CLOVIS AI ๋ฃฉ๋ถ ์ƒ์„ฑ๊ธฐ</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = { darkMode: 'class', theme: { extend: { colors: { brand: { blue: '#3B82F6', hover: '#2563EB' } } } } }
</script>
<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin />
<link rel="stylesheet" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css" />
<style>
* { font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
body { -webkit-font-smoothing: antialiased; background: #1a1a1a; color: #f9fafb; margin: 0; overflow: hidden; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #1a1a1a; }
::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4b5563; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes shimmer { 0% { background-position: -600px 0; } 100% { background-position: 600px 0; } }
@keyframes pulseRing { 0% { transform: scale(0.85); opacity: .9; } 100% { transform: scale(1.6); opacity: 0; } }
.animate-fadeIn { animation: fadeIn .25s ease-out; }
.shimmer { background: linear-gradient(90deg, #232323 0%, #2c2c2c 40%, #232323 80%); background-size: 600px 100%; animation: shimmer 1.6s linear infinite; }
.pulse-ring::before { content: ''; position: absolute; inset: -6px; border-radius: 9999px; border: 2px solid #3B82F6; animation: pulseRing 1.4s ease-out infinite; }
.ai-label-overlay { position: absolute; top: 12pt; right: 12pt; font-weight: 300; font-size: 10pt; color: #3c3c3c; pointer-events: none; z-index: 2; letter-spacing: -0.02em; }
.drop-active { border-color: #3B82F6 !important; background: rgba(59,130,246,.08) !important; }
textarea { resize: vertical; }
</style>
<script type="importmap">
{ "imports": {
"react": "https://esm.sh/react@19.1.0",
"react/": "https://esm.sh/react@19.1.0/",
"react-dom/": "https://esm.sh/react-dom@19.1.0/",
"lucide-react": "https://esm.sh/lucide-react@0.462.0?external=react"
} }
</script>
</head>
<body>
<div id="root"></div>
<script type="module">
import React, { useState, useEffect, useRef, useCallback } from 'react';
import ReactDOM from 'react-dom/client';
import { Download, X, Upload, Sparkles, RefreshCw, AlertTriangle, Clock, Check, ImagePlus, User, Maximize2, ChevronDown } from 'lucide-react';
const h = React.createElement;
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// Constants โ€” ์›Œํฌํ”Œ๋กœ์šฐ(SPAO.json) CustomCombo ์˜ต์…˜๊ณผ 1:1
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
const SHOT_OPTIONS = ['์ „์‹ ์ปท', '์ƒ๋ฐ˜์‹ ์ปท', 'ํ•˜๋ฐ˜์‹ ์ปท']; // ํ”„๋ ˆ์ž„์€ ํ•ญ์ƒ ์ƒท ๊ทœ์น™์ด ์ •ํ•จ (๋ ˆํผ๋Ÿฐ์Šค๋Š” ํฌ์ฆˆ ์ฐธ๊ณ ์šฉ)
const ANGLE_OPTIONS = ['์ •๋ฉด', '๋ฐ˜์ธก๋ฉด', '์ธก๋ฉด', '๋กœ์šฐ์•ต๊ธ€', 'ํ•˜์ด์•ต๊ธ€', 'ํ›„๋ฉด', '๋ ˆํผ๋Ÿฐ์Šค ๋”ฐ๋ฆ„'];
const GAZE_OPTIONS = ['์นด๋ฉ”๋ผ ์‘์‹œ', '์ž์—ฐ์Šค๋Ÿฌ์šด ์‹œ์„ ', '๋ ˆํผ๋Ÿฐ์Šค ๋”ฐ๋ฆ„'];
const AGE_OPTIONS = ['์„ฑ์ธ', 'ํ‚ค์ฆˆ'];
const DETAIL_GROUPS = [
{ key: 'outer', label: '์•„์šฐํ„ฐ', length: 'outer_length', fit: 'outer_fit' },
{ key: 'top', label: '์ƒ์˜', length: 'top_length', fit: 'top_fit' },
{ key: 'bottom', label: 'ํ•˜์˜', length: 'bottom_length', fit: 'bottom_fit' },
];
const DETAIL_OPTIONS = {
outer_length: { label: '์•„์šฐํ„ฐ ๊ธธ์ด', options: ['ํ—ˆ๋ฆฌ', '๊ณจ๋ฐ˜', 'ํ—ˆ๋ฒ…์ง€'], def: '๊ณจ๋ฐ˜' },
outer_fit: { label: '์•„์šฐํ„ฐ ํ•', options: ['์Šฌ๋ฆผ', 'ํ‘œ์ค€', '์˜ค๋ฒ„'], def: 'ํ‘œ์ค€' },
top_length: { label: '์ƒ์˜ ๊ธธ์ด', options: ['ํ—ˆ๋ฆฌ', '๊ณจ๋ฐ˜', 'ํ—ˆ๋ฒ…์ง€'], def: '๊ณจ๋ฐ˜' },
top_fit: { label: '์ƒ์˜ ํ•', options: ['์Šฌ๋ฆผ', 'ํ‘œ์ค€', '์˜ค๋ฒ„'], def: '์˜ค๋ฒ„' },
bottom_length: { label: 'ํ•˜์˜ ๊ธธ์ด', options: ['ํ—ˆ๋ฒ…์ง€', '๋ฌด๋ฆŽ', '์ข…์•„๋ฆฌ', '๋ฐœ๋ชฉ', '์‹ ๋ฐœ'], def: '์‹ ๋ฐœ' },
bottom_fit: { label: 'ํ•˜์˜ ํ•', options: ['์Šฌ๋ฆผ', 'ํ‘œ์ค€', '์˜ค๋ฒ„'], def: '์˜ค๋ฒ„' },
};
const ADULT_FACE_PRESETS = [
{ id: 'preset_17', label: '์—ฌ์„ฑ 1', url: '/face_preset_17.png' },
{ id: 'preset_18', label: '์—ฌ์„ฑ 2', url: '/face_preset_18.png' },
{ id: 'preset_19', label: '์—ฌ์„ฑ 3', url: '/face_preset_19.png' },
];
// CLOVIS ๋Š” ํ‚ค์ฆˆ ๋ผ์ธ์ด ์—†์–ด ํ‚ค์ฆˆ ํ”„๋ฆฌ์…‹ยท์—ฐ๋ น ํ† ๊ธ€์„ ๋…ธ์ถœํ•˜์ง€ ์•Š์Œ (์›Œํฌํ”Œ๋กœ์šฐ age ์ฝค๋ณด์—๋Š” '์„ฑ์ธ' ๊ณ ์ • ์ „๋‹ฌ)
const IMAGE_SLOTS = [
{ key: 'outer', label: '์•„์šฐํ„ฐ', required: false },
{ key: 'top', label: '์ƒ์˜', required: false },
{ key: 'bottom', label: 'ํ•˜์˜', required: false, hint: '์›ํ”ผ์Šค๋„ ์—ฌ๊ธฐ' },
{ key: 'shoes', label: '์‹ ๋ฐœ', required: false },
{ key: 'inner', label: '์ด๋„ˆ์›จ์–ด', required: false },
{ key: 'belt', label: '๋ฒจํŠธ', required: false },
{ key: 'background', label: '๋ฐฐ๊ฒฝ', required: false, hint: '๋น„์šฐ๋ฉด ๊ธฐ๋ณธ ์ŠคํŠœ๋””์˜ค' },
{ key: 'pose', label: '๋ ˆํผ๋Ÿฐ์Šค ํฌ์ฆˆ', required: false, hint: 'ํฌ์ฆˆ ์ฐธ๊ณ ์šฉ ยท ๊ตฌ๋„๋Š” ์ƒท ์„ ํƒ ๊ธฐ์ค€' },
];
// ๋””ํ…Œ์ผ ์ฐธ์กฐ: ํด๋กœ์ฆˆ์—…์„ ์ƒ์„ฑ ๋ชจ๋ธ์— ์ง์ ‘ ์ฐธ์กฐ๋กœ ์ „๋‹ฌ (์ „์ฒด ์ตœ๋Œ€ 4์žฅ)
// ์˜ท๋งˆ๋‹ค ์Šฌ๋กฏ 2๊ฐœ(a/b), ์Šฌ๋กฏ๋ณ„๋กœ ์ข…๋ฅ˜๋ฅผ ๊ณ ๋ฆ„ โ€” ์ข…๋ฅ˜๋Š” comfy_client.DETAIL_KIND_EN ํ‚ค์™€ 1:1
const DETAIL_MAX = 4;
const DETAIL_SLOTS = ['a', 'b'];
// ์˜ท ์ข…๋ฅ˜๋ณ„ ๋””ํ…Œ์ผ ํ•ญ๋ชฉ โ€” key ๋Š” comfy_client.DETAIL_KIND_EN ๊ณผ 1:1. short: ์นฉ ํ‘œ์‹œ, label: ํˆดํŒ
const K = {
texture: { key: 'texture', short: '์กฐ์ง๊ฐ', label: '์›๋‹จ ์กฐ์ง๊ฐ (์˜ท ์ „์ฒด์— ๋ฐ˜์˜)' },
logo: { key: 'logo', short: '๋กœ๊ณ ', label: '๋กœ๊ณ ยทํ”„๋ฆฐํŠธ (๋ฉ”์ธ ์‚ฌ์ง„๊ณผ ๊ฐ™์€ ์œ„์น˜)' },
neckline: { key: 'neckline', short: '๋„ฅ๋ผ์ธ', label: '๋„ฅ๋ผ์ธยท์นด๋ผ' },
collar: { key: 'collar', short: '์นด๋ผยทํ›„๋“œ', label: '์นด๋ผยทํ›„๋“œยท๋ผํŽ ' },
sleeve: { key: 'sleeve', short: '์†Œ๋งค', label: '์†Œ๋งคยท์ปคํ”„์Šค' },
hem: { key: 'hem', short: '๋ฐ‘๋‹จ', label: '๋ฐ‘๋‹จยทํ—ด ๋งˆ๊ฐ' },
waist: { key: 'waist', short: 'ํ—ˆ๋ฆฌ', label: 'ํ—ˆ๋ฆฌ (์›จ์ด์ŠคํŠธ๋ฐด๋“œยท๋ฒจํŠธ๋ฃจํ”„ยท๋“œ๋กœ์ŠคํŠธ๋ง)' },
pocket: { key: 'pocket', short: 'ํฌ์ผ“', label: 'ํฌ์ผ“ (ํ˜•ํƒœยท์Šคํ‹ฐ์น˜ยทํ”Œ๋žฉ)' },
closure: { key: 'closure', short: '์ง€ํผยท๋ฒ„ํŠผ', label: '์ง€ํผยท๋ฒ„ํŠผยท์Šค๋ƒ…' },
trim: { key: 'trim', short: '๋ถ€์ž์žฌ', label: '๋ถ€์ž์žฌ (๋ผ๋ฒจยทํƒญยท์™€ํŽœ ๋“ฑ)' },
material: { key: 'material', short: '์†Œ์žฌ', label: '์†Œ์žฌยท์งˆ๊ฐ (๊ฐ€์ฃฝยท์Šค์›จ์ด๋“œยท๋ฉ”์‹œ ๋“ฑ, ์ „์ฒด์— ๋ฐ˜์˜)' },
sole: { key: 'sole', short: '๋ฐ‘์ฐฝ', label: '๋ฐ‘์ฐฝยท์•„์›ƒ์†”' },
lacing: { key: 'lacing', short: '๋ˆ', label: '๋ˆยท์•„์ผ๋ ›ยท์„คํฌ' },
heel: { key: 'heel', short: '๋’ค์ถ•', label: '๋’ค์ถ•ยทํžํƒญยท๋ฐœ๋ชฉ' },
buckle: { key: 'buckle', short: '๋ฒ„ํด', label: '๋ฒ„ํด' },
edge: { key: 'edge', short: '์Šคํ‹ฐ์น˜', label: '์Šคํ‹ฐ์น˜ยท์—ฃ์ง€ยท๋ฒจํŠธํ™€' },
};
const DETAIL_KINDS_BY_GARMENT = {
outer: [K.texture, K.logo, K.collar, K.sleeve, K.hem, K.pocket, K.closure, K.trim],
top: [K.texture, K.logo, K.neckline, K.sleeve, K.hem, K.pocket, K.trim],
bottom: [K.texture, K.logo, K.waist, K.hem, K.pocket, K.closure, K.trim],
shoes: [K.material, K.logo, K.sole, K.lacing, K.heel, K.trim],
inner: [K.texture, K.logo, K.neckline, K.sleeve, K.hem],
belt: [K.material, K.buckle, K.logo, K.edge],
};
// ์Šฌ๋กฏ ๊ธฐ๋ณธ๊ฐ’: ์™ผ์ชฝ = ์†Œ์žฌ/์กฐ์ง๊ฐ, ์˜ค๋ฅธ์ชฝ = ๋กœ๊ณ  (๋ฒจํŠธ๋Š” ๋ฒ„ํด)
const defaultKind = (g, slot) => {
const list = DETAIL_KINDS_BY_GARMENT[g] || [];
if (slot === 'a') return list[0]?.key;
return g === 'belt' ? 'buckle' : (list.find(k => k.key === 'logo') || list[1] || list[0])?.key;
};
const DETAIL_GARMENTS = [
{ key: 'outer', label: '์•„์šฐํ„ฐ' }, { key: 'top', label: '์ƒ์˜' }, { key: 'bottom', label: 'ํ•˜์˜' },
{ key: 'shoes', label: '์‹ ๋ฐœ' }, { key: 'inner', label: '์ด๋„ˆ์›จ์–ด' }, { key: 'belt', label: '๋ฒจํŠธ' },
];
// AI ํ‘œ๊ธฐ โ€” ์ €์žฅ ์‹œ ์บ”๋ฒ„์Šค์— ์‚ฝ์ž… (๊ธฐ์กด ์•ฑ๊ณผ ๋™์ผ ๊ทœ๊ฒฉ)
const AI_LABEL_TEXT = 'AI ์ƒ์„ฑ ์ด๋ฏธ์ง€';
const AI_LABEL_FONT_PT = 28;
const AI_LABEL_MARGIN_PT = 12 * (28 / 10);
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// Helpers
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
const fileToDataUrl = (file, maxSide = 1536) => new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onerror = reject;
reader.onload = () => {
const img = new Image();
img.onerror = reject;
img.onload = () => {
const scale = Math.min(1, maxSide / Math.max(img.width, img.height));
const w = Math.round(img.width * scale), hgt = Math.round(img.height * scale);
const canvas = document.createElement('canvas');
canvas.width = w; canvas.height = hgt;
const ctx = canvas.getContext('2d');
const keepPng = /png|webp/i.test(file.type);
if (!keepPng) { ctx.fillStyle = '#fff'; ctx.fillRect(0, 0, w, hgt); }
ctx.drawImage(img, 0, 0, w, hgt);
resolve(keepPng ? canvas.toDataURL('image/png') : canvas.toDataURL('image/jpeg', 0.92));
};
img.src = reader.result;
};
reader.readAsDataURL(file);
});
const drawAiDisclosureOnCanvas = (ctx, width, height) => {
ctx.save();
ctx.textAlign = 'right'; ctx.textBaseline = 'top'; ctx.fillStyle = '#3c3c3c';
ctx.font = `300 ${AI_LABEL_FONT_PT}pt 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif`;
const ptToPx = 96 / 72;
const m = Math.max(AI_LABEL_MARGIN_PT * ptToPx, Math.min(width, height) * 0.028, 18);
ctx.fillText(AI_LABEL_TEXT, width - m, m);
ctx.restore();
};
async function downloadWithLabel(imageUrl, filename, withLabel = true) {
const img = new Image();
await new Promise((res, rej) => { img.onload = res; img.onerror = rej; img.src = imageUrl; });
const canvas = document.createElement('canvas');
canvas.width = img.naturalWidth; canvas.height = img.naturalHeight;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
if (withLabel) drawAiDisclosureOnCanvas(ctx, canvas.width, canvas.height);
const a = document.createElement('a');
a.href = canvas.toDataURL('image/png'); a.download = filename; a.click();
}
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// ์ฑ„๋„ ์‚ฌ์ด์ฆˆ ๋‚ด๋ณด๋‚ด๊ธฐ โ€” ์ƒ์„ฑ์€ 3:4 ์›๋ณธ ํ•œ ๋ฒˆ, ์ฑ„๋„ ๊ทœ๊ฒฉ์€ ์ €์žฅ ์‹œ ๋ณ€ํ™˜
// ์—ฌ๋ฐฑ์€ AI ์žฌ์ƒ์„ฑ์ด ์•„๋‹ˆ๋ผ ์›๋ณธ ๊ฐ€์žฅ์ž๋ฆฌ ํ”ฝ์…€์„ ์ค„(ํ–‰) ๋‹จ์œ„๋กœ ์—ฐ์žฅํ•ด ์ฑ„์›€ (์›๋ณธ ํ”ฝ์…€ ๋ฌด์†์‹ค)
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
const EXPORT_PRESETS = [
{ key: 'original', label: '์›๋ณธ', desc: '1536ร—2048', w: null, h: null, suffix: '' },
{ key: 'mall', label: '์ด๋žœ๋“œ๋ชฐยท๋„ค์ด๋ฒ„ยท์‚ฌ๋ฐฉ๋„ท', desc: '1400ร—1400', w: 1400, h: 1400, suffix: '_1400x1400' },
{ key: 'zigzag', label: '์ง€๊ทธ์žฌ๊ทธ', desc: '1080ร—1296', w: 1080, h: 1296, suffix: '_1080x1296' },
];
// ๋Œ€์ƒ ์บ”๋ฒ„์Šค์— (์คŒยทํŒฌ ๋ฐ˜์˜ํ•ด) ์›๋ณธ์„ ๊ทธ๋ฆฌ๊ณ , ๋‚จ๋Š” ์ขŒ์šฐ ์—ฌ๋ฐฑ์€ ๊ฐ€์žฅ์ž๋ฆฌ 1px ์—ด์„ ๋Š˜๋ ค ์ฑ„์šด๋‹ค.
function renderChannelCanvas(img, W, H, zoom, offX, offY, withLabel) {
const sw = img.naturalWidth, sh = img.naturalHeight;
const s = Math.min(W / sw, H / sh) * zoom;
const dw = sw * s, dh = sh * s;
// ํŒฌ ํด๋žจํ”„: ์ปค๋ฒ„ ์•ˆ ๋˜๋Š” ์ถ•์€ ์ค‘์•™ ๊ณ ์ •, ์ปค๋ฒ„๋˜๋Š” ์ถ•์€ ๋นˆํ‹ˆ์ด ์•ˆ ์ƒ๊ธฐ๋Š” ๋ฒ”์œ„๋กœ ์ œํ•œ
let dx = dw >= W ? Math.min(0, Math.max(W - dw, (W - dw) / 2 + offX)) : (W - dw) / 2;
let dy = dh >= H ? Math.min(0, Math.max(H - dh, (H - dh) / 2 + offY)) : (H - dh) / 2;
const canvas = document.createElement('canvas');
canvas.width = W; canvas.height = H;
const ctx = canvas.getContext('2d');
ctx.imageSmoothingQuality = 'high';
ctx.fillStyle = '#ffffff'; ctx.fillRect(0, 0, W, H);
// ๋ณด์ด๋Š” ์›๋ณธ ์„ธ๋กœ ๊ตฌ๊ฐ„ (์—ฌ๋ฐฑ ์ค„์˜ ์ƒ‰์„ ๊ฐ™์€ ํ–‰์—์„œ ์ž‡๊ธฐ ์œ„ํ•ด)
const sy0 = Math.max(0, -dy / s), syh = Math.min(sh - sy0, H / s);
const padL = Math.ceil(Math.max(0, dx)), padR = Math.ceil(Math.max(0, W - (dx + dw)));
if (padL > 0) ctx.drawImage(img, 0, sy0, 1, syh, 0, 0, padL, H);
if (padR > 0) ctx.drawImage(img, sw - 1, sy0, 1, syh, W - padR, 0, padR, H);
ctx.drawImage(img, dx, dy, dw, dh);
if (withLabel) drawAiDisclosureOnCanvas(ctx, W, H);
return canvas;
}
function ExportModal({ current, aiLabel, onClose }) {
const [preset, setPreset] = useState('mall');
const [zoom, setZoom] = useState(1);
const [off, setOff] = useState({ x: 0, y: 0 });
const imgRef = useRef(null);
const [ready, setReady] = useState(false);
const canvasRef = useRef(null);
const dragRef = useRef(null);
const p = EXPORT_PRESETS.find(x => x.key === preset);
useEffect(() => { // ์›๋ณธ ๋กœ๋“œ (1ํšŒ)
const img = new Image();
img.onload = () => { imgRef.current = img; setReady(true); };
img.src = current.imageUrl;
}, [current.imageUrl]);
useEffect(() => { setZoom(1); setOff({ x: 0, y: 0 }); }, [preset]);
useEffect(() => { // ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๋ Œ๋”
const img = imgRef.current, cv = canvasRef.current;
if (!ready || !img || !cv || !p.w) return;
const out = renderChannelCanvas(img, p.w, p.h, zoom, off.x, off.y, aiLabel);
cv.width = out.width; cv.height = out.height;
cv.getContext('2d').drawImage(out, 0, 0);
}, [ready, preset, zoom, off, aiLabel]);
const startDrag = (e) => {
if (!p.w) return;
e.preventDefault();
dragRef.current = { x: e.clientX, y: e.clientY, ox: off.x, oy: off.y };
const scale = p.h / (canvasRef.current?.getBoundingClientRect().height || p.h);
const move = (ev) => {
const d = dragRef.current; if (!d) return;
setOff({ x: d.ox + (ev.clientX - d.x) * scale, y: d.oy + (ev.clientY - d.y) * scale });
};
const up = () => { dragRef.current = null; window.removeEventListener('pointermove', move); window.removeEventListener('pointerup', up); };
window.addEventListener('pointermove', move); window.addEventListener('pointerup', up);
};
const save = () => {
const base = `clovis_${current.meta.shot}_${current.meta.angle}_${current.id}`;
if (!p.w) { downloadWithLabel(current.imageUrl, `${base}.png`, aiLabel); return; }
const out = renderChannelCanvas(imgRef.current, p.w, p.h, zoom, off.x, off.y, aiLabel);
const a = document.createElement('a');
a.href = out.toDataURL('image/png'); a.download = `${base}${p.suffix}.png`; a.click();
};
return h('div', { className: 'fixed inset-0 z-50 bg-black/80 flex items-center justify-center animate-fadeIn', onClick: onClose },
h('div', { className: 'bg-[#222] rounded-2xl border border-[#333] w-[min(720px,94vw)] max-h-[92vh] overflow-y-auto p-5 flex flex-col gap-4', onClick: e => e.stopPropagation() },
h('div', { className: 'flex items-center justify-between' },
h('h3', { className: 'text-[15px] font-semibold' }, '๋‹ค์šด๋กœ๋“œ โ€” ์ฑ„๋„ ์‚ฌ์ด์ฆˆ'),
h('button', { type: 'button', onClick: onClose, className: 'text-gray-500 hover:text-white' }, h(X, { size: 18 }))),
// ์ฑ„๋„ ์„ ํƒ
h('div', { className: 'grid grid-cols-3 gap-2' }, EXPORT_PRESETS.map(x =>
h('button', { key: x.key, type: 'button', onClick: () => setPreset(x.key),
className: `rounded-xl border px-2 py-2.5 text-center transition-colors ${preset === x.key ? 'border-brand-blue bg-brand-blue/10' : 'border-[#3a3a3a] hover:border-[#4b5563]'}` },
h('div', { className: `text-[12.5px] font-semibold leading-tight ${preset === x.key ? 'text-white' : 'text-gray-300'}` }, x.label),
h('div', { className: 'text-[11px] text-gray-500 mt-0.5' }, x.desc)))),
// ๋ฏธ๋ฆฌ๋ณด๊ธฐ
p.w
? h('div', { className: 'flex flex-col items-center gap-3' },
h('div', { className: 'relative' },
h('canvas', { ref: canvasRef, onPointerDown: startDrag,
className: 'max-h-[52vh] w-auto max-w-full rounded-lg border border-[#3a3a3a] bg-white cursor-grab active:cursor-grabbing select-none touch-none' }),
h('div', { className: 'absolute bottom-2 left-1/2 -translate-x-1/2 text-[10.5px] text-gray-400 bg-black/55 rounded-full px-2.5 py-0.5 pointer-events-none' }, '๋“œ๋ž˜๊ทธ๋กœ ์œ„์น˜ ์กฐ์ ˆ')),
h('div', { className: 'w-full max-w-[420px] flex items-center gap-3' },
h('span', { className: 'text-[11.5px] text-gray-500 shrink-0' }, '๋ชจ๋ธ ํฌ๊ธฐ'),
h('input', { type: 'range', min: 100, max: 180, value: Math.round(zoom * 100),
onChange: e => setZoom(e.target.value / 100), className: 'flex-1 accent-[#3B82F6]' }),
h('span', { className: 'text-[11.5px] text-gray-400 w-10 text-right font-mono' }, `${Math.round(zoom * 100)}%`),
h('button', { type: 'button', onClick: () => { setZoom(1); setOff({ x: 0, y: 0 }); },
className: 'text-[11.5px] text-gray-500 hover:text-gray-300 shrink-0' }, '์ดˆ๊ธฐํ™”')),
h('p', { className: 'text-[11.5px] text-gray-500 text-center leading-relaxed m-0' },
'100% = ์ „์ฒด๊ฐ€ ๋‹ค ๋“ค์–ด๊ฐ€๋Š” ์ƒํƒœ (์ขŒ์šฐ๋Š” ๋ฐฐ๊ฒฝ ์—ฐ์žฅ). ์Šฌ๋ผ์ด๋”๋ฅผ ์˜ฌ๋ฆฌ๋ฉด ์œ„์•„๋ž˜ ์—ฌ๋ฐฑ๋ถ€ํ„ฐ ์ž˜๋ฆฌ๋ฉฐ ๋ชจ๋ธ์ด ์ปค์ง‘๋‹ˆ๋‹ค.'))
: h('p', { className: 'text-[12.5px] text-gray-400 text-center py-6 m-0' }, '์ƒ์„ฑ๋œ ์›๋ณธ(1536ร—2048)์„ ๊ทธ๋Œ€๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.'),
// ์ €์žฅ
h('div', { className: 'flex items-center justify-between gap-3' },
h('span', { className: 'text-[11.5px] text-gray-500' }, aiLabel ? "'AI ์ƒ์„ฑ ์ด๋ฏธ์ง€' ํ‘œ๊ธฐ ํฌํ•จ" : 'AI ํ‘œ๊ธฐ ์—†์Œ'),
h('button', { type: 'button', onClick: save,
className: 'h-10 px-5 rounded-xl bg-brand-blue hover:bg-brand-hover text-white text-[13px] font-semibold flex items-center gap-1.5' },
h(Download, { size: 15 }), p.w ? `${p.desc} ์ €์žฅ` : '์›๋ณธ ์ €์žฅ'))));
}
// ๋น„๋กœ๊ทธ์ธ ์‚ฌ์šฉ์ž๋„ ์ž‘์—…์„ ๋‹ค์‹œ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๋„๋ก ๋ธŒ๋ผ์šฐ์ €๋ณ„ ID๋ฅผ ๋ณด๊ด€ (๋กœ๊ทธ์ธ ์‹œ์—” ์„œ๋ฒ„๊ฐ€ ๊ณ„์ •๋ช…์œผ๋กœ ๋ฌถ์Œ)
const CLIENT_ID = (() => {
try {
let id = localStorage.getItem('clovis_client_id');
if (!id) { id = crypto.randomUUID(); localStorage.setItem('clovis_client_id', id); }
return id;
} catch { return 'c-' + Math.random().toString(36).slice(2); }
})();
const apiHeaders = (json = false) => ({ 'X-Client-Id': CLIENT_ID, ...(json ? { 'Content-Type': 'application/json' } : {}) });
// ์ œ์ถœ โ†’ jobId โ†’ ํด๋ง. ๊ธด HTTP ์—ฐ๊ฒฐ์„ ์žก๊ณ  ์žˆ์ง€ ์•Š์œผ๋ฏ€๋กœ Space ํ”„๋ก์‹œ ํƒ€์ž„์•„์›ƒ๊ณผ ๋ฌด๊ด€.
async function submitToComfy(payload) {
const res = await fetch('/api/comfy/generate', { method: 'POST', headers: apiHeaders(true), body: JSON.stringify(payload) });
if (!res.ok) { const e = await res.json().catch(() => ({})); throw new Error(e.detail || `HTTP ${res.status}`); }
return (await res.json()).jobId;
}
async function pollComfyJob(jobId, onProgress) {
let misses = 0;
while (true) {
await sleep(3000);
let r;
try { r = await fetch(`/api/comfy/jobs/${jobId}`, { headers: apiHeaders() }); } catch { if (++misses > 10) throw new Error('์„œ๋ฒ„ ์‘๋‹ต์ด ์—†์Šต๋‹ˆ๋‹ค.'); continue; }
if (r.status === 404) throw new Error('์ž‘์—… ์ •๋ณด๋ฅผ ์žƒ์–ด๋ฒ„๋ ธ์Šต๋‹ˆ๋‹ค (์„œ๋ฒ„ ์žฌ์‹œ์ž‘). ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.');
if (!r.ok) { if (++misses > 10) throw new Error(`HTTP ${r.status}`); continue; }
misses = 0;
const j = await r.json();
onProgress?.(j);
if (j.status === 'done') return j;
if (j.status === 'cancelled') return null; // ์‚ฌ์šฉ์ž ์ทจ์†Œ โ€” ์กฐ์šฉํžˆ ์ข…๋ฃŒ
if (j.status === 'error') throw new Error(j.error || '์ƒ์„ฑ ์‹คํŒจ');
}
}
const fmtSec = (s) => { s = Math.round(s || 0); return s >= 60 ? `${Math.floor(s / 60)}๋ถ„ ${s % 60}์ดˆ` : `${s}์ดˆ`; };
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// UI atoms
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
const SectionTitle = ({ children, right }) => h('div', { className: 'flex items-center justify-between mb-2.5' },
h('h3', { className: 'text-[13px] font-semibold text-gray-200 tracking-tight' }, children), right || null);
const Segmented = ({ options, value, onChange, cols }) => h('div', {
className: `grid gap-1.5`, style: { gridTemplateColumns: `repeat(${cols || options.length}, minmax(0, 1fr))` } },
options.map(o => h('button', {
key: o, type: 'button', onClick: () => onChange(o),
className: `px-2 py-2 rounded-lg text-[12.5px] font-medium border transition-colors ${value === o
? 'bg-brand-blue border-brand-blue text-white'
: 'bg-[#242424] border-[#333] text-gray-300 hover:border-[#4b5563] hover:text-white'}`
}, o)));
const UploadTile = ({ slot, value, onChange, disabled }) => {
const inputRef = useRef(null);
const [drag, setDrag] = useState(false);
const handleFiles = async (files) => {
const f = files?.[0]; if (!f || !f.type.startsWith('image/')) return;
onChange(await fileToDataUrl(f), f.name);
};
return h('div', {
className: `relative rounded-xl border overflow-hidden group ${drag ? 'drop-active' : ''} ${value ? 'border-[#3a3a3a]' : 'border-dashed border-[#3a3a3a] bg-[#212121] hover:border-[#4b5563]'}`,
style: { aspectRatio: '3 / 4' },
onDragOver: e => { e.preventDefault(); setDrag(true); }, onDragLeave: () => setDrag(false),
onDrop: e => { e.preventDefault(); setDrag(false); if (!disabled) handleFiles(e.dataTransfer.files); },
onClick: () => !disabled && !value && inputRef.current?.click(),
},
h('input', { ref: inputRef, type: 'file', accept: 'image/*', className: 'hidden', onChange: e => { handleFiles(e.target.files); e.target.value = ''; } }),
value
? h(React.Fragment, null,
h('img', { src: value, className: 'w-full h-full object-cover bg-white', alt: slot.label }),
!disabled && h('button', { type: 'button', onClick: e => { e.stopPropagation(); onChange(null, null); },
className: 'absolute top-1.5 right-1.5 w-6 h-6 rounded-full bg-black/70 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity' }, h(X, { size: 13 })),
h('div', { className: 'absolute bottom-0 inset-x-0 px-2 py-1 bg-gradient-to-t from-black/70 to-transparent text-[11px] text-white' }, slot.label))
: h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center gap-1 text-gray-500 cursor-pointer' },
h(ImagePlus, { size: 18 }),
h('span', { className: 'text-[11.5px] text-gray-300' }, slot.label, slot.required && h('span', { className: 'text-brand-blue ml-0.5' }, '*')),
slot.hint && h('span', { className: 'text-[10px] text-gray-500 px-2 text-center leading-tight' }, slot.hint))
);
};
const DetailTile = ({ value, onChange, disabled }) => {
const inputRef = useRef(null);
const handleFiles = async (files) => {
const f = files?.[0]; if (!f || !f.type.startsWith('image/')) return;
onChange(await fileToDataUrl(f, 1024), f.name);
};
return h('div', {
className: `relative w-full rounded-lg overflow-hidden group ${value ? 'border border-[#3a3a3a]' : 'border border-dashed border-[#3a3a3a] bg-[#212121] hover:border-[#4b5563]'} ${disabled ? 'opacity-60 border-[#333]' : ''}`,
style: { aspectRatio: '1 / 1' },
onDragOver: e => e.preventDefault(), onDrop: e => { e.preventDefault(); if (!disabled) handleFiles(e.dataTransfer.files); },
onClick: () => !disabled && !value && inputRef.current?.click(),
},
h('input', { ref: inputRef, type: 'file', accept: 'image/*', className: 'hidden', onChange: e => { handleFiles(e.target.files); e.target.value = ''; } }),
value
? h(React.Fragment, null,
h('img', { src: value, className: 'w-full h-full object-cover bg-white' }),
!disabled && h('button', { type: 'button', onClick: e => { e.stopPropagation(); onChange(null, null); },
className: 'absolute top-1 right-1 w-5 h-5 rounded-full bg-black/70 text-white flex items-center justify-center opacity-0 group-hover:opacity-100' }, h(X, { size: 11 })))
: h('div', { className: 'absolute inset-0 flex items-center justify-center text-gray-600 cursor-pointer' }, h(ImagePlus, { size: 14 })));
};
const FaceTile = ({ preset, selected, onClick }) => h('button', {
type: 'button', onClick, title: preset.label,
className: `relative rounded-xl overflow-hidden border-2 transition-colors ${selected ? 'border-brand-blue' : 'border-transparent hover:border-[#4b5563]'}`,
style: { aspectRatio: '1 / 1' } },
h('img', { src: preset.url, className: 'w-full h-full object-cover', alt: preset.label }),
selected && h('div', { className: 'absolute top-1 right-1 w-5 h-5 rounded-full bg-brand-blue flex items-center justify-center' }, h(Check, { size: 12, className: 'text-white' })),
h('div', { className: 'absolute bottom-0 inset-x-0 px-1.5 py-0.5 bg-black/60 text-[10.5px] text-white text-center' }, preset.label));
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// App
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
function App() {
const [user, setUser] = useState({ username: 'anonymous', is_logged_in: false, oauth_enabled: false });
const [health, setHealth] = useState(null);
const age = '์„ฑ์ธ'; // CLOVIS: ์„ฑ์ธ ๊ณ ์ •
const [facePreset, setFacePreset] = useState('preset_17');
const [detailKinds, setDetailKinds] = useState({}); // 'outer:a' โ†’ kind key
const [faceUpload, setFaceUpload] = useState(null);
const [shot, setShot] = useState('์ „์‹ ์ปท');
const [angle, setAngle] = useState('๋ฐ˜์ธก๋ฉด');
const [gaze, setGaze] = useState('์ž์—ฐ์Šค๋Ÿฌ์šด ์‹œ์„ ');
const [prompt, setPrompt] = useState('');
const [details, setDetails] = useState(Object.fromEntries(Object.entries(DETAIL_OPTIONS).map(([k, v]) => [k, v.def])));
const [detailTab, setDetailTab] = useState('top');
const [images, setImages] = useState({});
const [imageNames, setImageNames] = useState({}); // ์Šฌ๋กฏ๋ณ„ ์›๋ณธ ํŒŒ์ผ๋ช… (Dataset ๋กœ๊ทธยท์Šคํƒ€์ผ์ฝ”๋“œ ์ง‘๊ณ„์šฉ)
const [faceUploadName, setFaceUploadName] = useState(null);
const [poseSpec, setPoseSpec] = useState(''); // ํฌ์ฆˆ ์ง€์‹œ ๋ฌธ์žฅ (๋น„์šฐ๋ฉด GPT ๋น„์ „์ด ๋ ˆํผ๋Ÿฐ์Šค์—์„œ ์ž๋™ ์ถ”์ถœ)
const [jobs, setJobs] = useState([]); // ์ง„ํ–‰ ์ค‘/์‹คํŒจ ์ž‘์—… [{id, jobId, meta, stageLabel, startedAt, error}]
const [tick, setTick] = useState(0); // ๊ฒฝ๊ณผ์‹œ๊ฐ„ ํ‘œ์‹œ์šฉ 1์ดˆ ํƒ€์ด๋จธ
const [results, setResults] = useState([]); // [{id, imageUrl, meta, elapsedSec}]
const [current, setCurrent] = useState(null);
const [error, setError] = useState(null);
const [aiLabel, setAiLabel] = useState(true);
const [lightbox, setLightbox] = useState(false); // ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€ ํ™•๋Œ€ ๋ณด๊ธฐ
const [exportOpen, setExportOpen] = useState(false); // ์ฑ„๋„ ์‚ฌ์ด์ฆˆ ๋‹ค์šด๋กœ๋“œ ๋ชจ๋‹ฌ
const [resultTab, setResultTab] = useState('session'); // 'session' | 'history'
const [hist, setHist] = useState({ items: null, loading: false, error: null, truncated: false });
const [showSpecs, setShowSpecs] = useState(false); // ์˜์ƒ ๋ถ„์„ ๊ฒฐ๊ณผ / ์ตœ์ข… ํ”„๋กฌํ”„ํŠธ ํŽผ์น˜๊ธฐ
useEffect(() => {
if (!lightbox) return;
const onKey = (e) => { if (e.key === 'Escape') setLightbox(false); };
window.addEventListener('keydown', onKey);
return () => window.removeEventListener('keydown', onKey);
}, [lightbox]);
const faceFileRef = useRef(null);
useEffect(() => {
fetch('/api/whoami').then(r => r.ok ? r.json() : null).then(d => d && setUser(d)).catch(() => {});
fetch('/api/comfy/health').then(r => r.ok ? r.json() : { ok: false, error: '๋ธŒ๋ฆฌ์ง€ ๋ผ์šฐํŠธ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค' }).then(setHealth).catch(() => setHealth({ ok: false, error: '์ƒํƒœ ํ™•์ธ ์‹คํŒจ' }));
}, []);
const activeJobs = jobs.filter(j => !j.error);
useEffect(() => {
if (activeJobs.length === 0) return;
const id = setInterval(() => setTick(t => t + 1), 1000);
return () => clearInterval(id);
}, [activeJobs.length]);
const presets = ADULT_FACE_PRESETS;
const setImg = (key, v, name) => {
setImages(prev => ({ ...prev, [key]: v })); setImageNames(prev => ({ ...prev, [key]: v ? (name || null) : null }));
if (key === 'pose' && !v) { if (angle === '๋ ˆํผ๋Ÿฐ์Šค ๋”ฐ๋ฆ„') setAngle('๋ฐ˜์ธก๋ฉด'); if (gaze === '๋ ˆํผ๋Ÿฐ์Šค ๋”ฐ๋ฆ„') setGaze('์ž์—ฐ์Šค๋Ÿฌ์šด ์‹œ์„ '); }
};
const kindOf = (g, slot) => { // ์ €์žฅ๋œ ๊ฐ’์ด ๊ทธ ์˜ท ์ข…๋ฅ˜์— ์—†์œผ๋ฉด ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ
const list = DETAIL_KINDS_BY_GARMENT[g] || [];
const v = detailKinds[`${g}:${slot}`];
return list.some(k => k.key === v) ? v : defaultKind(g, slot);
};
const detailList = DETAIL_GARMENTS.flatMap(g => DETAIL_SLOTS.map(slot => ({ garment: g.key, kind: kindOf(g.key, slot), image: images[`detail:${g.key}:${slot}`], filename: imageNames[`detail:${g.key}:${slot}`] })))
.filter(x => x.image && images[x.garment]);
const detailCount = detailList.length;
const missing = [];
if (!images.outer && !images.top && !images.bottom) missing.push('์˜์ƒ 1๊ฐœ ์ด์ƒ (์•„์šฐํ„ฐยท์ƒ์˜ยทํ•˜์˜)');
const canGenerate = missing.length === 0 && (faceUpload || facePreset) && health?.ok;
// ํ•˜๋‚˜์˜ payload ๋กœ ์ž‘์—… 1๊ฑด ์‹œ์ž‘. payload ๋Š” ๊ฒฐ๊ณผ์— ํ•จ๊ป˜ ๋ณด๊ด€๋˜์–ด "์ด ์„ค์ •์œผ๋กœ ๋‹ค์‹œ ์ƒ์„ฑ"์— ์“ฐ์ธ๋‹ค.
const startJob = async (payload, meta) => {
const id = Date.now().toString(36) + Math.random().toString(36).slice(2, 5);
setJobs(prev => [...prev, { id, meta, payload, stageLabel: '์š”์ฒญ ์ „์†ก ์ค‘', startedAt: Date.now() }]);
const patch = (p) => setJobs(prev => prev.map(j => j.id === id ? { ...j, ...p } : j));
let jobId;
try {
jobId = await submitToComfy(payload);
} catch (e) {
patch({ error: e.message }); return;
}
patch({ jobId, stageLabel: '๋Œ€๊ธฐ ์ค‘' });
await trackJob(id, jobId, meta, patch, payload);
};
const buildPayload = () => {
const meta = { shot, angle, gaze, age, prompt, face: faceUpload ? '์—…๋กœ๋“œ' : (presets.find(p => p.id === facePreset)?.label || facePreset) };
const mainImages = Object.fromEntries(Object.entries(images).filter(([k, v]) => v && !k.startsWith('detail:')));
return { face: faceUpload || facePreset, faceFilename: faceUpload ? faceUploadName : null, images: mainImages, imageFilenames: imageNames,
details: detailList.slice(0, DETAIL_MAX).map(x => ({ garment: x.garment, kind: x.kind, image: x.image, filename: x.filename || null })),
poseSpec: (images.pose || poseSpec.trim()) ? poseSpec.trim() : '',
options: { shot, angle, gaze, age, ...details }, prompt, meta };
};
const handleGenerate = () => {
if (user.oauth_enabled && !user.is_logged_in) { alert("๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์šฐ์ธก ์ƒ๋‹จ์˜ 'Hugging Face๋กœ ๋กœ๊ทธ์ธ' ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”."); return; }
if (!canGenerate) return;
setError(null);
const payload = buildPayload();
startJob(payload, payload.meta);
};
// ์ง€๋‚œ ๊ธฐ๋ก: HF Dataset ์— ์˜๊ตฌ ์ €์žฅ๋œ ๋ณธ์ธ ์ƒ์„ฑ ์ด๋ ฅ (์„ธ์…˜๊ณผ ๋ฌด๊ด€ํ•˜๊ฒŒ ์œ ์ง€๋จ)
const loadHistory = async (refresh = false) => {
setHist(prev => ({ ...prev, loading: true, error: null }));
try {
const r = await fetch(`/api/my/history${refresh ? '?refresh=1' : ''}`, { headers: apiHeaders() });
if (!r.ok) throw new Error(r.status === 401 ? '๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.' : '๊ธฐ๋ก์„ ๋ถˆ๋Ÿฌ์˜ค์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.');
const j = await r.json();
const items = (j.items || []).map(it => ({
id: `hist_${it.ts}`, history: true,
imageUrl: it.imageUrl, thumbUrl: it.thumbUrl || it.imageUrl,
meta: { shot: it.shot, angle: it.angle, gaze: it.gaze, age: '์„ฑ์ธ', face: it.face, prompt: it.prompt },
elapsedSec: it.elapsed, createdAt: it.time, finalPrompt: it.fullPrompt || null,
garmentSpecs: null, poseSpec: null,
}));
setHist({ items, loading: false, error: null, truncated: !!j.truncated });
} catch (e) {
setHist(prev => ({ ...prev, loading: false, error: e.message }));
}
};
useEffect(() => { if (resultTab === 'history' && hist.items === null && !hist.loading) loadHistory(); }, [resultTab]);
// ์„ธ์…˜ ๊ฒฐ๊ณผ ์‚ญ์ œ: ํ™”๋ฉด์—์„œ ์ œ๊ฑฐ + ์„œ๋ฒ„ ๋ณด๊ด€๋ถ„๋„ ์‚ญ์ œํ•ด ์ƒˆ๋กœ๊ณ ์นจ ๋ณต๊ตฌ๋ฅผ ๋ง‰์Œ
const deleteResult = async (r) => {
if (!confirm('์ด ๊ฒฐ๊ณผ๋ฅผ ์ง€์šธ๊นŒ์š”? ๋˜๋Œ๋ฆด ์ˆ˜ ์—†์–ด์š”.')) return;
setResults(prev => {
const next = prev.filter(x => x.id !== r.id);
setCurrent(cur => (cur?.id === r.id ? (next[0] || null) : cur));
return next;
});
try { if (r.jobId) await fetch(`/api/comfy/jobs/${r.jobId}`, { method: 'DELETE', headers: apiHeaders() }); } catch {}
};
// ์„ธ์…˜ ๊ฒฐ๊ณผ์— ๋ณด๊ด€๋œ payload ๋กœ ๋™์ผ ์กฐ๊ฑด ์žฌ์ƒ์„ฑ (ํ˜„์žฌ ํผ ์ƒํƒœ๋Š” ๊ฑด๋“œ๋ฆฌ์ง€ ์•Š์Œ)
const regenFrom = (r) => {
if (user.oauth_enabled && !user.is_logged_in) { alert("๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค."); return; }
if (!r?.payload) return;
startJob(r.payload, r.meta);
};
// ์„œ๋ฒ„ ์ž‘์—…์„ ์™„๋ฃŒ๊นŒ์ง€ ๋”ฐ๋ผ๊ฐ€๋ฉฐ ๊ฒฐ๊ณผ/์—๋Ÿฌ๋ฅผ ๋ฐ˜์˜ (์ƒˆ ์š”์ฒญ๊ณผ ์ƒˆ๋กœ๊ณ ์นจ ๋ณต๊ตฌ ๋‘˜ ๋‹ค ์‚ฌ์šฉ)
const trackJob = async (id, jobId, meta, patch, payload = null) => {
try {
const j = await pollComfyJob(jobId, (st) => patch({ stageLabel: st.stageLabel, execStartedAt: st.execStartedAt || null }));
if (!j) { setJobs(prev => prev.filter(x => x.id !== id)); return; } // ์ทจ์†Œ๋จ
const item = { id, jobId, imageUrl: j.imageUrl, meta, payload, elapsedSec: j.elapsedSec, createdAt: j.createdAt, garmentSpecs: j.garmentSpecs || null, finalPrompt: j.finalPrompt || null, poseSpec: j.poseSpec || null };
setResults(prev => prev.some(r => r.id === id) ? prev : [item, ...prev]);
setCurrent(prev => prev || item);
setJobs(prev => prev.filter(x => x.id !== id));
} catch (e) {
patch({ error: e.message });
}
};
const dismissJob = (id) => setJobs(prev => prev.filter(j => j.id !== id));
const cancelJob = async (job) => { // ์ง„ํ–‰ ์ค‘ ์ž‘์—… ์ทจ์†Œ: ์„œ๋ฒ„์— ์š”์ฒญ ํ›„ ์นด๋“œ ์ œ๊ฑฐ (ํด๋ง๋„ cancelled ๋ฅผ ๋ณด๊ณ  ๋ฉˆ์ถค)
setJobs(prev => prev.map(x => x.id === job.id ? { ...x, cancelling: true, stageLabel: '์ทจ์†Œ ์ค‘' } : x));
try { if (job.jobId) await fetch(`/api/comfy/jobs/${job.jobId}/cancel`, { method: 'POST', headers: apiHeaders() }); } catch {}
setJobs(prev => prev.filter(x => x.id !== job.id));
};
// ์ƒˆ๋กœ๊ณ ์นจ/์žฌ์ ‘์† ์‹œ ์„œ๋ฒ„์— ๋‚จ์•„ ์žˆ๋Š” ๋‚ด ์ž‘์—… ๋ณต๊ตฌ
useEffect(() => {
(async () => {
try {
const r = await fetch('/api/comfy/jobs', { headers: apiHeaders() });
if (!r.ok) return;
const { jobs: saved } = await r.json();
const done = saved.filter(j => j.status === 'done' && j.imageUrl)
.map(j => ({ id: j.id, jobId: j.id, imageUrl: j.imageUrl, meta: j.meta || {}, elapsedSec: j.elapsedSec, createdAt: j.createdAt, garmentSpecs: j.garmentSpecs || null, finalPrompt: j.finalPrompt || null, poseSpec: j.poseSpec || null }))
.sort((a, b) => b.createdAt - a.createdAt);
if (done.length) { setResults(done); setCurrent(prev => prev || done[0]); }
const pending = saved.filter(j => j.status !== 'done' && j.status !== 'cancelled');
if (pending.length) {
setJobs(pending.map(j => ({ id: j.id, jobId: j.id, meta: j.meta || {}, stageLabel: j.stageLabel, startedAt: j.createdAt, execStartedAt: j.execStartedAt || null, error: j.error || null })));
for (const j of pending.filter(x => x.status === 'running')) {
const patch = (p) => setJobs(prev => prev.map(x => x.id === j.id ? { ...x, ...p } : x));
trackJob(j.id, j.id, j.meta || {}, patch);
}
}
} catch {}
})();
}, []);
// โ”€โ”€ Left: settings โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
const left = h('aside', { className: 'w-full lg:w-[420px] xl:w-[460px] shrink-0 h-full overflow-y-auto border-r border-[#2a2a2a] bg-[#1e1e1e]' },
h('div', { className: 'p-5 space-y-6' },
h('section', null,
h(SectionTitle, null, '์–ผ๊ตด'),
h('div', { className: 'grid grid-cols-4 gap-2' },
presets.map(p => h(FaceTile, { key: p.id, preset: p, selected: !faceUpload && facePreset === p.id, onClick: () => { setFaceUpload(null); setFacePreset(p.id); } })),
h('button', { type: 'button', onClick: () => faceFileRef.current?.click(),
className: `relative rounded-xl overflow-hidden border-2 ${faceUpload ? 'border-brand-blue' : 'border-dashed border-[#3a3a3a] hover:border-[#4b5563] bg-[#242424]'}`, style: { aspectRatio: '1 / 1' } },
faceUpload
? h(React.Fragment, null, h('img', { src: faceUpload, className: 'w-full h-full object-cover' }),
h('span', { onClick: e => { e.stopPropagation(); setFaceUpload(null); }, className: 'absolute top-1 right-1 w-5 h-5 rounded-full bg-black/70 flex items-center justify-center' }, h(X, { size: 11 })),
h('div', { className: 'absolute bottom-0 inset-x-0 py-0.5 bg-black/60 text-[10.5px] text-center' }, '์—…๋กœ๋“œ'))
: h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center gap-1 text-gray-400' }, h(User, { size: 16 }), h('span', { className: 'text-[10.5px]' }, '์ง์ ‘ ์—…๋กœ๋“œ'))),
h('input', { ref: faceFileRef, type: 'file', accept: 'image/*', className: 'hidden', onChange: async e => { const f = e.target.files?.[0]; if (f) { setFaceUpload(await fileToDataUrl(f, 1024)); setFaceUploadName(f.name); } e.target.value = ''; } }))),
h('section', null, h(SectionTitle, null, '์ƒท ์„ ํƒ'), h(Segmented, { options: SHOT_OPTIONS, value: shot, cols: 3, onChange: setShot })),
h('section', null,
h(SectionTitle, { right: images.pose && h('span', { className: 'text-[11px] text-gray-500' }, "'๋ ˆํผ๋Ÿฐ์Šค ๋”ฐ๋ฆ„' = ํฌ์ฆˆ ์‚ฌ์ง„์˜ ์•ต๊ธ€") }, '์นด๋ฉ”๋ผ ์•ต๊ธ€'),
h(Segmented, { options: images.pose ? ANGLE_OPTIONS : ANGLE_OPTIONS.filter(o => o !== '๋ ˆํผ๋Ÿฐ์Šค ๋”ฐ๋ฆ„'), value: angle, onChange: setAngle, cols: 4 })),
h('section', null, h(SectionTitle, null, '์‹œ์„ '), h(Segmented, { options: images.pose ? GAZE_OPTIONS : GAZE_OPTIONS.filter(o => o !== '๋ ˆํผ๋Ÿฐ์Šค ๋”ฐ๋ฆ„'), value: gaze, onChange: setGaze })),
h('section', null,
h(SectionTitle, null, 'ํ”„๋กฌํ”„ํŠธ ์ž‘์„ฑ'),
h('textarea', { value: prompt, onChange: e => setPrompt(e.target.value), rows: 3,
placeholder: '์ถ”๊ฐ€ ์ง€์‹œ์‚ฌํ•ญ (์„ ํƒ). ์˜ˆ: ์†์„ ์ฃผ๋จธ๋‹ˆ์— ๋„ฃ๊ณ  ์‚ด์ง ๋ฏธ์†Œ, ์†Œ๋งค๋ฅผ ํ•œ ๋ฒˆ ์ ‘์–ด ์˜ฌ๋ฆฐ ์Šคํƒ€์ผ๋ง',
className: 'w-full rounded-xl bg-[#242424] border border-[#333] px-3 py-2.5 text-[13px] text-gray-100 placeholder-gray-500 focus:outline-none focus:border-brand-blue' })),
h('section', null,
h(SectionTitle, { right: h('span', { className: 'text-[11px] text-gray-500' }, '์•„์šฐํ„ฐยท์ƒ์˜ยทํ•˜์˜ ์ค‘ 1๊ฐœ ์ด์ƒ') }, '์ด๋ฏธ์ง€ ์—…๋กœ๋“œ'),
h('div', { className: 'grid grid-cols-4 gap-2' },
IMAGE_SLOTS.map(s => h(UploadTile, { key: s.key, slot: s, value: images[s.key], onChange: (v, name) => setImg(s.key, v, name) })))),
(images.pose || poseSpec) && (health?.ok && health.poseText !== false) && h('section', { className: 'animate-fadeIn' },
h(SectionTitle, { right: h('span', { className: 'text-[11px] text-gray-500' }, '๋น„์šฐ๋ฉด ๋ ˆํผ๋Ÿฐ์Šค์—์„œ ์ž๋™ ์ถ”์ถœ') }, 'ํฌ์ฆˆ ์ง€์‹œ (์„ ํƒ)'),
h('textarea', { value: poseSpec, onChange: e => setPoseSpec(e.target.value), rows: 3,
placeholder: '์˜ˆ: ์˜ค๋ฅธํŒ”์„ ๋“ค์–ด ์†๋“ฑ์„ ์˜ค๋ฅธ์ชฝ ๊ด€์ž๋†€์ด์— ๊ฐ€๋ณ๊ฒŒ ๋Œ„๋‹ค. ์™ผํŒ”์€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋‚ด๋ฆฌ๊ณ  ์ฒด์ค‘์€ ์™ผ๋ฐœ์—. ๋ชธํ†ต์€ ์นด๋ฉ”๋ผ ์ชฝ์œผ๋กœ ์‚ด์ง ์šฐ์ธก.',
className: 'w-full rounded-xl bg-[#242424] border border-[#333] px-3 py-2.5 text-[12.5px] text-gray-100 placeholder-gray-500 focus:outline-none focus:border-brand-blue' }),
h('p', { className: 'text-[11px] text-gray-500 mt-1.5 leading-relaxed' }, '๋ ˆํผ๋Ÿฐ์Šค ํฌ์ฆˆ๋ฅผ ๋ฌธ์žฅ์œผ๋กœ ๋ฐ”๊ฟ” ํ”„๋กฌํ”„ํŠธ ๋งจ ๋์— ์ตœ์šฐ์„  ์ง€์‹œ๋กœ ๋„ฃ์–ด์š”. ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋ฉด ์•„๋ž˜ ํŒจ๋„์—์„œ ์ž๋™ ์ถ”์ถœ๋œ ๋ฌธ์žฅ์„ ํ™•์ธํ•˜๊ณ , ํ‹€๋ฆฐ ๋ถ€๋ถ„์„ ์—ฌ๊ธฐ์„œ ๊ณ ์ณ ๋‹ค์‹œ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์–ด์š”.')),
h('section', null,
h(SectionTitle, null, '๊ธธ์ด ยท ํ•'),
h('div', { className: 'flex gap-1.5 mb-3' },
DETAIL_GROUPS.map(g => h('button', {
key: g.key, type: 'button', onClick: () => setDetailTab(g.key),
className: `px-3 py-1.5 rounded-lg text-[12.5px] font-semibold transition-colors ${detailTab === g.key
? 'bg-brand-blue text-white'
: (images[g.key] ? 'bg-[#2a2a2a] text-gray-200 hover:bg-[#333]' : 'bg-[#242424] text-gray-500 hover:text-gray-300')}`
}, g.label, images[g.key] ? h('span', { className: `ml-1.5 inline-block w-1.5 h-1.5 rounded-full align-middle ${detailTab === g.key ? 'bg-white' : 'bg-brand-blue'}` }) : null))),
(() => {
const g = DETAIL_GROUPS.find(x => x.key === detailTab);
const rows = [['๊ธธ์ด', g.length], ['ํ•', g.fit]];
return h('div', { key: g.key, className: 'space-y-2 animate-fadeIn' },
rows.map(([label, k]) => h('div', { key: k, className: 'grid grid-cols-[52px_1fr] items-center gap-2' },
h('span', { className: 'text-[12px] text-gray-400' }, label),
h('div', { className: 'flex flex-wrap gap-1.5' },
DETAIL_OPTIONS[k].options.map(o => h('button', {
key: o, type: 'button', onClick: () => setDetails(d => ({ ...d, [k]: o })),
className: `px-3 py-1.5 rounded-lg text-[12.5px] font-medium border transition-colors ${details[k] === o
? 'bg-brand-blue border-brand-blue text-white'
: 'bg-[#242424] border-[#333] text-gray-300 hover:border-[#4b5563] hover:text-white'}`
}, o))))),
!images[g.key] && h('p', { className: 'text-[11px] text-gray-500 pt-1' }, `${g.label} ์ด๋ฏธ์ง€๋ฅผ ์˜ฌ๋ฆฌ์ง€ ์•Š์œผ๋ฉด ์ด ์„ค์ •์€ ์‚ฌ์šฉ๋˜์ง€ ์•Š์•„์š”.`));
})()),
h('section', null,
h(SectionTitle, { right: h('span', { className: `text-[11px] ${detailCount >= DETAIL_MAX ? 'text-amber-400' : 'text-gray-500'}` }, `์„ ํƒ ยท ${detailCount}/${DETAIL_MAX}์žฅ`) }, '๋””ํ…Œ์ผ ์ฐธ์กฐ'),
health?.ok && health.detailCuts === false
? h('p', { className: 'text-[11.5px] text-gray-500' }, 'ํ˜„์žฌ ๋ฐฐํฌ๋œ ์›Œํฌํ”Œ๋กœ์šฐ(workflow_api.json)์— ๋””ํ…Œ์ผ ์ฐธ์กฐ ์ž…๋ ฅ์ด ์—†์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์–ด์š”. v5 ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ Export (API)ํ•ด์„œ ๊ต์ฒดํ•ด์ฃผ์„ธ์š”.')
: h(React.Fragment, null,
h('p', { className: 'text-[11px] text-gray-500 mb-2.5 leading-relaxed' }, 'ํด๋กœ์ฆˆ์—…์„ ์˜ฌ๋ฆฌ๊ณ  ์–ด๋–ค ๋ถ€์œ„์ธ์ง€ ๊ณจ๋ผ์ฃผ์„ธ์š” (์˜ท ์ข…๋ฅ˜๋ณ„๋กœ ํ•ญ๋ชฉ์ด ๋‹ฌ๋ผ์š”). ์กฐ์ง๊ฐยท์†Œ์žฌ๋Š” ์˜ท ์ „์ฒด์—, ๋‚˜๋จธ์ง€๋Š” ๊ทธ ๋ถ€์œ„์—๋งŒ ๋ฐ˜์˜ํ•˜๊ณ  ์‹ค๋ฃจ์—ฃ์€ ๋ฉ”์ธ ์‚ฌ์ง„ ๊ทธ๋Œ€๋กœ ์œ ์ง€ํ•˜๋„๋ก ์ „๋‹ฌ๋ผ์š”. ์ฐธ์กฐ๊ฐ€ ๋งŽ์œผ๋ฉด ์ •ํ™•๋„๊ฐ€ ๋–จ์–ด์ ธ์„œ ์ „์ฒด 4์žฅ๊นŒ์ง€๋งŒ.'),
h('div', { className: 'grid grid-cols-2 gap-x-4 gap-y-2.5' },
DETAIL_GARMENTS.map(g => {
const enabled = !!images[g.key];
return h('div', { key: g.key, className: 'flex items-center gap-2' },
h('span', { className: `w-14 shrink-0 text-[12px] ${enabled ? 'text-gray-300' : 'text-gray-600'}`, title: enabled ? '' : `${g.label} ์ด๋ฏธ์ง€๋ฅผ ๋จผ์ € ์˜ฌ๋ ค์ฃผ์„ธ์š”` }, g.label),
DETAIL_SLOTS.map(slot => {
const id = `${g.key}:${slot}`;
const cur = images[`detail:${id}`];
const kind = kindOf(g.key, slot);
const kindList = DETAIL_KINDS_BY_GARMENT[g.key] || [];
const kindObj = kindList.find(k => k.key === kind) || kindList[0];
return h('div', { key: slot, className: 'w-16 flex flex-col items-center gap-1' },
h(DetailTile, { value: cur, disabled: !enabled || (!cur && detailCount >= DETAIL_MAX), onChange: (v, name) => setImg(`detail:${id}`, v, name) }),
// ์ข…๋ฅ˜ ์„ ํƒ ์นฉ โ€” ๋„ค์ดํ‹ฐ๋ธŒ select ๋ฅผ ๋ฒ„ํŠผ์ฒ˜๋Ÿผ ๋ณด์ด๊ฒŒ (appearance-none + ์ปค์Šคํ…€ ํ™”์‚ดํ‘œ)
h('div', { className: 'relative w-full', title: enabled ? `${kindObj.label} ยท ํด๋ฆญํ•ด์„œ ๋ถ€์œ„ ๋ณ€๊ฒฝ` : '' },
h('select', {
value: kind, disabled: !enabled,
onChange: e => setDetailKinds(prev => ({ ...prev, [id]: e.target.value })),
style: { appearance: 'none', WebkitAppearance: 'none', MozAppearance: 'none' },
className: `w-full h-6 rounded-md border text-[10.5px] font-medium pl-1.5 pr-5 cursor-pointer focus:outline-none focus:border-brand-blue transition-colors
${cur ? 'bg-brand-blue/15 border-brand-blue/60 text-blue-200 hover:bg-brand-blue/25'
: 'bg-[#2a2a2a] border-[#3f3f3f] text-gray-300 hover:border-[#5a5a5a] hover:bg-[#303030]'}
disabled:opacity-40 disabled:cursor-default`
}, kindList.map(k => h('option', { key: k.key, value: k.key, className: 'bg-[#242424] text-gray-200' }, k.short))),
h(ChevronDown, { size: 12, className: `absolute right-1 top-1/2 -translate-y-1/2 pointer-events-none ${cur ? 'text-blue-200' : 'text-gray-400'}` })));
}));
})))),
h('div', { className: 'pt-3 pb-3 sticky bottom-0 bg-[#1e1e1e] border-t border-[#2a2a2a] -mx-5 px-5' },
missing.length > 0 && h('p', { className: 'text-[11.5px] text-gray-500 mb-2' }, `ํ•„์š”: ${missing.join(', ')}`),
activeJobs.length > 0 && missing.length === 0 && h('p', { className: 'text-[11.5px] text-gray-500 mb-2' }, `${activeJobs.length}๊ฑด ์ง„ํ–‰ ์ค‘ โ€” ์„ค์ •์„ ๋ฐ”๊ฟ” ๋ฐ”๋กœ ๋‹ค์Œ ์ปท์„ ๊ฑธ์–ด๋‘˜ ์ˆ˜ ์žˆ์–ด์š”`),
h('button', { type: 'button', onClick: handleGenerate, disabled: !canGenerate,
className: `w-full h-12 rounded-xl font-semibold text-[14px] flex items-center justify-center gap-2 transition-colors ${canGenerate ? 'bg-brand-blue hover:bg-brand-hover text-white' : 'bg-[#2a2a2a] text-gray-500 cursor-not-allowed'}` },
h(Sparkles, { size: 16 }),
activeJobs.length > 0 ? `๋ฃฉ๋ถ ์ƒ์„ฑ (${activeJobs.length}๊ฑด ์ง„ํ–‰ ์ค‘)` : '๋ฃฉ๋ถ ์ƒ์„ฑ'))));
// โ”€โ”€ Right: result โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
const right = h('main', { className: 'flex-1 h-full overflow-y-auto' },
h('div', { className: 'max-w-5xl mx-auto p-6 lg:p-8' },
!health?.ok && health && h('div', { className: 'mb-5 rounded-xl border border-amber-500/40 bg-amber-500/10 px-4 py-3 text-[13px] text-amber-200 flex gap-2' },
h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', null, health.error || 'Comfy ๋ธŒ๋ฆฌ์ง€ ์„ค์ •์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”.')),
health?.ok && health.loginRequired === false && h('div', { className: 'mb-5 rounded-xl border border-amber-500/40 bg-amber-500/10 px-4 py-3 text-[13px] text-amber-200 flex gap-2' },
h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', null, 'HF OAuth๊ฐ€ ์—ฐ๊ฒฐ๋˜์ง€ ์•Š์•„ ๋กœ๊ทธ์ธ ์—†์ด ๋ˆ„๊ตฌ๋‚˜ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ์ƒํƒœ์ž…๋‹ˆ๋‹ค. README์˜ hf_oauth ์„ค์ •๊ณผ Space ์žฌ์‹œ์ž‘์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”.')),
error && h('div', { className: 'mb-5 rounded-xl border border-red-500/40 bg-red-500/10 px-4 py-3 text-[13px] text-red-200 flex gap-2 animate-fadeIn' },
h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', { className: 'break-all' }, error)),
jobs.length > 0 && h('div', { className: 'mb-5 rounded-xl border border-[#2a2a2a] bg-[#202020] overflow-hidden animate-fadeIn' },
h('div', { className: 'px-4 py-2.5 border-b border-[#2a2a2a] text-[12.5px] font-semibold text-gray-300 flex items-center gap-2' },
h(RefreshCw, { size: 13, className: activeJobs.length ? 'animate-spin text-brand-blue' : 'text-gray-500' }),
`์ง„ํ–‰ ์ค‘ ${activeJobs.length}๊ฑด`, jobs.length - activeJobs.length > 0 ? h('span', { className: 'text-red-300 font-normal' }, ` ยท ์‹คํŒจ ${jobs.length - activeJobs.length}๊ฑด`) : null),
jobs.map((j, i) => h('div', { key: j.id, className: `px-4 py-2.5 flex items-center gap-3 text-[12.5px] ${i > 0 ? 'border-t border-[#262626]' : ''}` },
h('div', { className: `w-1.5 h-1.5 rounded-full shrink-0 ${j.error ? 'bg-red-400' : 'bg-brand-blue pulse-ring relative'}` }),
h('div', { className: 'flex-1 min-w-0' },
h('div', { className: 'text-gray-100 truncate' }, `${j.meta.face} ยท ${j.meta.shot} ยท ${j.meta.angle} ยท ${j.meta.gaze}`, j.meta.prompt ? h('span', { className: 'text-gray-500' }, ` ยท "${j.meta.prompt}"`) : null),
h('div', { className: j.error ? 'text-red-300 break-all' : 'text-gray-400' },
j.error ? j.error : (j.execStartedAt ? `${j.stageLabel} ยท ${fmtSec((Date.now() - j.execStartedAt) / 1000)}` : `${j.stageLabel} ยท ๋Œ€๊ธฐ ${fmtSec((Date.now() - j.startedAt) / 1000)}`))),
j.error
? h('button', { type: 'button', title: '์ง€์šฐ๊ธฐ', onClick: () => dismissJob(j.id), className: 'text-gray-500 hover:text-white' }, h(X, { size: 14 }))
: h('button', { type: 'button', title: '์ž‘์—… ์ทจ์†Œ', disabled: j.cancelling, onClick: () => cancelJob(j),
className: 'shrink-0 text-[11.5px] px-2.5 py-1 rounded-lg border border-[#3a3a3a] text-gray-400 hover:text-red-300 hover:border-red-400/50 disabled:opacity-50 transition-colors' },
j.cancelling ? '์ทจ์†Œ ์ค‘โ€ฆ' : '์ทจ์†Œ')))),
h('div', { className: 'grid grid-cols-1 md:grid-cols-[minmax(0,1fr)_200px] gap-6' },
// ๋ฉ”์ธ ๋ทฐ์–ด
h('div', { className: 'rounded-2xl bg-[#202020] border border-[#2a2a2a] overflow-hidden relative', style: { minHeight: '60vh' } },
!current && activeJobs.length > 0
? h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center gap-5' },
h('div', { className: 'shimmer absolute inset-0 opacity-60' }),
h('div', { className: 'relative pulse-ring w-14 h-14 rounded-full bg-brand-blue/20 flex items-center justify-center' }, h(Sparkles, { size: 22, className: 'text-brand-blue' })),
h('div', { className: 'relative text-center' },
h('div', { className: 'text-[15px] font-semibold text-gray-100' }, activeJobs[0].stageLabel),
h('div', { className: 'mt-1 text-[12.5px] text-gray-400 flex items-center justify-center gap-1' }, h(Clock, { size: 12 }),
activeJobs[0].execStartedAt ? `${fmtSec((Date.now() - activeJobs[0].execStartedAt) / 1000)} ๊ฒฝ๊ณผ ยท ๋ณดํ†ต 1~2๋ถ„ ์†Œ์š”` : '์‹คํ–‰ ์ˆœ์„œ๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ค‘')),
h('p', { className: 'relative text-[11.5px] text-gray-500 max-w-xs text-center' }, '์ด ํƒญ์„ ๋‹ซ์ง€ ๋งˆ์„ธ์š”. ์ƒ์„ฑ์ด ๋๋‚˜๋ฉด ์—ฌ๊ธฐ์— ์ด๋ฏธ์ง€๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.'))
: current
? h('div', { className: 'animate-fadeIn flex flex-col' },
h('div', { className: 'flex justify-center bg-[#1c1c1c]' },
h('div', { className: 'relative inline-block' },
h('img', { src: current.imageUrl, onClick: () => setLightbox(true), title: 'ํด๋ฆญํ•˜๋ฉด ํฌ๊ฒŒ ๋ณด๊ธฐ',
className: 'max-h-[78vh] w-auto max-w-full block bg-white cursor-zoom-in', alt: '์ƒ์„ฑ ๊ฒฐ๊ณผ' }),
aiLabel && h('div', { className: 'ai-label-overlay' }, AI_LABEL_TEXT),
h('button', { type: 'button', onClick: () => setLightbox(true), title: 'ํฌ๊ฒŒ ๋ณด๊ธฐ',
className: 'absolute bottom-3 right-3 w-9 h-9 rounded-lg bg-black/55 hover:bg-black/75 text-white flex items-center justify-center' }, h(Maximize2, { size: 16 })))),
h('div', { className: 'flex items-center justify-between gap-3 px-4 py-3 border-t border-[#2a2a2a]' },
h('label', { className: 'flex items-center gap-2 cursor-pointer select-none text-[12.5px] text-gray-300' },
h('button', { type: 'button', role: 'switch', 'aria-checked': aiLabel, onClick: () => setAiLabel(v => !v),
className: `relative w-9 h-5 rounded-full transition-colors ${aiLabel ? 'bg-brand-blue' : 'bg-[#3a3a3a]'}` },
h('span', { className: `absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white transition-transform ${aiLabel ? 'translate-x-4' : ''}` })),
h('span', null, "'AI ์ƒ์„ฑ ์ด๋ฏธ์ง€' ํ‘œ๊ธฐ"),
h('span', { className: 'text-gray-500' }, aiLabel ? 'ํ™”๋ฉดยท๋‹ค์šด๋กœ๋“œ์— ํฌํ•จ' : 'ํ‘œ๊ธฐ ์—†์Œ')),
h('button', { type: 'button', onClick: () => setExportOpen(true),
className: 'h-10 px-4 rounded-xl bg-brand-blue hover:bg-brand-hover text-white text-[13px] font-semibold flex items-center gap-1.5' }, h(Download, { size: 15 }), '๋‹ค์šด๋กœ๋“œ')))
: h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center text-gray-500 gap-2' },
h(Upload, { size: 28, className: 'opacity-50' }),
h('p', { className: 'text-[13.5px]' }, '์™ผ์ชฝ์—์„œ ์–ผ๊ตดยท์˜์ƒ์„ ๊ณ ๋ฅด๊ณ  ๋ฃฉ๋ถ ์ƒ์„ฑ์„ ๋ˆ„๋ฅด๋ฉด'),
h('p', { className: 'text-[13.5px]' }, 'ํ•œ ๋ฒˆ์— ๋ชจ๋ธ์ปท์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.'))),
// ํžˆ์Šคํ† ๋ฆฌ (์ด๋ฒˆ ์„ธ์…˜ / ์ง€๋‚œ ๊ธฐ๋ก)
h('div', null,
h('div', { className: 'flex items-center gap-1 mb-2.5' },
h('button', { type: 'button', onClick: () => setResultTab('session'),
className: `px-2.5 py-1 rounded-lg text-[12px] font-semibold transition-colors ${resultTab === 'session' ? 'bg-[#2f2f2f] text-white' : 'text-gray-500 hover:text-gray-300'}` },
`์ด๋ฒˆ ์„ธ์…˜ ${results.length ? `(${results.length})` : ''}`),
h('button', { type: 'button', onClick: () => setResultTab('history'),
className: `px-2.5 py-1 rounded-lg text-[12px] font-semibold transition-colors ${resultTab === 'history' ? 'bg-[#2f2f2f] text-white' : 'text-gray-500 hover:text-gray-300'}` },
'์ง€๋‚œ ๊ธฐ๋ก'),
resultTab === 'history' && h('button', { type: 'button', title: '๊ธฐ๋ก ์ƒˆ๋กœ๊ณ ์นจ', onClick: () => loadHistory(true), disabled: hist.loading,
className: 'ml-auto text-gray-500 hover:text-gray-300 disabled:opacity-50' },
h(RefreshCw, { size: 13, className: hist.loading ? 'animate-spin' : '' }))),
resultTab === 'history'
? (hist.loading && hist.items === null
? h('p', { className: 'text-[12px] text-gray-500' }, '๊ธฐ๋ก ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘โ€ฆ')
: hist.error
? h('p', { className: 'text-[12px] text-red-400' }, hist.error)
: !hist.items || hist.items.length === 0
? h('p', { className: 'text-[12px] text-gray-500' }, '์ €์žฅ๋œ ๊ธฐ๋ก ์—†์Œ')
: h('div', null,
h('div', { className: 'grid grid-cols-3 md:grid-cols-1 gap-2' },
hist.items.map(r => h('button', { key: r.id, type: 'button', onClick: () => setCurrent(r),
className: `w-full relative rounded-xl overflow-hidden border-2 ${current?.id === r.id ? 'border-brand-blue' : 'border-transparent hover:border-[#4b5563]'}` },
h('img', { src: r.thumbUrl, loading: 'lazy', className: 'w-full h-auto block bg-white' }),
h('div', { className: 'absolute bottom-0 inset-x-0 px-2 py-1 bg-black/65 text-[10.5px] text-left leading-tight' },
h('div', null, `${r.meta.face ? r.meta.face + ' ยท ' : ''}${r.meta.shot} ยท ${r.meta.angle}`),
h('div', { className: 'text-gray-300' }, r.createdAt))))),
hist.truncated && h('p', { className: 'text-[11px] text-gray-500 mt-2' }, '์ตœ๊ทผ 60๊ฑด๊นŒ์ง€ ํ‘œ์‹œ โ€” ์ „์ฒด๋Š” ํ†ต๊ณ„ ๋Œ€์‹œ๋ณด๋“œ์—์„œ')))
: results.length === 0
? h('p', { className: 'text-[12px] text-gray-500' }, '์•„์ง ์—†์Œ')
: h('div', { className: 'grid grid-cols-3 md:grid-cols-1 gap-2' },
results.map(r => h('div', { key: r.id, className: 'relative group' },
h('button', { type: 'button', onClick: () => setCurrent(r),
className: `w-full relative rounded-xl overflow-hidden border-2 ${current?.id === r.id ? 'border-brand-blue' : 'border-transparent hover:border-[#4b5563]'}` },
h('img', { src: r.imageUrl, className: 'w-full h-auto block bg-white' }),
h('div', { className: 'absolute bottom-0 inset-x-0 px-2 py-1 bg-black/65 text-[10.5px] text-left leading-tight' },
h('div', null, `${r.meta.face ? r.meta.face + ' ยท ' : ''}${r.meta.shot} ยท ${r.meta.angle}`),
h('div', { className: 'text-gray-300' }, `${r.meta.gaze} ยท ${fmtSec(r.elapsedSec)}`))),
h('div', { className: 'absolute top-1.5 right-1.5 hidden group-hover:flex gap-1' },
r.payload && h('button', { type: 'button', onClick: (e) => { e.stopPropagation(); regenFrom(r); }, title: '์ด ์„ค์ •์œผ๋กœ ๋‹ค์‹œ ์ƒ์„ฑ',
className: 'w-7 h-7 rounded-lg bg-black/60 hover:bg-brand-blue text-white flex items-center justify-center transition-colors' },
h(RefreshCw, { size: 13 })),
h('button', { type: 'button', onClick: (e) => { e.stopPropagation(); deleteResult(r); }, title: '์ด ๊ฒฐ๊ณผ ์ง€์šฐ๊ธฐ',
className: 'w-7 h-7 rounded-lg bg-black/60 hover:bg-red-500 text-white flex items-center justify-center transition-colors' },
h(X, { size: 13 })))))))),
current && h('div', { className: 'mt-5 text-[12px] text-gray-500' },
`${current.history ? `์ง€๋‚œ ๊ธฐ๋ก (${current.createdAt}) ยท ` : ''}${current.meta.age} ยท ${current.meta.shot} ยท ${current.meta.angle} ยท ${current.meta.gaze}`, current.meta.prompt ? ` ยท "${current.meta.prompt}"` : ''),
current && (current.garmentSpecs || current.finalPrompt || current.poseSpec) && h('div', { className: 'mt-3 rounded-xl border border-[#2a2a2a] bg-[#202020]' },
h('button', { type: 'button', onClick: () => setShowSpecs(v => !v), className: 'w-full flex items-center justify-between px-4 py-2.5 text-[12.5px] font-semibold text-gray-300 hover:text-white' },
h('span', null, 'ํฌ์ฆˆ ๋ถ„์„ ยท ์˜์ƒ ๋ถ„์„ ยท ์ตœ์ข… ํ”„๋กฌํ”„ํŠธ'), h('span', { className: 'text-gray-500 font-normal' }, showSpecs ? '์ ‘๊ธฐ' : 'ํŽผ์น˜๊ธฐ')),
showSpecs && h('div', { className: 'px-4 pb-4 space-y-3 animate-fadeIn' },
current.poseSpec && h('div', null,
h('div', { className: 'flex items-center justify-between mb-1' },
h('div', { className: 'text-[11px] text-gray-500' }, 'ํฌ์ฆˆ ๋ถ„์„ (๋ ˆํผ๋Ÿฐ์Šค โ†’ ๋ฌธ์žฅ, ํ”„๋กฌํ”„ํŠธ ์ตœ์šฐ์„  ์ง€์‹œ)'),
h('button', { type: 'button', onClick: () => { setPoseSpec(current.poseSpec); document.querySelector('aside')?.scrollTo({ top: 0, behavior: 'smooth' }); },
className: 'text-[11px] text-brand-blue hover:underline' }, '์ด ๋ฌธ์žฅ์„ ์ˆ˜์ •ํ•ด์„œ ๋‹ค์‹œ ์ƒ์„ฑ')),
h('pre', { className: 'text-[11.5px] text-gray-200 whitespace-pre-wrap break-words bg-[#1a1a1a] rounded-lg p-3 max-h-40 overflow-y-auto' }, current.poseSpec)),
current.garmentSpecs && h('div', null,
h('div', { className: 'text-[11px] text-gray-500 mb-1' }, 'GPT ๋น„์ „ ์˜์ƒ ๋ถ„์„ (GARMENT SPECS)'),
h('pre', { className: 'text-[11.5px] text-gray-200 whitespace-pre-wrap break-words bg-[#1a1a1a] rounded-lg p-3 max-h-48 overflow-y-auto' }, current.garmentSpecs)),
current.finalPrompt && h('div', null,
h('div', { className: 'text-[11px] text-gray-500 mb-1' }, 'GPT-image์— ์ „๋‹ฌ๋œ ์ตœ์ข… ํ”„๋กฌํ”„ํŠธ'),
h('pre', { className: 'text-[11.5px] text-gray-300 whitespace-pre-wrap break-words bg-[#1a1a1a] rounded-lg p-3 max-h-64 overflow-y-auto' }, current.finalPrompt))))));
// โ”€โ”€ Header โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
const header = h('header', { className: 'h-14 shrink-0 border-b border-[#2a2a2a] bg-[#1a1a1a] flex items-center justify-between px-5' },
h('div', { className: 'flex items-center gap-5' },
h('div', { className: 'flex items-center gap-3' },
h('div', { className: 'w-8 h-8 rounded-lg bg-brand-blue flex items-center justify-center' }, h(Sparkles, { size: 16, className: 'text-white' })),
h('div', { className: 'text-[15px] font-bold tracking-tight' }, 'CLOVIS AI ๋ฃฉ๋ถ ์ƒ์„ฑ๊ธฐ')),
user.oauth_enabled && h('div', { className: 'flex items-center gap-2 text-[12.5px] pl-5 border-l border-[#2a2a2a]' },
user.is_logged_in
? h(React.Fragment, null,
h('span', { className: 'text-gray-300' }, user.name || user.username),
h('a', { href: user.logout_url, className: 'text-gray-500 hover:text-white' }, '๋กœ๊ทธ์•„์›ƒ'))
: h('a', { href: user.login_url, className: 'px-3 py-1.5 rounded-lg bg-[#2a2a2a] hover:bg-[#333] text-gray-100' }, '๐Ÿค— Hugging Face๋กœ ๋กœ๊ทธ์ธ'))),
h('div', null,
health && !health.ok && h('span', { className: 'inline-flex items-center gap-1.5 text-[12.5px] text-amber-400' },
h('span', { className: 'w-1.5 h-1.5 rounded-full bg-amber-400' }), 'Comfy ์„ค์ • ํ•„์š”')));
const lightboxEl = lightbox && current && h('div', {
className: 'fixed inset-0 z-50 bg-black/90 flex items-center justify-center animate-fadeIn cursor-zoom-out',
onClick: () => setLightbox(false) },
h('img', { src: current.imageUrl, alt: '์ƒ์„ฑ ๊ฒฐ๊ณผ ํ™•๋Œ€', onClick: e => e.stopPropagation(),
className: 'max-w-[96vw] max-h-[96vh] object-contain bg-white cursor-default shadow-2xl' }),
aiLabel && h('div', { className: 'absolute top-4 right-16 text-[12px] text-gray-300 font-light pointer-events-none' }, AI_LABEL_TEXT),
h('button', { type: 'button', onClick: () => setLightbox(false), title: '๋‹ซ๊ธฐ (Esc)',
className: 'absolute top-4 right-4 w-10 h-10 rounded-full bg-white/10 hover:bg-white/20 text-white flex items-center justify-center' }, h(X, { size: 18 })),
h('div', { className: 'absolute bottom-4 left-1/2 -translate-x-1/2 flex gap-2', onClick: e => e.stopPropagation() },
h('button', { type: 'button', onClick: () => { setLightbox(false); setExportOpen(true); },
className: 'h-10 px-4 rounded-xl bg-brand-blue hover:bg-brand-hover text-white text-[13px] font-semibold flex items-center gap-1.5' }, h(Download, { size: 15 }), '๋‹ค์šด๋กœ๋“œ')));
const exportEl = exportOpen && current && h(ExportModal, { current, aiLabel, onClose: () => setExportOpen(false) });
return h('div', { className: 'h-screen flex flex-col bg-[#1a1a1a]' }, header,
h('div', { className: 'flex-1 flex flex-col lg:flex-row min-h-0' }, left, right), lightboxEl, exportEl);
}
ReactDOM.createRoot(document.getElementById('root')).render(h(App));
</script>
</body>
</html>