sunyoung00 commited on
Commit
0ee2f13
Β·
verified Β·
1 Parent(s): 947a2f3

Upload index (50).html

Browse files
Files changed (1) hide show
  1. index (50).html +819 -0
index (50).html ADDED
@@ -0,0 +1,819 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="ko" class="dark">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>CLOVIS AI 룩뢁 생성기</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script>
9
+ tailwind.config = { darkMode: 'class', theme: { extend: { colors: { brand: { blue: '#3B82F6', hover: '#2563EB' } } } } }
10
+ </script>
11
+ <link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin />
12
+ <link rel="stylesheet" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css" />
13
+ <style>
14
+ * { font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
15
+ body { -webkit-font-smoothing: antialiased; background: #1a1a1a; color: #f9fafb; margin: 0; overflow: hidden; }
16
+ ::-webkit-scrollbar { width: 6px; height: 6px; }
17
+ ::-webkit-scrollbar-track { background: #1a1a1a; }
18
+ ::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
19
+ ::-webkit-scrollbar-thumb:hover { background: #4b5563; }
20
+ @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
21
+ @keyframes shimmer { 0% { background-position: -600px 0; } 100% { background-position: 600px 0; } }
22
+ @keyframes pulseRing { 0% { transform: scale(0.85); opacity: .9; } 100% { transform: scale(1.6); opacity: 0; } }
23
+ .animate-fadeIn { animation: fadeIn .25s ease-out; }
24
+ .shimmer { background: linear-gradient(90deg, #232323 0%, #2c2c2c 40%, #232323 80%); background-size: 600px 100%; animation: shimmer 1.6s linear infinite; }
25
+ .pulse-ring::before { content: ''; position: absolute; inset: -6px; border-radius: 9999px; border: 2px solid #3B82F6; animation: pulseRing 1.4s ease-out infinite; }
26
+ .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; }
27
+ .drop-active { border-color: #3B82F6 !important; background: rgba(59,130,246,.08) !important; }
28
+ textarea { resize: vertical; }
29
+ </style>
30
+ <script type="importmap">
31
+ { "imports": {
32
+ "react": "https://esm.sh/react@19.1.0",
33
+ "react/": "https://esm.sh/react@19.1.0/",
34
+ "react-dom/": "https://esm.sh/react-dom@19.1.0/",
35
+ "lucide-react": "https://esm.sh/lucide-react@0.462.0?external=react"
36
+ } }
37
+ </script>
38
+ </head>
39
+ <body>
40
+ <div id="root"></div>
41
+ <script type="module">
42
+ import React, { useState, useEffect, useRef, useCallback } from 'react';
43
+ import ReactDOM from 'react-dom/client';
44
+ import { Download, X, Upload, Sparkles, RefreshCw, AlertTriangle, Clock, Check, ImagePlus, User, Maximize2, ChevronDown } from 'lucide-react';
45
+
46
+ const h = React.createElement;
47
+
48
+ // ═══════════════════════════════════════════════════════════
49
+ // Constants β€” μ›Œν¬ν”Œλ‘œμš°(SPAO.json) CustomCombo μ˜΅μ…˜κ³Ό 1:1
50
+ // ═══════════════════════════════════════════════════════════
51
+ const SHOT_OPTIONS = ['μ „μ‹ μ»·', 'μƒλ°˜μ‹ μ»·', 'ν•˜λ°˜μ‹ μ»·']; // ν”„λ ˆμž„μ€ 항상 μƒ· κ·œμΉ™μ΄ 정함 (λ ˆνΌλŸ°μŠ€λŠ” 포즈 참고용)
52
+ const ANGLE_OPTIONS = ['μ •λ©΄', '반츑면', 'μΈ‘λ©΄', 'λ‘œμš°μ•΅κΈ€', 'ν•˜μ΄μ•΅κΈ€', 'ν›„λ©΄', '레퍼런슀 따름'];
53
+ const GAZE_OPTIONS = ['카메라 μ‘μ‹œ', 'μžμ—°μŠ€λŸ¬μš΄ μ‹œμ„ ', '레퍼런슀 따름'];
54
+ const AGE_OPTIONS = ['성인', 'ν‚€μ¦ˆ'];
55
+ const DETAIL_GROUPS = [
56
+ { key: 'outer', label: 'μ•„μš°ν„°', length: 'outer_length', fit: 'outer_fit' },
57
+ { key: 'top', label: 'μƒμ˜', length: 'top_length', fit: 'top_fit' },
58
+ { key: 'bottom', label: 'ν•˜μ˜', length: 'bottom_length', fit: 'bottom_fit' },
59
+ ];
60
+ const DETAIL_OPTIONS = {
61
+ outer_length: { label: 'μ•„μš°ν„° 길이', options: ['ν—ˆλ¦¬', '골반', 'ν—ˆλ²…μ§€'], def: '골반' },
62
+ outer_fit: { label: 'μ•„μš°ν„° 핏', options: ['슬림', 'ν‘œμ€€', 'μ˜€λ²„'], def: 'ν‘œμ€€' },
63
+ top_length: { label: 'μƒμ˜ 길이', options: ['ν—ˆλ¦¬', '골반', 'ν—ˆλ²…μ§€'], def: '골반' },
64
+ top_fit: { label: 'μƒμ˜ 핏', options: ['슬림', 'ν‘œμ€€', 'μ˜€λ²„'], def: 'μ˜€λ²„' },
65
+ bottom_length: { label: 'ν•˜μ˜ 길이', options: ['ν—ˆλ²…μ§€', '무릎', '쒅아리', '발λͺ©', 'μ‹ λ°œ'], def: 'μ‹ λ°œ' },
66
+ bottom_fit: { label: 'ν•˜μ˜ 핏', options: ['슬림', 'ν‘œμ€€', 'μ˜€λ²„'], def: 'μ˜€λ²„' },
67
+ };
68
+
69
+ const ADULT_FACE_PRESETS = [
70
+ { id: 'preset_17', label: 'μ—¬μ„± 1', url: '/face_preset_17.png' },
71
+ { id: 'preset_18', label: 'μ—¬μ„± 2', url: '/face_preset_18.png' },
72
+ { id: 'preset_19', label: 'μ—¬μ„± 3', url: '/face_preset_19.png' },
73
+ ];
74
+ // CLOVIS λŠ” ν‚€μ¦ˆ 라인이 μ—†μ–΄ ν‚€μ¦ˆ 프리셋·연령 토글을 λ…ΈμΆœν•˜μ§€ μ•ŠμŒ (μ›Œν¬ν”Œλ‘œμš° age μ½€λ³΄μ—λŠ” '성인' κ³ μ • 전달)
75
+
76
+ const IMAGE_SLOTS = [
77
+ { key: 'outer', label: 'μ•„μš°ν„°', required: false },
78
+ { key: 'top', label: 'μƒμ˜', required: false },
79
+ { key: 'bottom', label: 'ν•˜μ˜', required: false, hint: 'μ›ν”ΌμŠ€λ„ μ—¬κΈ°' },
80
+ { key: 'shoes', label: 'μ‹ λ°œ', required: false },
81
+ { key: 'inner', label: 'μ΄λ„ˆμ›¨μ–΄', required: false },
82
+ { key: 'belt', label: '벨트', required: false },
83
+ { key: 'background', label: 'λ°°κ²½', required: false, hint: 'λΉ„μš°λ©΄ κΈ°λ³Έ μŠ€νŠœλ””μ˜€' },
84
+ { key: 'pose', label: '레퍼런슀 포즈', required: false, hint: '포즈 참고용 Β· κ΅¬λ„λŠ” μƒ· 선택 κΈ°μ€€' },
85
+ ];
86
+
87
+ // λ””ν…ŒμΌ μ°Έμ‘°: ν΄λ‘œμ¦ˆμ—…μ„ 생성 λͺ¨λΈμ— 직접 참쑰둜 전달 (전체 μ΅œλŒ€ 4μž₯)
88
+ // μ˜·λ§ˆλ‹€ 슬둯 2개(a/b), μŠ¬λ‘―λ³„λ‘œ μ’…λ₯˜λ₯Ό 고름 β€” μ’…λ₯˜λŠ” comfy_client.DETAIL_KIND_EN 킀와 1:1
89
+ const DETAIL_MAX = 4;
90
+ const DETAIL_SLOTS = ['a', 'b'];
91
+ // 옷 μ’…λ₯˜λ³„ λ””ν…ŒμΌ ν•­λͺ© β€” key λŠ” comfy_client.DETAIL_KIND_EN κ³Ό 1:1. short: μΉ© ν‘œμ‹œ, label: 툴팁
92
+ const K = {
93
+ texture: { key: 'texture', short: '쑰직감', label: '원단 쑰직감 (옷 전체에 반영)' },
94
+ logo: { key: 'logo', short: '둜고', label: 'λ‘œκ³ Β·ν”„λ¦°νŠΈ (메인 사진과 같은 μœ„μΉ˜)' },
95
+ neckline: { key: 'neckline', short: 'λ„₯라인', label: 'λ„₯라인·카라' },
96
+ collar: { key: 'collar', short: 'μΉ΄λΌΒ·ν›„λ“œ', label: 'μΉ΄λΌΒ·ν›„λ“œΒ·λΌνŽ ' },
97
+ sleeve: { key: 'sleeve', short: 'μ†Œλ§€', label: 'μ†Œλ§€Β·μ»€ν”„μŠ€' },
98
+ hem: { key: 'hem', short: '밑단', label: '밑단·헴 마감' },
99
+ waist: { key: 'waist', short: 'ν—ˆλ¦¬', label: 'ν—ˆλ¦¬ (μ›¨μ΄μŠ€νŠΈλ°΄λ“œΒ·λ²¨νŠΈλ£¨ν”„Β·λ“œλ‘œμŠ€νŠΈλ§)' },
100
+ pocket: { key: 'pocket', short: '포켓', label: '포켓 (ν˜•νƒœΒ·μŠ€ν‹°μΉ˜Β·ν”Œλž©)' },
101
+ closure: { key: 'closure', short: 'μ§€νΌΒ·λ²„νŠΌ', label: 'μ§€νΌΒ·λ²„νŠΌΒ·μŠ€λƒ…' },
102
+ trim: { key: 'trim', short: 'λΆ€μžμž¬', label: 'λΆ€μžμž¬ (λΌλ²¨Β·νƒ­Β·μ™€νŽœ λ“±)' },
103
+ material: { key: 'material', short: 'μ†Œμž¬', label: 'μ†Œμž¬Β·μ§ˆκ° (κ°€μ£½Β·μŠ€μ›¨μ΄λ“œΒ·λ©”μ‹œ λ“±, 전체에 반영)' },
104
+ sole: { key: 'sole', short: 'λ°‘μ°½', label: '밑창·아웃솔' },
105
+ lacing: { key: 'lacing', short: '끈', label: 'λˆΒ·μ•„μΌλ ›Β·μ„€ν¬' },
106
+ heel: { key: 'heel', short: 'λ’€μΆ•', label: 'λ’€μΆ•Β·νžνƒ­Β·λ°œλͺ©' },
107
+ buckle: { key: 'buckle', short: '버클', label: '버클' },
108
+ edge: { key: 'edge', short: 'μŠ€ν‹°μΉ˜', label: 'μŠ€ν‹°μΉ˜Β·μ—£μ§€Β·λ²¨νŠΈν™€' },
109
+ };
110
+ const DETAIL_KINDS_BY_GARMENT = {
111
+ outer: [K.texture, K.logo, K.collar, K.sleeve, K.hem, K.pocket, K.closure, K.trim],
112
+ top: [K.texture, K.logo, K.neckline, K.sleeve, K.hem, K.pocket, K.trim],
113
+ bottom: [K.texture, K.logo, K.waist, K.hem, K.pocket, K.closure, K.trim],
114
+ shoes: [K.material, K.logo, K.sole, K.lacing, K.heel, K.trim],
115
+ inner: [K.texture, K.logo, K.neckline, K.sleeve, K.hem],
116
+ belt: [K.material, K.buckle, K.logo, K.edge],
117
+ };
118
+ // 슬둯 κΈ°λ³Έκ°’: μ™Όμͺ½ = μ†Œμž¬/쑰직감, 였λ₯Έμͺ½ = 둜고 (λ²¨νŠΈλŠ” 버클)
119
+ const defaultKind = (g, slot) => {
120
+ const list = DETAIL_KINDS_BY_GARMENT[g] || [];
121
+ if (slot === 'a') return list[0]?.key;
122
+ return g === 'belt' ? 'buckle' : (list.find(k => k.key === 'logo') || list[1] || list[0])?.key;
123
+ };
124
+ const DETAIL_GARMENTS = [
125
+ { key: 'outer', label: 'μ•„μš°ν„°' }, { key: 'top', label: 'μƒμ˜' }, { key: 'bottom', label: 'ν•˜μ˜' },
126
+ { key: 'shoes', label: 'μ‹ λ°œ' }, { key: 'inner', label: 'μ΄λ„ˆμ›¨μ–΄' }, { key: 'belt', label: '벨트' },
127
+ ];
128
+
129
+ // AI ν‘œκΈ° β€” μ €μž₯ μ‹œ μΊ”λ²„μŠ€μ— μ‚½μž… (κΈ°μ‘΄ μ•±κ³Ό 동일 규격)
130
+ const AI_LABEL_TEXT = 'AI 생성 이미지';
131
+ const AI_LABEL_FONT_PT = 28;
132
+ const AI_LABEL_MARGIN_PT = 12 * (28 / 10);
133
+
134
+ // ═══════════════════════════════════════════════════════════
135
+ // Helpers
136
+ // ═══════════════════════════════════════════════════════════
137
+ const fileToDataUrl = (file, maxSide = 1536) => new Promise((resolve, reject) => {
138
+ const reader = new FileReader();
139
+ reader.onerror = reject;
140
+ reader.onload = () => {
141
+ const img = new Image();
142
+ img.onerror = reject;
143
+ img.onload = () => {
144
+ const scale = Math.min(1, maxSide / Math.max(img.width, img.height));
145
+ const w = Math.round(img.width * scale), hgt = Math.round(img.height * scale);
146
+ const canvas = document.createElement('canvas');
147
+ canvas.width = w; canvas.height = hgt;
148
+ const ctx = canvas.getContext('2d');
149
+ const keepPng = /png|webp/i.test(file.type);
150
+ if (!keepPng) { ctx.fillStyle = '#fff'; ctx.fillRect(0, 0, w, hgt); }
151
+ ctx.drawImage(img, 0, 0, w, hgt);
152
+ resolve(keepPng ? canvas.toDataURL('image/png') : canvas.toDataURL('image/jpeg', 0.92));
153
+ };
154
+ img.src = reader.result;
155
+ };
156
+ reader.readAsDataURL(file);
157
+ });
158
+
159
+ const drawAiDisclosureOnCanvas = (ctx, width, height) => {
160
+ ctx.save();
161
+ ctx.textAlign = 'right'; ctx.textBaseline = 'top'; ctx.fillStyle = '#3c3c3c';
162
+ ctx.font = `300 ${AI_LABEL_FONT_PT}pt 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif`;
163
+ const ptToPx = 96 / 72;
164
+ const m = Math.max(AI_LABEL_MARGIN_PT * ptToPx, Math.min(width, height) * 0.028, 18);
165
+ ctx.fillText(AI_LABEL_TEXT, width - m, m);
166
+ ctx.restore();
167
+ };
168
+
169
+ async function downloadWithLabel(imageUrl, filename, withLabel = true) {
170
+ const img = new Image();
171
+ await new Promise((res, rej) => { img.onload = res; img.onerror = rej; img.src = imageUrl; });
172
+ const canvas = document.createElement('canvas');
173
+ canvas.width = img.naturalWidth; canvas.height = img.naturalHeight;
174
+ const ctx = canvas.getContext('2d');
175
+ ctx.drawImage(img, 0, 0);
176
+ if (withLabel) drawAiDisclosureOnCanvas(ctx, canvas.width, canvas.height);
177
+ const a = document.createElement('a');
178
+ a.href = canvas.toDataURL('image/png'); a.download = filename; a.click();
179
+ }
180
+
181
+ const sleep = (ms) => new Promise(r => setTimeout(r, ms));
182
+
183
+ // ═══════════════════════════════════════════════════════════
184
+ // 채널 μ‚¬μ΄μ¦ˆ 내보내기 β€” 생성은 3:4 원본 ν•œ 번, 채널 κ·œκ²©μ€ μ €μž₯ μ‹œ λ³€ν™˜
185
+ // 여백은 AI μž¬μƒμ„±μ΄ μ•„λ‹ˆλΌ 원본 κ°€μž₯자리 픽셀을 쀄(ν–‰) λ‹¨μœ„λ‘œ μ—°μž₯ν•΄ 채움 (원본 ν”½μ…€ 무손싀)
186
+ // ═══════════════════════════════════════════════════════════
187
+ const EXPORT_PRESETS = [
188
+ { key: 'original', label: '원본', desc: '1536Γ—2048', w: null, h: null, suffix: '' },
189
+ { key: 'mall', label: 'μ΄λžœλ“œλͺ°Β·λ„€μ΄λ²„·사방넷', desc: '1400Γ—1400', w: 1400, h: 1400, suffix: '_1400x1400' },
190
+ { key: 'zigzag', label: 'μ§€κ·Έμž¬κ·Έ', desc: '1080Γ—1296', w: 1080, h: 1296, suffix: '_1080x1296' },
191
+ ];
192
+
193
+ // λŒ€μƒ μΊ”λ²„μŠ€μ— (쀌·팬 λ°˜μ˜ν•΄) 원본을 그리고, λ‚¨λŠ” 쒌우 여백은 κ°€μž₯자리 1px 열을 늘렀 μ±„μš΄λ‹€.
194
+ function renderChannelCanvas(img, W, H, zoom, offX, offY, withLabel) {
195
+ const sw = img.naturalWidth, sh = img.naturalHeight;
196
+ const s = Math.min(W / sw, H / sh) * zoom;
197
+ const dw = sw * s, dh = sh * s;
198
+ // 팬 ν΄λž¨ν”„: 컀버 μ•ˆ λ˜λŠ” 좕은 쀑앙 κ³ μ •, μ»€λ²„λ˜λŠ” 좕은 λΉˆν‹ˆμ΄ μ•ˆ μƒκΈ°λŠ” λ²”μœ„λ‘œ μ œν•œ
199
+ let dx = dw >= W ? Math.min(0, Math.max(W - dw, (W - dw) / 2 + offX)) : (W - dw) / 2;
200
+ let dy = dh >= H ? Math.min(0, Math.max(H - dh, (H - dh) / 2 + offY)) : (H - dh) / 2;
201
+ const canvas = document.createElement('canvas');
202
+ canvas.width = W; canvas.height = H;
203
+ const ctx = canvas.getContext('2d');
204
+ ctx.imageSmoothingQuality = 'high';
205
+ ctx.fillStyle = '#ffffff'; ctx.fillRect(0, 0, W, H);
206
+ // λ³΄μ΄λŠ” 원본 μ„Έλ‘œ ꡬ간 (μ—¬λ°± μ€„μ˜ 색을 같은 ν–‰μ—μ„œ μž‡κΈ° μœ„ν•΄)
207
+ const sy0 = Math.max(0, -dy / s), syh = Math.min(sh - sy0, H / s);
208
+ const padL = Math.ceil(Math.max(0, dx)), padR = Math.ceil(Math.max(0, W - (dx + dw)));
209
+ if (padL > 0) ctx.drawImage(img, 0, sy0, 1, syh, 0, 0, padL, H);
210
+ if (padR > 0) ctx.drawImage(img, sw - 1, sy0, 1, syh, W - padR, 0, padR, H);
211
+ ctx.drawImage(img, dx, dy, dw, dh);
212
+ if (withLabel) drawAiDisclosureOnCanvas(ctx, W, H);
213
+ return canvas;
214
+ }
215
+
216
+ function ExportModal({ current, aiLabel, onClose }) {
217
+ const [preset, setPreset] = useState('mall');
218
+ const [zoom, setZoom] = useState(1);
219
+ const [off, setOff] = useState({ x: 0, y: 0 });
220
+ const imgRef = useRef(null);
221
+ const [ready, setReady] = useState(false);
222
+ const canvasRef = useRef(null);
223
+ const dragRef = useRef(null);
224
+ const p = EXPORT_PRESETS.find(x => x.key === preset);
225
+
226
+ useEffect(() => { // 원본 λ‘œλ“œ (1회)
227
+ const img = new Image();
228
+ img.onload = () => { imgRef.current = img; setReady(true); };
229
+ img.src = current.imageUrl;
230
+ }, [current.imageUrl]);
231
+
232
+ useEffect(() => { setZoom(1); setOff({ x: 0, y: 0 }); }, [preset]);
233
+
234
+ useEffect(() => { // 미리보기 λ Œλ”
235
+ const img = imgRef.current, cv = canvasRef.current;
236
+ if (!ready || !img || !cv || !p.w) return;
237
+ const out = renderChannelCanvas(img, p.w, p.h, zoom, off.x, off.y, aiLabel);
238
+ cv.width = out.width; cv.height = out.height;
239
+ cv.getContext('2d').drawImage(out, 0, 0);
240
+ }, [ready, preset, zoom, off, aiLabel]);
241
+
242
+ const startDrag = (e) => {
243
+ if (!p.w) return;
244
+ e.preventDefault();
245
+ dragRef.current = { x: e.clientX, y: e.clientY, ox: off.x, oy: off.y };
246
+ const scale = p.h / (canvasRef.current?.getBoundingClientRect().height || p.h);
247
+ const move = (ev) => {
248
+ const d = dragRef.current; if (!d) return;
249
+ setOff({ x: d.ox + (ev.clientX - d.x) * scale, y: d.oy + (ev.clientY - d.y) * scale });
250
+ };
251
+ const up = () => { dragRef.current = null; window.removeEventListener('pointermove', move); window.removeEventListener('pointerup', up); };
252
+ window.addEventListener('pointermove', move); window.addEventListener('pointerup', up);
253
+ };
254
+
255
+ const save = () => {
256
+ const base = `clovis_${current.meta.shot}_${current.meta.angle}_${current.id}`;
257
+ if (!p.w) { downloadWithLabel(current.imageUrl, `${base}.png`, aiLabel); return; }
258
+ const out = renderChannelCanvas(imgRef.current, p.w, p.h, zoom, off.x, off.y, aiLabel);
259
+ const a = document.createElement('a');
260
+ a.href = out.toDataURL('image/png'); a.download = `${base}${p.suffix}.png`; a.click();
261
+ };
262
+
263
+ return h('div', { className: 'fixed inset-0 z-50 bg-black/80 flex items-center justify-center animate-fadeIn', onClick: onClose },
264
+ 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() },
265
+ h('div', { className: 'flex items-center justify-between' },
266
+ h('h3', { className: 'text-[15px] font-semibold' }, 'λ‹€μš΄λ‘œλ“œ β€” 채널 μ‚¬μ΄μ¦ˆ'),
267
+ h('button', { type: 'button', onClick: onClose, className: 'text-gray-500 hover:text-white' }, h(X, { size: 18 }))),
268
+ // 채널 선택
269
+ h('div', { className: 'grid grid-cols-3 gap-2' }, EXPORT_PRESETS.map(x =>
270
+ h('button', { key: x.key, type: 'button', onClick: () => setPreset(x.key),
271
+ 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]'}` },
272
+ h('div', { className: `text-[12.5px] font-semibold leading-tight ${preset === x.key ? 'text-white' : 'text-gray-300'}` }, x.label),
273
+ h('div', { className: 'text-[11px] text-gray-500 mt-0.5' }, x.desc)))),
274
+ // 미리보기
275
+ p.w
276
+ ? h('div', { className: 'flex flex-col items-center gap-3' },
277
+ h('div', { className: 'relative' },
278
+ h('canvas', { ref: canvasRef, onPointerDown: startDrag,
279
+ 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' }),
280
+ 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' }, 'λ“œλž˜κ·Έλ‘œ μœ„μΉ˜ 쑰절')),
281
+ h('div', { className: 'w-full max-w-[420px] flex items-center gap-3' },
282
+ h('span', { className: 'text-[11.5px] text-gray-500 shrink-0' }, 'λͺ¨λΈ 크기'),
283
+ h('input', { type: 'range', min: 100, max: 180, value: Math.round(zoom * 100),
284
+ onChange: e => setZoom(e.target.value / 100), className: 'flex-1 accent-[#3B82F6]' }),
285
+ h('span', { className: 'text-[11.5px] text-gray-400 w-10 text-right font-mono' }, `${Math.round(zoom * 100)}%`),
286
+ h('button', { type: 'button', onClick: () => { setZoom(1); setOff({ x: 0, y: 0 }); },
287
+ className: 'text-[11.5px] text-gray-500 hover:text-gray-300 shrink-0' }, 'μ΄ˆκΈ°ν™”')),
288
+ h('p', { className: 'text-[11.5px] text-gray-500 text-center leading-relaxed m-0' },
289
+ '100% = 전체가 λ‹€ λ“€μ–΄κ°€λŠ” μƒνƒœ (μ’Œμš°λŠ” λ°°κ²½ μ—°μž₯). μŠ¬λΌμ΄λ”λ₯Ό 올리면 μœ„μ•„λž˜ μ—¬λ°±λΆ€ν„° 잘리며 λͺ¨λΈμ΄ μ»€μ§‘λ‹ˆλ‹€.'))
290
+ : h('p', { className: 'text-[12.5px] text-gray-400 text-center py-6 m-0' }, 'μƒμ„±λœ 원본(1536Γ—2048)을 κ·ΈλŒ€λ‘œ μ €μž₯ν•©λ‹ˆλ‹€.'),
291
+ // μ €μž₯
292
+ h('div', { className: 'flex items-center justify-between gap-3' },
293
+ h('span', { className: 'text-[11.5px] text-gray-500' }, aiLabel ? "'AI 생성 이미지' ν‘œκΈ° 포함" : 'AI ν‘œκΈ° μ—†μŒ'),
294
+ h('button', { type: 'button', onClick: save,
295
+ 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' },
296
+ h(Download, { size: 15 }), p.w ? `${p.desc} μ €μž₯` : '원본 μ €μž₯'))));
297
+ }
298
+
299
+ // λΉ„λ‘œκ·ΈμΈ μ‚¬μš©μžλ„ μž‘μ—…μ„ λ‹€μ‹œ 뢈러올 수 μžˆλ„λ‘ λΈŒλΌμš°μ €λ³„ IDλ₯Ό 보관 (둜그인 μ‹œμ—” μ„œλ²„κ°€ 계정λͺ…μœΌλ‘œ 묢음)
300
+ const CLIENT_ID = (() => {
301
+ try {
302
+ let id = localStorage.getItem('clovis_client_id');
303
+ if (!id) { id = crypto.randomUUID(); localStorage.setItem('clovis_client_id', id); }
304
+ return id;
305
+ } catch { return 'c-' + Math.random().toString(36).slice(2); }
306
+ })();
307
+ const apiHeaders = (json = false) => ({ 'X-Client-Id': CLIENT_ID, ...(json ? { 'Content-Type': 'application/json' } : {}) });
308
+
309
+ // 제좜 β†’ jobId β†’ 폴링. κΈ΄ HTTP 연결을 작고 μžˆμ§€ μ•ŠμœΌλ―€λ‘œ Space ν”„λ‘μ‹œ νƒ€μž„μ•„μ›ƒκ³Ό 무관.
310
+ async function submitToComfy(payload) {
311
+ const res = await fetch('/api/comfy/generate', { method: 'POST', headers: apiHeaders(true), body: JSON.stringify(payload) });
312
+ if (!res.ok) { const e = await res.json().catch(() => ({})); throw new Error(e.detail || `HTTP ${res.status}`); }
313
+ return (await res.json()).jobId;
314
+ }
315
+ async function pollComfyJob(jobId, onProgress) {
316
+ let misses = 0;
317
+ while (true) {
318
+ await sleep(3000);
319
+ let r;
320
+ try { r = await fetch(`/api/comfy/jobs/${jobId}`, { headers: apiHeaders() }); } catch { if (++misses > 10) throw new Error('μ„œλ²„ 응닡이 μ—†μŠ΅λ‹ˆλ‹€.'); continue; }
321
+ if (r.status === 404) throw new Error('μž‘μ—… 정보λ₯Ό μžƒμ–΄λ²„λ ΈμŠ΅λ‹ˆλ‹€ (μ„œλ²„ μž¬μ‹œμž‘). λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”.');
322
+ if (!r.ok) { if (++misses > 10) throw new Error(`HTTP ${r.status}`); continue; }
323
+ misses = 0;
324
+ const j = await r.json();
325
+ onProgress?.(j);
326
+ if (j.status === 'done') return j;
327
+ if (j.status === 'cancelled') return null; // μ‚¬μš©μž μ·¨μ†Œ β€” 쑰용히 μ’…λ£Œ
328
+ if (j.status === 'error') throw new Error(j.error || '생성 μ‹€νŒ¨');
329
+ }
330
+ }
331
+
332
+ const fmtSec = (s) => { s = Math.round(s || 0); return s >= 60 ? `${Math.floor(s / 60)}λΆ„ ${s % 60}초` : `${s}초`; };
333
+
334
+ // ═══════════════════════════════════════════════════════════
335
+ // UI atoms
336
+ // ═══════════════════════════════════════════════════════════
337
+ const SectionTitle = ({ children, right }) => h('div', { className: 'flex items-center justify-between mb-2.5' },
338
+ h('h3', { className: 'text-[13px] font-semibold text-gray-200 tracking-tight' }, children), right || null);
339
+
340
+ const Segmented = ({ options, value, onChange, cols }) => h('div', {
341
+ className: `grid gap-1.5`, style: { gridTemplateColumns: `repeat(${cols || options.length}, minmax(0, 1fr))` } },
342
+ options.map(o => h('button', {
343
+ key: o, type: 'button', onClick: () => onChange(o),
344
+ className: `px-2 py-2 rounded-lg text-[12.5px] font-medium border transition-colors ${value === o
345
+ ? 'bg-brand-blue border-brand-blue text-white'
346
+ : 'bg-[#242424] border-[#333] text-gray-300 hover:border-[#4b5563] hover:text-white'}`
347
+ }, o)));
348
+
349
+ const UploadTile = ({ slot, value, onChange, disabled }) => {
350
+ const inputRef = useRef(null);
351
+ const [drag, setDrag] = useState(false);
352
+ const handleFiles = async (files) => {
353
+ const f = files?.[0]; if (!f || !f.type.startsWith('image/')) return;
354
+ onChange(await fileToDataUrl(f), f.name);
355
+ };
356
+ return h('div', {
357
+ className: `relative rounded-xl border overflow-hidden group ${drag ? 'drop-active' : ''} ${value ? 'border-[#3a3a3a]' : 'border-dashed border-[#3a3a3a] bg-[#212121] hover:border-[#4b5563]'}`,
358
+ style: { aspectRatio: '3 / 4' },
359
+ onDragOver: e => { e.preventDefault(); setDrag(true); }, onDragLeave: () => setDrag(false),
360
+ onDrop: e => { e.preventDefault(); setDrag(false); if (!disabled) handleFiles(e.dataTransfer.files); },
361
+ onClick: () => !disabled && !value && inputRef.current?.click(),
362
+ },
363
+ h('input', { ref: inputRef, type: 'file', accept: 'image/*', className: 'hidden', onChange: e => { handleFiles(e.target.files); e.target.value = ''; } }),
364
+ value
365
+ ? h(React.Fragment, null,
366
+ h('img', { src: value, className: 'w-full h-full object-cover bg-white', alt: slot.label }),
367
+ !disabled && h('button', { type: 'button', onClick: e => { e.stopPropagation(); onChange(null, null); },
368
+ 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 })),
369
+ 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))
370
+ : h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center gap-1 text-gray-500 cursor-pointer' },
371
+ h(ImagePlus, { size: 18 }),
372
+ h('span', { className: 'text-[11.5px] text-gray-300' }, slot.label, slot.required && h('span', { className: 'text-brand-blue ml-0.5' }, '*')),
373
+ slot.hint && h('span', { className: 'text-[10px] text-gray-500 px-2 text-center leading-tight' }, slot.hint))
374
+ );
375
+ };
376
+
377
+ const DetailTile = ({ value, onChange, disabled }) => {
378
+ const inputRef = useRef(null);
379
+ const handleFiles = async (files) => {
380
+ const f = files?.[0]; if (!f || !f.type.startsWith('image/')) return;
381
+ onChange(await fileToDataUrl(f, 1024), f.name);
382
+ };
383
+ return h('div', {
384
+ 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]' : ''}`,
385
+ style: { aspectRatio: '1 / 1' },
386
+ onDragOver: e => e.preventDefault(), onDrop: e => { e.preventDefault(); if (!disabled) handleFiles(e.dataTransfer.files); },
387
+ onClick: () => !disabled && !value && inputRef.current?.click(),
388
+ },
389
+ h('input', { ref: inputRef, type: 'file', accept: 'image/*', className: 'hidden', onChange: e => { handleFiles(e.target.files); e.target.value = ''; } }),
390
+ value
391
+ ? h(React.Fragment, null,
392
+ h('img', { src: value, className: 'w-full h-full object-cover bg-white' }),
393
+ !disabled && h('button', { type: 'button', onClick: e => { e.stopPropagation(); onChange(null, null); },
394
+ 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 })))
395
+ : h('div', { className: 'absolute inset-0 flex items-center justify-center text-gray-600 cursor-pointer' }, h(ImagePlus, { size: 14 })));
396
+ };
397
+
398
+ const FaceTile = ({ preset, selected, onClick }) => h('button', {
399
+ type: 'button', onClick, title: preset.label,
400
+ className: `relative rounded-xl overflow-hidden border-2 transition-colors ${selected ? 'border-brand-blue' : 'border-transparent hover:border-[#4b5563]'}`,
401
+ style: { aspectRatio: '1 / 1' } },
402
+ h('img', { src: preset.url, className: 'w-full h-full object-cover', alt: preset.label }),
403
+ 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' })),
404
+ 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));
405
+
406
+ // ═══════════════════════════════════════════════════════════
407
+ // App
408
+ // ═══════════════════════════════════════════════════════════
409
+ function App() {
410
+ const [user, setUser] = useState({ username: 'anonymous', is_logged_in: false, oauth_enabled: false });
411
+ const [health, setHealth] = useState(null);
412
+
413
+ const age = '성인'; // CLOVIS: 성인 κ³ μ •
414
+ const [facePreset, setFacePreset] = useState('preset_17');
415
+ const [detailKinds, setDetailKinds] = useState({}); // 'outer:a' β†’ kind key
416
+ const [genCount, setGenCount] = useState(1); // ν•œ λ²ˆμ— 생성할 맀수
417
+ const [faceUpload, setFaceUpload] = useState(null);
418
+ const [shot, setShot] = useState('μ „μ‹ μ»·');
419
+ const [angle, setAngle] = useState('반츑면');
420
+ const [gaze, setGaze] = useState('μžμ—°μŠ€λŸ¬μš΄ μ‹œμ„ ');
421
+ const [prompt, setPrompt] = useState('');
422
+ const [details, setDetails] = useState(Object.fromEntries(Object.entries(DETAIL_OPTIONS).map(([k, v]) => [k, v.def])));
423
+ const [detailTab, setDetailTab] = useState('top');
424
+ const [images, setImages] = useState({});
425
+ const [imageNames, setImageNames] = useState({}); // μŠ¬λ‘―λ³„ 원본 파일λͺ… (Dataset λ‘œκ·ΈΒ·μŠ€νƒ€μΌμ½”λ“œ μ§‘κ³„μš©)
426
+ const [faceUploadName, setFaceUploadName] = useState(null);
427
+ const [poseSpec, setPoseSpec] = useState(''); // 포즈 μ§€μ‹œ λ¬Έμž₯ (λΉ„μš°λ©΄ GPT 비전이 λ ˆνΌλŸ°μŠ€μ—μ„œ μžλ™ μΆ”μΆœ)
428
+
429
+ const [jobs, setJobs] = useState([]); // μ§„ν–‰ 쀑/μ‹€νŒ¨ μž‘μ—… [{id, jobId, meta, stageLabel, startedAt, error}]
430
+ const [tick, setTick] = useState(0); // κ²½κ³Όμ‹œκ°„ ν‘œμ‹œμš© 1초 타이머
431
+ const [results, setResults] = useState([]); // [{id, imageUrl, meta, elapsedSec}]
432
+ const [current, setCurrent] = useState(null);
433
+ const [error, setError] = useState(null);
434
+ const [aiLabel, setAiLabel] = useState(true);
435
+ const [lightbox, setLightbox] = useState(false); // κ²°κ³Ό 이미지 ν™•λŒ€ 보기
436
+ const [exportOpen, setExportOpen] = useState(false); // 채널 μ‚¬μ΄μ¦ˆ λ‹€μš΄λ‘œλ“œ λͺ¨λ‹¬
437
+ const [showSpecs, setShowSpecs] = useState(false); // μ˜μƒ 뢄석 κ²°κ³Ό / μ΅œμ’… ν”„λ‘¬ν”„νŠΈ 펼치기
438
+ useEffect(() => {
439
+ if (!lightbox) return;
440
+ const onKey = (e) => { if (e.key === 'Escape') setLightbox(false); };
441
+ window.addEventListener('keydown', onKey);
442
+ return () => window.removeEventListener('keydown', onKey);
443
+ }, [lightbox]);
444
+ const faceFileRef = useRef(null);
445
+
446
+ useEffect(() => {
447
+ fetch('/api/whoami').then(r => r.ok ? r.json() : null).then(d => d && setUser(d)).catch(() => {});
448
+ fetch('/api/comfy/health').then(r => r.ok ? r.json() : { ok: false, error: 'λΈŒλ¦¬μ§€ λΌμš°νŠΈκ°€ μ—†μŠ΅λ‹ˆλ‹€' }).then(setHealth).catch(() => setHealth({ ok: false, error: 'μƒνƒœ 확인 μ‹€νŒ¨' }));
449
+ }, []);
450
+
451
+ const activeJobs = jobs.filter(j => !j.error);
452
+ useEffect(() => {
453
+ if (activeJobs.length === 0) return;
454
+ const id = setInterval(() => setTick(t => t + 1), 1000);
455
+ return () => clearInterval(id);
456
+ }, [activeJobs.length]);
457
+
458
+ const presets = ADULT_FACE_PRESETS;
459
+ const setImg = (key, v, name) => {
460
+ setImages(prev => ({ ...prev, [key]: v })); setImageNames(prev => ({ ...prev, [key]: v ? (name || null) : null }));
461
+ if (key === 'pose' && !v) { if (angle === '레퍼런슀 따름') setAngle('반츑면'); if (gaze === '레퍼런슀 따름') setGaze('μžμ—°μŠ€λŸ¬μš΄ μ‹œμ„ '); }
462
+ };
463
+
464
+ const kindOf = (g, slot) => { // μ €μž₯된 값이 κ·Έ 옷 μ’…λ₯˜μ— μ—†μœΌλ©΄ κΈ°λ³Έκ°’μœΌλ‘œ
465
+ const list = DETAIL_KINDS_BY_GARMENT[g] || [];
466
+ const v = detailKinds[`${g}:${slot}`];
467
+ return list.some(k => k.key === v) ? v : defaultKind(g, slot);
468
+ };
469
+ 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}`] })))
470
+ .filter(x => x.image && images[x.garment]);
471
+ const detailCount = detailList.length;
472
+ const missing = [];
473
+ if (!images.outer && !images.top && !images.bottom) missing.push('μ˜μƒ 1개 이상 (μ•„μš°ν„°Β·μƒμ˜Β·ν•˜μ˜)');
474
+ const canGenerate = missing.length === 0 && (faceUpload || facePreset) && health?.ok;
475
+
476
+ // ν•˜λ‚˜μ˜ payload 둜 μž‘μ—… 1건 μ‹œμž‘. payload λŠ” 결과에 ν•¨κ»˜ λ³΄κ΄€λ˜μ–΄ "이 μ„€μ •μœΌλ‘œ λ‹€μ‹œ 생성"에 쓰인닀.
477
+ const startJob = async (payload, meta) => {
478
+ const id = Date.now().toString(36) + Math.random().toString(36).slice(2, 5);
479
+ setJobs(prev => [...prev, { id, meta, payload, stageLabel: 'μš”μ²­ 전솑 쀑', startedAt: Date.now() }]);
480
+ const patch = (p) => setJobs(prev => prev.map(j => j.id === id ? { ...j, ...p } : j));
481
+ let jobId;
482
+ try {
483
+ jobId = await submitToComfy(payload);
484
+ } catch (e) {
485
+ patch({ error: e.message }); return;
486
+ }
487
+ patch({ jobId, stageLabel: 'λŒ€κΈ° 쀑' });
488
+ await trackJob(id, jobId, meta, patch, payload);
489
+ };
490
+
491
+ const buildPayload = () => {
492
+ const meta = { shot, angle, gaze, age, prompt, face: faceUpload ? 'μ—…λ‘œλ“œ' : (presets.find(p => p.id === facePreset)?.label || facePreset) };
493
+ const mainImages = Object.fromEntries(Object.entries(images).filter(([k, v]) => v && !k.startsWith('detail:')));
494
+ return { face: faceUpload || facePreset, faceFilename: faceUpload ? faceUploadName : null, images: mainImages, imageFilenames: imageNames,
495
+ details: detailList.slice(0, DETAIL_MAX).map(x => ({ garment: x.garment, kind: x.kind, image: x.image, filename: x.filename || null })),
496
+ poseSpec: (images.pose || poseSpec.trim()) ? poseSpec.trim() : '',
497
+ options: { shot, angle, gaze, age, ...details }, prompt, meta };
498
+ };
499
+
500
+ const handleGenerate = () => {
501
+ if (user.oauth_enabled && !user.is_logged_in) { alert("둜그인이 ν•„μš”ν•©λ‹ˆλ‹€. 우츑 μƒλ‹¨μ˜ 'Hugging Face둜 둜그인' λ²„νŠΌμ„ λˆŒλŸ¬μ£Όμ„Έμš”."); return; }
502
+ if (!canGenerate) return;
503
+ setError(null);
504
+ const payload = buildPayload();
505
+ for (let i = 0; i < genCount; i++) startJob(payload, payload.meta); // 같은 payload 객체 곡유 (λ©”λͺ¨λ¦¬ μ ˆμ•½)
506
+ };
507
+
508
+ // μ„Έμ…˜ κ²°κ³Ό μ‚­μ œ: ν™”λ©΄μ—μ„œ 제거 + μ„œλ²„ 보관뢄도 μ‚­μ œν•΄ μƒˆλ‘œκ³ μΉ¨ 볡ꡬλ₯Ό λ§‰μŒ
509
+ const deleteResult = async (r) => {
510
+ if (!confirm('이 κ²°κ³Όλ₯Ό μ§€μšΈκΉŒμš”? 되돌릴 수 μ—†μ–΄μš”.')) return;
511
+ setResults(prev => {
512
+ const next = prev.filter(x => x.id !== r.id);
513
+ setCurrent(cur => (cur?.id === r.id ? (next[0] || null) : cur));
514
+ return next;
515
+ });
516
+ try { if (r.jobId) await fetch(`/api/comfy/jobs/${r.jobId}`, { method: 'DELETE', headers: apiHeaders() }); } catch {}
517
+ };
518
+
519
+ // μ„Έμ…˜ 결과에 λ³΄κ΄€λœ payload 둜 동일 쑰건 μž¬μƒμ„± (ν˜„μž¬ 폼 μƒνƒœλŠ” κ±΄λ“œλ¦¬μ§€ μ•ŠμŒ)
520
+ const regenFrom = (r) => {
521
+ if (user.oauth_enabled && !user.is_logged_in) { alert("둜그인이 ν•„μš”ν•©λ‹ˆλ‹€."); return; }
522
+ if (!r?.payload) return;
523
+ startJob(r.payload, r.meta);
524
+ };
525
+
526
+ // μ„œλ²„ μž‘μ—…μ„ μ™„λ£ŒκΉŒμ§€ 따라가며 κ²°κ³Ό/μ—λŸ¬λ₯Ό 반영 (μƒˆ μš”μ²­κ³Ό μƒˆλ‘œκ³ μΉ¨ 볡ꡬ λ‘˜ λ‹€ μ‚¬μš©)
527
+ const trackJob = async (id, jobId, meta, patch, payload = null) => {
528
+ try {
529
+ const j = await pollComfyJob(jobId, (st) => patch({ stageLabel: st.stageLabel, execStartedAt: st.execStartedAt || null }));
530
+ if (!j) { setJobs(prev => prev.filter(x => x.id !== id)); return; } // μ·¨μ†Œλ¨
531
+ 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 };
532
+ setResults(prev => prev.some(r => r.id === id) ? prev : [item, ...prev]);
533
+ setCurrent(prev => prev || item);
534
+ setJobs(prev => prev.filter(x => x.id !== id));
535
+ } catch (e) {
536
+ patch({ error: e.message });
537
+ }
538
+ };
539
+ const dismissJob = (id) => setJobs(prev => prev.filter(j => j.id !== id));
540
+ const cancelJob = async (job) => { // μ§„ν–‰ 쀑 μž‘μ—… μ·¨μ†Œ: μ„œλ²„μ— μš”μ²­ ν›„ μΉ΄λ“œ 제거 (폴링도 cancelled λ₯Ό 보고 멈좀)
541
+ setJobs(prev => prev.map(x => x.id === job.id ? { ...x, cancelling: true, stageLabel: 'μ·¨μ†Œ 쀑' } : x));
542
+ try { if (job.jobId) await fetch(`/api/comfy/jobs/${job.jobId}/cancel`, { method: 'POST', headers: apiHeaders() }); } catch {}
543
+ setJobs(prev => prev.filter(x => x.id !== job.id));
544
+ };
545
+
546
+ // μƒˆλ‘œκ³ μΉ¨/μž¬μ ‘μ† μ‹œ μ„œλ²„μ— 남아 μžˆλŠ” λ‚΄ μž‘μ—… 볡ꡬ
547
+ useEffect(() => {
548
+ (async () => {
549
+ try {
550
+ const r = await fetch('/api/comfy/jobs', { headers: apiHeaders() });
551
+ if (!r.ok) return;
552
+ const { jobs: saved } = await r.json();
553
+ const done = saved.filter(j => j.status === 'done' && j.imageUrl)
554
+ .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 }))
555
+ .sort((a, b) => b.createdAt - a.createdAt);
556
+ if (done.length) { setResults(done); setCurrent(prev => prev || done[0]); }
557
+ const pending = saved.filter(j => j.status !== 'done' && j.status !== 'cancelled');
558
+ if (pending.length) {
559
+ 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 })));
560
+ for (const j of pending.filter(x => x.status === 'running')) {
561
+ const patch = (p) => setJobs(prev => prev.map(x => x.id === j.id ? { ...x, ...p } : x));
562
+ trackJob(j.id, j.id, j.meta || {}, patch);
563
+ }
564
+ }
565
+ } catch {}
566
+ })();
567
+ }, []);
568
+
569
+ // ── Left: settings ────────────────────────────────────────
570
+ 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]' },
571
+ h('div', { className: 'p-5 space-y-6' },
572
+
573
+ h('section', null,
574
+ h(SectionTitle, null, 'μ–Όκ΅΄'),
575
+ h('div', { className: 'grid grid-cols-4 gap-2' },
576
+ presets.map(p => h(FaceTile, { key: p.id, preset: p, selected: !faceUpload && facePreset === p.id, onClick: () => { setFaceUpload(null); setFacePreset(p.id); } })),
577
+ h('button', { type: 'button', onClick: () => faceFileRef.current?.click(),
578
+ 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' } },
579
+ faceUpload
580
+ ? h(React.Fragment, null, h('img', { src: faceUpload, className: 'w-full h-full object-cover' }),
581
+ 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 })),
582
+ h('div', { className: 'absolute bottom-0 inset-x-0 py-0.5 bg-black/60 text-[10.5px] text-center' }, 'μ—…λ‘œλ“œ'))
583
+ : 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]' }, '직접 μ—…λ‘œλ“œ'))),
584
+ 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 = ''; } }))),
585
+
586
+ h('section', null, h(SectionTitle, null, 'μƒ· 선택'), h(Segmented, { options: SHOT_OPTIONS, value: shot, cols: 3, onChange: setShot })),
587
+ h('section', null,
588
+ h(SectionTitle, { right: images.pose && h('span', { className: 'text-[11px] text-gray-500' }, "'레퍼런슀 따름' = 포즈 μ‚¬μ§„μ˜ μ•΅κΈ€") }, '카메라 μ•΅κΈ€'),
589
+ h(Segmented, { options: images.pose ? ANGLE_OPTIONS : ANGLE_OPTIONS.filter(o => o !== '레퍼런슀 따름'), value: angle, onChange: setAngle, cols: 4 })),
590
+ h('section', null, h(SectionTitle, null, 'μ‹œμ„ '), h(Segmented, { options: images.pose ? GAZE_OPTIONS : GAZE_OPTIONS.filter(o => o !== '레퍼런슀 따름'), value: gaze, onChange: setGaze })),
591
+
592
+ h('section', null,
593
+ h(SectionTitle, null, 'ν”„λ‘¬ν”„νŠΈ μž‘μ„±'),
594
+ h('textarea', { value: prompt, onChange: e => setPrompt(e.target.value), rows: 3,
595
+ placeholder: 'μΆ”κ°€ μ§€μ‹œμ‚¬ν•­ (선택). 예: 손을 μ£Όλ¨Έλ‹ˆμ— λ„£κ³  살짝 λ―Έμ†Œ, μ†Œλ§€λ₯Ό ν•œ 번 μ ‘μ–΄ 올린 μŠ€νƒ€μΌλ§',
596
+ 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' })),
597
+
598
+ h('section', null,
599
+ h(SectionTitle, { right: h('span', { className: 'text-[11px] text-gray-500' }, 'μ•„μš°ν„°Β·μƒμ˜Β·ν•˜μ˜ 쀑 1개 이상') }, '이미지 μ—…λ‘œλ“œ'),
600
+ h('div', { className: 'grid grid-cols-4 gap-2' },
601
+ IMAGE_SLOTS.map(s => h(UploadTile, { key: s.key, slot: s, value: images[s.key], onChange: (v, name) => setImg(s.key, v, name) })))),
602
+
603
+ (images.pose || poseSpec) && (health?.ok && health.poseText !== false) && h('section', { className: 'animate-fadeIn' },
604
+ h(SectionTitle, { right: h('span', { className: 'text-[11px] text-gray-500' }, 'λΉ„μš°λ©΄ λ ˆνΌλŸ°μŠ€μ—μ„œ μžλ™ μΆ”μΆœ') }, '포즈 μ§€μ‹œ (선택)'),
605
+ h('textarea', { value: poseSpec, onChange: e => setPoseSpec(e.target.value), rows: 3,
606
+ placeholder: '예: 였λ₯ΈνŒ”을 λ“€μ–΄ 손등을 였λ₯Έμͺ½ κ΄€μžλ†€μ΄μ— κ°€λ³κ²Œ λŒ„λ‹€. μ™ΌνŒ”μ€ μžμ—°μŠ€λŸ½κ²Œ 내리고 체쀑은 μ™Όλ°œμ—. λͺΈν†΅μ€ 카메라 μͺ½μœΌλ‘œ 살짝 우츑.',
607
+ 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' }),
608
+ h('p', { className: 'text-[11px] text-gray-500 mt-1.5 leading-relaxed' }, '레퍼런슀 포즈λ₯Ό λ¬Έμž₯으둜 λ°”κΏ” ν”„λ‘¬ν”„νŠΈ 맨 끝에 μ΅œμš°μ„  μ§€μ‹œλ‘œ λ„£μ–΄μš”. κ²°κ³Όκ°€ λ‚˜μ˜€λ©΄ μ•„λž˜ νŒ¨λ„μ—μ„œ μžλ™ μΆ”μΆœλœ λ¬Έμž₯을 ν™•μΈν•˜κ³ , ν‹€λ¦° 뢀뢄을 μ—¬κΈ°μ„œ 고쳐 λ‹€μ‹œ 생성할 수 μžˆμ–΄μš”.')),
609
+
610
+ h('section', null,
611
+ h(SectionTitle, null, '길이 Β· 핏'),
612
+ h('div', { className: 'flex gap-1.5 mb-3' },
613
+ DETAIL_GROUPS.map(g => h('button', {
614
+ key: g.key, type: 'button', onClick: () => setDetailTab(g.key),
615
+ className: `px-3 py-1.5 rounded-lg text-[12.5px] font-semibold transition-colors ${detailTab === g.key
616
+ ? 'bg-brand-blue text-white'
617
+ : (images[g.key] ? 'bg-[#2a2a2a] text-gray-200 hover:bg-[#333]' : 'bg-[#242424] text-gray-500 hover:text-gray-300')}`
618
+ }, 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))),
619
+ (() => {
620
+ const g = DETAIL_GROUPS.find(x => x.key === detailTab);
621
+ const rows = [['길이', g.length], ['핏', g.fit]];
622
+ return h('div', { key: g.key, className: 'space-y-2 animate-fadeIn' },
623
+ rows.map(([label, k]) => h('div', { key: k, className: 'grid grid-cols-[52px_1fr] items-center gap-2' },
624
+ h('span', { className: 'text-[12px] text-gray-400' }, label),
625
+ h('div', { className: 'flex flex-wrap gap-1.5' },
626
+ DETAIL_OPTIONS[k].options.map(o => h('button', {
627
+ key: o, type: 'button', onClick: () => setDetails(d => ({ ...d, [k]: o })),
628
+ className: `px-3 py-1.5 rounded-lg text-[12.5px] font-medium border transition-colors ${details[k] === o
629
+ ? 'bg-brand-blue border-brand-blue text-white'
630
+ : 'bg-[#242424] border-[#333] text-gray-300 hover:border-[#4b5563] hover:text-white'}`
631
+ }, o))))),
632
+ !images[g.key] && h('p', { className: 'text-[11px] text-gray-500 pt-1' }, `${g.label} 이미지λ₯Ό μ˜¬λ¦¬μ§€ μ•ŠμœΌλ©΄ 이 섀정은 μ‚¬μš©λ˜μ§€ μ•Šμ•„μš”.`));
633
+ })()),
634
+
635
+ h('section', null,
636
+ h(SectionTitle, { right: h('span', { className: `text-[11px] ${detailCount >= DETAIL_MAX ? 'text-amber-400' : 'text-gray-500'}` }, `선택 Β· ${detailCount}/${DETAIL_MAX}μž₯`) }, 'λ””ν…ŒμΌ μ°Έμ‘°'),
637
+ health?.ok && health.detailCuts === false
638
+ ? h('p', { className: 'text-[11.5px] text-gray-500' }, 'ν˜„μž¬ 배포된 μ›Œν¬ν”Œλ‘œμš°(workflow_api.json)에 λ””ν…ŒμΌ μ°Έμ‘° μž…λ ₯이 μ—†μ–΄ μ‚¬μš©ν•  수 μ—†μ–΄μš”. v5 μ›Œν¬ν”Œλ‘œμš°λ₯Ό Export (API)ν•΄μ„œ κ΅μ²΄ν•΄μ£Όμ„Έμš”.')
639
+ : h(React.Fragment, null,
640
+ h('p', { className: 'text-[11px] text-gray-500 mb-2.5 leading-relaxed' }, 'ν΄λ‘œμ¦ˆμ—…μ„ 올리고 μ–΄λ–€ λΆ€μœ„μΈμ§€ κ³¨λΌμ£Όμ„Έμš” (옷 μ’…λ₯˜λ³„λ‘œ ν•­λͺ©μ΄ λ‹¬λΌμš”). μ‘°μ§κ°Β·μ†Œμž¬λŠ” 옷 전체에, λ‚˜λ¨Έμ§€λŠ” κ·Έ λΆ€μœ„μ—λ§Œ λ°˜μ˜ν•˜κ³  싀루엣은 메인 사진 κ·ΈλŒ€λ‘œ μœ μ§€ν•˜λ„λ‘ μ „λ‹¬λΌμš”. μ°Έμ‘°κ°€ 많으면 정확도가 λ–¨μ–΄μ Έμ„œ 전체 4μž₯κΉŒμ§€λ§Œ.'),
641
+ h('div', { className: 'grid grid-cols-2 gap-x-4 gap-y-2.5' },
642
+ DETAIL_GARMENTS.map(g => {
643
+ const enabled = !!images[g.key];
644
+ return h('div', { key: g.key, className: 'flex items-center gap-2' },
645
+ h('span', { className: `w-14 shrink-0 text-[12px] ${enabled ? 'text-gray-300' : 'text-gray-600'}`, title: enabled ? '' : `${g.label} 이미지λ₯Ό λ¨Όμ € μ˜¬λ €μ£Όμ„Έμš”` }, g.label),
646
+ DETAIL_SLOTS.map(slot => {
647
+ const id = `${g.key}:${slot}`;
648
+ const cur = images[`detail:${id}`];
649
+ const kind = kindOf(g.key, slot);
650
+ const kindList = DETAIL_KINDS_BY_GARMENT[g.key] || [];
651
+ const kindObj = kindList.find(k => k.key === kind) || kindList[0];
652
+ return h('div', { key: slot, className: 'w-16 flex flex-col items-center gap-1' },
653
+ h(DetailTile, { value: cur, disabled: !enabled || (!cur && detailCount >= DETAIL_MAX), onChange: (v, name) => setImg(`detail:${id}`, v, name) }),
654
+ // μ’…λ₯˜ 선택 μΉ© β€” λ„€μ΄ν‹°λΈŒ select λ₯Ό λ²„νŠΌμ²˜λŸΌ 보이게 (appearance-none + μ»€μŠ€ν…€ ν™”μ‚΄ν‘œ)
655
+ h('div', { className: 'relative w-full', title: enabled ? `${kindObj.label} Β· ν΄λ¦­ν•΄μ„œ λΆ€μœ„ λ³€κ²½` : '' },
656
+ h('select', {
657
+ value: kind, disabled: !enabled,
658
+ onChange: e => setDetailKinds(prev => ({ ...prev, [id]: e.target.value })),
659
+ style: { appearance: 'none', WebkitAppearance: 'none', MozAppearance: 'none' },
660
+ 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
661
+ ${cur ? 'bg-brand-blue/15 border-brand-blue/60 text-blue-200 hover:bg-brand-blue/25'
662
+ : 'bg-[#2a2a2a] border-[#3f3f3f] text-gray-300 hover:border-[#5a5a5a] hover:bg-[#303030]'}
663
+ disabled:opacity-40 disabled:cursor-default`
664
+ }, kindList.map(k => h('option', { key: k.key, value: k.key, className: 'bg-[#242424] text-gray-200' }, k.short))),
665
+ 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'}` })));
666
+ }));
667
+ })))),
668
+
669
+ h('div', { className: 'pt-3 pb-3 sticky bottom-0 bg-[#1e1e1e] border-t border-[#2a2a2a] -mx-5 px-5' },
670
+ missing.length > 0 && h('p', { className: 'text-[11.5px] text-gray-500 mb-2' }, `ν•„μš”: ${missing.join(', ')}`),
671
+ activeJobs.length > 0 && missing.length === 0 && h('p', { className: 'text-[11.5px] text-gray-500 mb-2' }, `${activeJobs.length}건 μ§„ν–‰ 쀑 β€” 섀정을 λ°”κΏ” λ°”λ‘œ λ‹€μŒ 컷을 κ±Έμ–΄λ‘˜ 수 μžˆμ–΄μš”`),
672
+ h('div', { className: 'flex items-center justify-between mb-2' },
673
+ h('span', { className: 'text-[11.5px] text-gray-500' }, '맀수'),
674
+ h('div', { className: 'flex gap-1' }, [1, 2].map(n =>
675
+ h('button', { key: n, type: 'button', onClick: () => setGenCount(n),
676
+ className: `px-3 py-1 rounded-lg text-[12px] font-medium transition-colors ${genCount === n ? 'bg-brand-blue text-white' : 'bg-[#2a2a2a] text-gray-400 hover:text-gray-200'}` }, `${n}μž₯`)))),
677
+ h('button', { type: 'button', onClick: handleGenerate, disabled: !canGenerate,
678
+ 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'}` },
679
+ h(Sparkles, { size: 16 }),
680
+ activeJobs.length > 0 ? `룩뢁 생성${genCount > 1 ? ` ${genCount}μž₯` : ''} (${activeJobs.length}건 μ§„ν–‰ 쀑)` : `룩뢁 생성${genCount > 1 ? ` ${genCount}μž₯` : ''}`))));
681
+
682
+ // ── Right: result ─────────────────────────────────────────
683
+ const right = h('main', { className: 'flex-1 h-full overflow-y-auto' },
684
+ h('div', { className: 'max-w-5xl mx-auto p-6 lg:p-8' },
685
+ !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' },
686
+ h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', null, health.error || 'Comfy λΈŒλ¦¬μ§€ 섀정을 ν™•μΈν•΄μ£Όμ„Έμš”.')),
687
+ 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' },
688
+ h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', null, 'HF OAuthκ°€ μ—°κ²°λ˜μ§€ μ•Šμ•„ 둜그인 없이 λˆ„κ΅¬λ‚˜ 생성할 수 μžˆλŠ” μƒνƒœμž…λ‹ˆλ‹€. README의 hf_oauth μ„€μ •κ³Ό Space μž¬μ‹œμž‘μ„ ν™•μΈν•΄μ£Όμ„Έμš”.')),
689
+ 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' },
690
+ h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', { className: 'break-all' }, error)),
691
+
692
+ jobs.length > 0 && h('div', { className: 'mb-5 rounded-xl border border-[#2a2a2a] bg-[#202020] overflow-hidden animate-fadeIn' },
693
+ 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' },
694
+ h(RefreshCw, { size: 13, className: activeJobs.length ? 'animate-spin text-brand-blue' : 'text-gray-500' }),
695
+ `μ§„ν–‰ 쀑 ${activeJobs.length}건`, jobs.length - activeJobs.length > 0 ? h('span', { className: 'text-red-300 font-normal' }, ` Β· μ‹€νŒ¨ ${jobs.length - activeJobs.length}건`) : null),
696
+ 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]' : ''}` },
697
+ h('div', { className: `w-1.5 h-1.5 rounded-full shrink-0 ${j.error ? 'bg-red-400' : 'bg-brand-blue pulse-ring relative'}` }),
698
+ h('div', { className: 'flex-1 min-w-0' },
699
+ 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),
700
+ h('div', { className: j.error ? 'text-red-300 break-all' : 'text-gray-400' },
701
+ j.error ? j.error : (j.execStartedAt ? `${j.stageLabel} Β· ${fmtSec((Date.now() - j.execStartedAt) / 1000)}` : `${j.stageLabel} Β· λŒ€κΈ° ${fmtSec((Date.now() - j.startedAt) / 1000)}`))),
702
+ j.error
703
+ ? h('button', { type: 'button', title: 'μ§€μš°κΈ°', onClick: () => dismissJob(j.id), className: 'text-gray-500 hover:text-white' }, h(X, { size: 14 }))
704
+ : h('button', { type: 'button', title: 'μž‘μ—… μ·¨μ†Œ', disabled: j.cancelling, onClick: () => cancelJob(j),
705
+ 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' },
706
+ j.cancelling ? 'μ·¨μ†Œ 쀑…' : 'μ·¨μ†Œ')))),
707
+
708
+ h('div', { className: 'grid grid-cols-1 md:grid-cols-[minmax(0,1fr)_200px] gap-6' },
709
+ // 메인 λ·°μ–΄
710
+ h('div', { className: 'rounded-2xl bg-[#202020] border border-[#2a2a2a] overflow-hidden relative', style: { minHeight: '60vh' } },
711
+ !current && activeJobs.length > 0
712
+ ? h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center gap-5' },
713
+ h('div', { className: 'shimmer absolute inset-0 opacity-60' }),
714
+ 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' })),
715
+ h('div', { className: 'relative text-center' },
716
+ h('div', { className: 'text-[15px] font-semibold text-gray-100' }, activeJobs[0].stageLabel),
717
+ h('div', { className: 'mt-1 text-[12.5px] text-gray-400 flex items-center justify-center gap-1' }, h(Clock, { size: 12 }),
718
+ activeJobs[0].execStartedAt ? `${fmtSec((Date.now() - activeJobs[0].execStartedAt) / 1000)} κ²½κ³Ό Β· 보톡 1~2λΆ„ μ†Œμš”` : 'μ‹€ν–‰ μˆœμ„œλ₯Ό κΈ°λ‹€λ¦¬λŠ” 쀑')),
719
+ h('p', { className: 'relative text-[11.5px] text-gray-500 max-w-xs text-center' }, '이 탭을 λ‹«μ§€ λ§ˆμ„Έμš”. 생성이 λλ‚˜λ©΄ 여기에 이미지가 ν‘œμ‹œλ©λ‹ˆλ‹€.'))
720
+ : current
721
+ ? h('div', { className: 'animate-fadeIn flex flex-col' },
722
+ h('div', { className: 'flex justify-center bg-[#1c1c1c]' },
723
+ h('div', { className: 'relative inline-block' },
724
+ h('img', { src: current.imageUrl, onClick: () => setLightbox(true), title: 'ν΄λ¦­ν•˜λ©΄ 크게 보기',
725
+ className: 'max-h-[78vh] w-auto max-w-full block bg-white cursor-zoom-in', alt: '생성 κ²°κ³Ό' }),
726
+ aiLabel && h('div', { className: 'ai-label-overlay' }, AI_LABEL_TEXT),
727
+ h('button', { type: 'button', onClick: () => setLightbox(true), title: '크게 보기',
728
+ 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 })))),
729
+ h('div', { className: 'flex items-center justify-between gap-3 px-4 py-3 border-t border-[#2a2a2a]' },
730
+ h('label', { className: 'flex items-center gap-2 cursor-pointer select-none text-[12.5px] text-gray-300' },
731
+ h('button', { type: 'button', role: 'switch', 'aria-checked': aiLabel, onClick: () => setAiLabel(v => !v),
732
+ className: `relative w-9 h-5 rounded-full transition-colors ${aiLabel ? 'bg-brand-blue' : 'bg-[#3a3a3a]'}` },
733
+ h('span', { className: `absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white transition-transform ${aiLabel ? 'translate-x-4' : ''}` })),
734
+ h('span', null, "'AI 생성 이미지' ν‘œκΈ°"),
735
+ h('span', { className: 'text-gray-500' }, aiLabel ? 'ν™”λ©΄Β·λ‹€μš΄λ‘œλ“œμ— 포함' : 'ν‘œκΈ° μ—†μŒ')),
736
+ h('button', { type: 'button', onClick: () => setExportOpen(true),
737
+ 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 }), 'λ‹€μš΄λ‘œλ“œ')))
738
+ : h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center text-gray-500 gap-2' },
739
+ h(Upload, { size: 28, className: 'opacity-50' }),
740
+ h('p', { className: 'text-[13.5px]' }, 'μ™Όμͺ½μ—μ„œ μ–Όκ΅΄Β·μ˜μƒμ„ κ³ λ₯΄κ³  룩뢁 생성을 λˆ„λ₯΄λ©΄'),
741
+ h('p', { className: 'text-[13.5px]' }, 'ν•œ λ²ˆμ— λͺ¨λΈμ»·μ΄ μƒμ„±λ©λ‹ˆλ‹€.'))),
742
+ // νžˆμŠ€ν† λ¦¬
743
+ h('div', null,
744
+ h('h3', { className: 'text-[13px] font-semibold text-gray-300 mb-2.5' }, `이번 μ„Έμ…˜ κ²°κ³Ό ${results.length ? `(${results.length})` : ''}`),
745
+ results.length === 0
746
+ ? h('p', { className: 'text-[12px] text-gray-500' }, '아직 μ—†μŒ')
747
+ : h('div', { className: 'grid grid-cols-3 md:grid-cols-1 gap-2' },
748
+ results.map(r => h('div', { key: r.id, className: 'relative group' },
749
+ h('button', { type: 'button', onClick: () => setCurrent(r),
750
+ className: `w-full relative rounded-xl overflow-hidden border-2 ${current?.id === r.id ? 'border-brand-blue' : 'border-transparent hover:border-[#4b5563]'}` },
751
+ h('img', { src: r.imageUrl, className: 'w-full h-auto block bg-white' }),
752
+ h('div', { className: 'absolute bottom-0 inset-x-0 px-2 py-1 bg-black/65 text-[10.5px] text-left leading-tight' },
753
+ h('div', null, `${r.meta.face ? r.meta.face + ' Β· ' : ''}${r.meta.shot} Β· ${r.meta.angle}`),
754
+ h('div', { className: 'text-gray-300' }, `${r.meta.gaze} Β· ${fmtSec(r.elapsedSec)}`))),
755
+ h('div', { className: 'absolute top-1.5 right-1.5 hidden group-hover:flex gap-1' },
756
+ r.payload && h('button', { type: 'button', onClick: (e) => { e.stopPropagation(); regenFrom(r); }, title: '이 μ„€μ •μœΌλ‘œ λ‹€μ‹œ 생성',
757
+ className: 'w-7 h-7 rounded-lg bg-black/60 hover:bg-brand-blue text-white flex items-center justify-center transition-colors' },
758
+ h(RefreshCw, { size: 13 })),
759
+ h('button', { type: 'button', onClick: (e) => { e.stopPropagation(); deleteResult(r); }, title: '이 κ²°κ³Ό μ§€μš°κΈ°',
760
+ className: 'w-7 h-7 rounded-lg bg-black/60 hover:bg-red-500 text-white flex items-center justify-center transition-colors' },
761
+ h(X, { size: 13 })))))))),
762
+
763
+ current && h('div', { className: 'mt-5 text-[12px] text-gray-500' },
764
+ `${current.meta.age} Β· ${current.meta.shot} Β· ${current.meta.angle} Β· ${current.meta.gaze}`, current.meta.prompt ? ` Β· "${current.meta.prompt}"` : ''),
765
+ current && (current.garmentSpecs || current.finalPrompt || current.poseSpec) && h('div', { className: 'mt-3 rounded-xl border border-[#2a2a2a] bg-[#202020]' },
766
+ 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' },
767
+ h('span', null, '포즈 뢄석 Β· μ˜μƒ 뢄석 Β· μ΅œμ’… ν”„λ‘¬ν”„νŠΈ'), h('span', { className: 'text-gray-500 font-normal' }, showSpecs ? 'μ ‘κΈ°' : '펼치기')),
768
+ showSpecs && h('div', { className: 'px-4 pb-4 space-y-3 animate-fadeIn' },
769
+ current.poseSpec && h('div', null,
770
+ h('div', { className: 'flex items-center justify-between mb-1' },
771
+ h('div', { className: 'text-[11px] text-gray-500' }, '포즈 뢄석 (레퍼런슀 β†’ λ¬Έμž₯, ν”„λ‘¬ν”„νŠΈ μ΅œμš°μ„  μ§€μ‹œ)'),
772
+ h('button', { type: 'button', onClick: () => { setPoseSpec(current.poseSpec); document.querySelector('aside')?.scrollTo({ top: 0, behavior: 'smooth' }); },
773
+ className: 'text-[11px] text-brand-blue hover:underline' }, '이 λ¬Έμž₯을 μˆ˜μ •ν•΄μ„œ λ‹€μ‹œ 생성')),
774
+ 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)),
775
+ current.garmentSpecs && h('div', null,
776
+ h('div', { className: 'text-[11px] text-gray-500 mb-1' }, 'GPT λΉ„μ „ μ˜μƒ 뢄석 (GARMENT SPECS)'),
777
+ 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)),
778
+ current.finalPrompt && h('div', null,
779
+ h('div', { className: 'text-[11px] text-gray-500 mb-1' }, 'GPT-image에 μ „λ‹¬λœ μ΅œμ’… ν”„λ‘¬ν”„νŠΈ'),
780
+ 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))))));
781
+
782
+ // ── Header ────────────────────────────────────────────────
783
+ const header = h('header', { className: 'h-14 shrink-0 border-b border-[#2a2a2a] bg-[#1a1a1a] flex items-center justify-between px-5' },
784
+ h('div', { className: 'flex items-center gap-5' },
785
+ h('div', { className: 'flex items-center gap-3' },
786
+ h('div', { className: 'w-8 h-8 rounded-lg bg-brand-blue flex items-center justify-center' }, h(Sparkles, { size: 16, className: 'text-white' })),
787
+ h('div', { className: 'text-[15px] font-bold tracking-tight' }, 'CLOVIS AI 룩뢁 생성기')),
788
+ user.oauth_enabled && h('div', { className: 'flex items-center gap-2 text-[12.5px] pl-5 border-l border-[#2a2a2a]' },
789
+ user.is_logged_in
790
+ ? h(React.Fragment, null,
791
+ h('span', { className: 'text-gray-300' }, user.name || user.username),
792
+ h('a', { href: user.logout_url, className: 'text-gray-500 hover:text-white' }, 'λ‘œκ·Έμ•„μ›ƒ'))
793
+ : h('a', { href: user.login_url, className: 'px-3 py-1.5 rounded-lg bg-[#2a2a2a] hover:bg-[#333] text-gray-100' }, 'πŸ€— Hugging Face둜 둜그인'))),
794
+ h('div', null,
795
+ health && !health.ok && h('span', { className: 'inline-flex items-center gap-1.5 text-[12.5px] text-amber-400' },
796
+ h('span', { className: 'w-1.5 h-1.5 rounded-full bg-amber-400' }), 'Comfy μ„€μ • ν•„μš”')));
797
+
798
+ const lightboxEl = lightbox && current && h('div', {
799
+ className: 'fixed inset-0 z-50 bg-black/90 flex items-center justify-center animate-fadeIn cursor-zoom-out',
800
+ onClick: () => setLightbox(false) },
801
+ h('img', { src: current.imageUrl, alt: '생성 κ²°κ³Ό ν™•λŒ€', onClick: e => e.stopPropagation(),
802
+ className: 'max-w-[96vw] max-h-[96vh] object-contain bg-white cursor-default shadow-2xl' }),
803
+ aiLabel && h('div', { className: 'absolute top-4 right-16 text-[12px] text-gray-300 font-light pointer-events-none' }, AI_LABEL_TEXT),
804
+ h('button', { type: 'button', onClick: () => setLightbox(false), title: 'λ‹«κΈ° (Esc)',
805
+ 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 })),
806
+ h('div', { className: 'absolute bottom-4 left-1/2 -translate-x-1/2 flex gap-2', onClick: e => e.stopPropagation() },
807
+ h('button', { type: 'button', onClick: () => { setLightbox(false); setExportOpen(true); },
808
+ 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 }), 'λ‹€μš΄λ‘œλ“œ')));
809
+
810
+ const exportEl = exportOpen && current && h(ExportModal, { current, aiLabel, onClose: () => setExportOpen(false) });
811
+
812
+ return h('div', { className: 'h-screen flex flex-col bg-[#1a1a1a]' }, header,
813
+ h('div', { className: 'flex-1 flex flex-col lg:flex-row min-h-0' }, left, right), lightboxEl, exportEl);
814
+ }
815
+
816
+ ReactDOM.createRoot(document.getElementById('root')).render(h(App));
817
+ </script>
818
+ </body>
819
+ </html>