Repository navigation
Expand file tree
/
Copy pathpage.tsx
More file actions
373 lines (352 loc) · 13.7 KB
/
Copy pathpage.tsx
File metadata and controls
373 lines (352 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
"use client";
import React, { useState, useRef } from "react";
import dynamic from "next/dynamic";
import { useImageHandler } from "../../lib/hooks/use-image-handler";
import { useTouchHandler } from "../../lib/hooks/use-touch-handler";
import { useZoomPrevention } from "../../lib/hooks/use-zoom-prevention";
import { downloadCanvas } from "../../lib/utils/canvas-download";
import { useTranslations } from "next-intl";
import NoSSR from "./components/no-ssr";
import { ExampleImageWithSkeleton } from "./components/example-image-with-skeleton";
import { ImageSkeleton, SkeletonLoader } from "./components/skeleton-loader";
// 동적 import로 hydration mismatch 방지
const CameraCanvas = dynamic(
() =>
import("./camera-canvas").then((mod) => ({ default: mod.CameraCanvas })),
{
ssr: false,
loading: () => null, // Will be handled by custom loading component
}
);
const ControlPanel = dynamic(
() =>
import("./control-panel").then((mod) => ({ default: mod.ControlPanel })),
{
ssr: false,
loading: () => null, // Will be handled by custom loading component
}
);
// Canvas loading component with skeleton
function CanvasLoadingSkeleton({ isDarkTheme, size }: { isDarkTheme: boolean; size: string }) {
return (
<div
style={{
width: size,
height: size,
borderRadius: "22.37%",
}}
>
<ImageSkeleton
aspectRatio="canvas"
size="100%"
isDarkTheme={isDarkTheme}
className="rounded-[22.37%]"
/>
</div>
);
}
// Control panel loading skeleton
function ControlPanelLoadingSkeleton({ isDarkTheme, isMobile }: { isDarkTheme: boolean; isMobile?: boolean }) {
if (isMobile) {
return (
<div className={`${isDarkTheme ? 'bg-gray-800' : 'bg-white'} ${isDarkTheme ? 'border-gray-700' : 'border-gray-200'} border-t p-4 space-y-4`}>
<SkeletonLoader height="48px" isDarkTheme={isDarkTheme} className="rounded" />
<SkeletonLoader height="20px" isDarkTheme={isDarkTheme} className="rounded" />
<SkeletonLoader height="8px" isDarkTheme={isDarkTheme} className="rounded-full" />
<SkeletonLoader height="20px" isDarkTheme={isDarkTheme} className="rounded" />
<SkeletonLoader height="8px" isDarkTheme={isDarkTheme} className="rounded-full" />
<SkeletonLoader height="48px" isDarkTheme={isDarkTheme} className="rounded" />
<SkeletonLoader height="48px" isDarkTheme={isDarkTheme} className="rounded" />
<div className="flex gap-2">
<SkeletonLoader height="48px" isDarkTheme={isDarkTheme} className="rounded flex-1" />
<SkeletonLoader height="48px" isDarkTheme={isDarkTheme} className="rounded flex-1" />
</div>
</div>
);
}
return (
<div className={`w-80 ${isDarkTheme ? 'bg-gray-800' : 'bg-white'} ${isDarkTheme ? 'border-gray-700' : 'border-gray-200'} border-l p-6 space-y-8`}>
<SkeletonLoader height="24px" width="120px" isDarkTheme={isDarkTheme} className="rounded" />
<SkeletonLoader height="48px" isDarkTheme={isDarkTheme} className="rounded" />
<div className="space-y-3">
<SkeletonLoader height="16px" width="80px" isDarkTheme={isDarkTheme} className="rounded" />
<SkeletonLoader height="8px" isDarkTheme={isDarkTheme} className="rounded-full" />
</div>
<div className="space-y-3">
<SkeletonLoader height="16px" width="60px" isDarkTheme={isDarkTheme} className="rounded" />
<SkeletonLoader height="8px" isDarkTheme={isDarkTheme} className="rounded-full" />
</div>
<SkeletonLoader height="48px" isDarkTheme={isDarkTheme} className="rounded" />
<SkeletonLoader height="48px" isDarkTheme={isDarkTheme} className="rounded" />
<SkeletonLoader height="48px" isDarkTheme={isDarkTheme} className="rounded" />
<SkeletonLoader height="48px" isDarkTheme={isDarkTheme} className="rounded" />
</div>
);
}
export default function Home() {
const t = useTranslations();
const [lensOpacity, setLensOpacity] = useState(0.75);
const [isDarkTheme, setIsDarkTheme] = useState(false);
const [canvasLoaded, setCanvasLoaded] = useState(false);
const [controlsLoaded, setControlsLoaded] = useState(false);
const canvasRef = useRef<HTMLDivElement>(null);
// Handle loading states
React.useEffect(() => {
// Simulate loading times
const canvasTimer = setTimeout(() => setCanvasLoaded(true), 100);
const controlsTimer = setTimeout(() => setControlsLoaded(true), 200);
return () => {
clearTimeout(canvasTimer);
clearTimeout(controlsTimer);
};
}, []);
const {
imagePosition,
setImagePosition,
imageScale,
setImageScale,
isAnimatedFile,
displayImage,
downloadImage,
selectedExample,
fileInputRef,
handleImageUpload,
handleExampleSelect,
resetImagePosition,
} = useImageHandler();
const {
handleMouseDown,
handleMouseMove,
handleMouseUp,
handleTouchMove,
handleTouchEnd,
handleTouchStart,
} = useTouchHandler(
imagePosition,
setImagePosition,
imageScale,
setImageScale
);
useZoomPrevention(imageScale, setImageScale);
const handleDownload = () => {
downloadCanvas(
downloadImage,
isDarkTheme,
imagePosition,
imageScale,
lensOpacity,
canvasRef
);
};
const themeClass = isDarkTheme ? "dark" : "";
const bgColor = isDarkTheme ? "bg-gray-900" : "bg-gray-50";
const textColor = isDarkTheme ? "text-white" : "text-gray-900";
const cardBg = isDarkTheme ? "bg-gray-800" : "bg-white";
const borderColor = isDarkTheme ? "border-gray-700" : "border-gray-200";
return (
<NoSSR>
<div
className={`min-h-screen ${bgColor} ${textColor} ${themeClass} select-none`}
style={{
touchAction: "pan-x pan-y",
zoom: 1,
transform: "scale(1)",
WebkitTransform: "scale(1)",
MozTransform: "scale(1)",
}}
>
{/* Mobile/Tablet Layout */}
<div className="flex flex-col lg:hidden">
{/* Mobile Header */}
<div
className={`${cardBg} ${borderColor} border-b px-4 py-3 flex items-center justify-center gap-2`}
>
<div className="w-6 h-6">
<img
src="/logo.png"
alt="Meme Lens Logo"
className="inset-0 w-full h-full object-cover pointer-events-none"
/>
</div>
<h1 className="text-lg font-semibold">{t("appTitle")}</h1>
</div>
{/* Mobile Canvas */}
<div className="flex-1 flex items-center justify-center p-4">
{canvasLoaded ? (
<CameraCanvas
displayImage={displayImage}
imagePosition={imagePosition}
imageScale={imageScale}
lensOpacity={lensOpacity}
isDarkTheme={isDarkTheme}
canvasRef={canvasRef}
onMouseDown={handleMouseDown}
onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp}
onTouchStart={handleTouchStart}
onTouchMove={handleTouchMove}
onTouchEnd={handleTouchEnd}
size="min(90vw, 90vh, 400px)"
/>
) : (
<CanvasLoadingSkeleton
isDarkTheme={isDarkTheme}
size="min(90vw, 90vh, 400px)"
/>
)}
</div>
{/* Mobile Controls */}
{controlsLoaded ? (
<ControlPanel
lensOpacity={lensOpacity}
setLensOpacity={setLensOpacity}
imageScale={imageScale}
setImageScale={setImageScale}
isDarkTheme={isDarkTheme}
setIsDarkTheme={setIsDarkTheme}
isAnimatedFile={isAnimatedFile}
onUploadClick={() => fileInputRef.current?.click()}
onReset={resetImagePosition}
onDownload={handleDownload}
onExampleSelect={handleExampleSelect}
selectedExample={selectedExample}
isMobile={true}
/>
) : (
<ControlPanelLoadingSkeleton isDarkTheme={isDarkTheme} isMobile={true} />
)}
</div>
{/* Desktop Layout */}
<div className="hidden lg:flex flex-col min-h-screen">
{/* Desktop Header */}
<div
className={`${cardBg} ${borderColor} border-b p-4 flex items-center justify-center gap-2`}
>
<div className="w-6 h-6">
<img
src="/logo.png"
alt="Meme Lens Logo"
className="inset-0 w-full h-full object-cover pointer-events-none"
/>
</div>
<h1 className="text-xl font-semibold">{t("appTitle")}</h1>
</div>
{/* Desktop Content */}
<div className="flex-1 flex min-h-0 overflow-hidden">
{/* Canvas Area with Example Gallery */}
<div className="flex-1 flex flex-col min-h-0 overflow-hidden">
{/* Canvas Section - Calculated to leave exact space for Example Images */}
<div
className="flex items-center justify-center p-4 min-h-0"
style={{
height: 'calc(100vh - 61px - max(80px, min(140px, 20vh)))'
}}
>
{canvasLoaded ? (
<CameraCanvas
displayImage={displayImage}
imagePosition={imagePosition}
imageScale={imageScale}
lensOpacity={lensOpacity}
isDarkTheme={isDarkTheme}
canvasRef={canvasRef}
onMouseDown={handleMouseDown}
onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp}
onTouchStart={handleTouchStart}
onTouchMove={handleTouchMove}
onTouchEnd={handleTouchEnd}
size="min(calc(100vh - 61px - max(80px, min(140px, 20vh)) - 32px), min(calc(100vw - 320px - 32px), 500px))"
/>
) : (
<CanvasLoadingSkeleton
isDarkTheme={isDarkTheme}
size="min(calc(100vh - 61px - max(80px, min(140px, 20vh)) - 32px), min(calc(100vw - 320px - 32px), 500px))"
/>
)}
</div>
{/* Example Gallery Section - Fixed height that matches calculation above */}
<div
className={`${cardBg} ${borderColor} border-t flex-shrink-0 overflow-hidden`}
style={{
height: 'max(80px, min(140px, 20vh))',
padding: '8px'
}}
>
<NoSSR>
<div className="max-w-3xl mx-auto h-full overflow-hidden">
<h3
className="font-medium mb-1"
style={{
fontSize: 'max(10px, min(14px, calc(100vh / 50)))'
}}
>
{t("exampleImages")}
</h3>
<div
className="grid grid-cols-4 h-auto"
style={{
gap: 'max(2px, min(8px, calc(100vh / 120)))'
}}
>
{[
{ id: 'example-1', path: '/example-1.webp', alt: 'Example 1' },
{ id: 'example-2', path: '/example-2.webp', alt: 'Example 2' },
{ id: 'example-3', path: '/example-3.webp', alt: 'Example 3' },
{ id: 'example-4', path: '/example-4.webp', alt: 'Example 4' },
].map((example) => (
<ExampleImageWithSkeleton
key={example.id}
src={example.path}
alt={example.alt}
onClick={() => handleExampleSelect(example.path)}
isSelected={selectedExample === example.path}
isDarkTheme={isDarkTheme}
borderColor={borderColor}
className="aspect-square rounded-sm"
style={{
height: 'calc(max(80px, min(140px, 20vh)) - 40px)',
width: 'calc(max(80px, min(140px, 20vh)) - 40px)',
maxHeight: '60px',
maxWidth: '60px'
}}
/>
))}
</div>
</div>
</NoSSR>
</div>
</div>
{/* Desktop Controls */}
{controlsLoaded ? (
<ControlPanel
lensOpacity={lensOpacity}
setLensOpacity={setLensOpacity}
imageScale={imageScale}
setImageScale={setImageScale}
isDarkTheme={isDarkTheme}
setIsDarkTheme={setIsDarkTheme}
isAnimatedFile={isAnimatedFile}
onUploadClick={() => fileInputRef.current?.click()}
onReset={resetImagePosition}
onDownload={handleDownload}
onExampleSelect={handleExampleSelect}
selectedExample={selectedExample}
isMobile={false}
/>
) : (
<ControlPanelLoadingSkeleton isDarkTheme={isDarkTheme} isMobile={false} />
)}
</div>
</div>
<input
ref={fileInputRef}
type="file"
accept="image/*,video/*"
onChange={handleImageUpload}
className="hidden"
/>
</div>
</NoSSR>
);
}