yonatanadvan commited on
Commit
6fff1d4
路
verified 路
1 Parent(s): 9f2981c

Update components/Guest/EditScreen.tsx

Browse files
Files changed (1) hide show
  1. components/Guest/EditScreen.tsx +31 -35
components/Guest/EditScreen.tsx CHANGED
@@ -16,11 +16,13 @@ interface Props {
16
  }
17
 
18
  const MAX_IMAGE_SIZE = 1024;
 
19
 
 
20
  const AI_PRESETS = [
21
  { id: 'hero', name: '讙讬讘讜专讬 注诇', prompt: 'Turn everyone into superheroes. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 35% top padding).' },
22
- { id: 'gta', name: '驻专注讜谞讬诐 诪爪专讬诐', prompt: 'Turn everyone into Ancient Egyptian Pharaohs style, pyramids and desert background, gold jewelry and headdresses, cinematic lighting, golden sands, wide angle, 4k. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
23
- { id: 'lego', name: '讗诇讬诐 讬讜讜谞讬诐', prompt: 'Turn everyone into Ancient Greek Gods and Goddesses style. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
24
  { id: 'simpson', name: '住诪讜专讗讬诐', prompt: 'Turn everyone into realistic Japanese Samurai warriors, wearing traditional armor and kimonos, cherry blossom forest background, 4k. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
25
  { id: 'disney', name: '讚讬住谞讬', prompt: '3D Disney Pixar character style. realistic. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
26
  { id: 'vikings', name: '讜讬拽讬谞讙讬诐', prompt: 'Turn everyone into tough Vikings with furs and helmets. Dramatic lighting. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
@@ -28,8 +30,7 @@ const AI_PRESETS = [
28
  { id: 'cyber', name: '住讬讬讘专驻讗谞拽', prompt: 'Futuristic cyborgs with neon lights. Neon city background. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
29
  { id: 'sketch', name: '专讬砖讜诐 讘注讬驻专讜谉', prompt: 'Pencil sketch drawing on paper. Black and white artistic style. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
30
  { id: 'joker', name: '讛讙壮讜拽专', prompt: 'Turn everyone into Joker style villains with clown makeup. Dark, dramatic lighting. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
31
- { id: 'retro', name: '砖谞讜转 讛-90', prompt: '1990s vintage flash photography photo. Grainy film look overexposed. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
32
- { id: 'marble', name: '驻住诇讬诐', prompt: 'Turn everyone into realistic White marble Greek statues. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
33
  { id: 'oil', name: '讜讗谉 讙讜讱', prompt: 'Classical oil painting portrait, Van Gogh style with thick brushstrokes. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
34
  { id: 'matrix', name: '诪讟专讬拽住', prompt: 'Turn everyone into The Matrix style, wearing black trench coats and sunglasses. Green digital code background. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 35% top padding).' },
35
  ];
@@ -103,6 +104,9 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
103
  const [aiImage, setAiImage] = useState<string | null>(null);
104
  const [isAiProcessing, setIsAiProcessing] = useState(false);
105
  const [hasUsedAI, setHasUsedAI] = useState(false);
 
 
 
106
 
107
  const containerRef = useRef<HTMLDivElement>(null);
108
  const WebGLWrapperRef = useRef<HTMLDivElement>(null);
@@ -131,7 +135,7 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
131
  let isMounted = true;
132
 
133
  const initSystem = async () => {
134
- if (!WebGLWrapperRef.current || !drawingCanvasRef.current) return; // 讞讬讬讘讬诐 讙诐 讗转 拽谞讘住 讛爪讬讜专
135
 
136
  const sourceImage = aiImage || originalImage;
137
  if (!sourceImage) return;
@@ -153,6 +157,7 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
153
  let renderWidth = img.width;
154
  let renderHeight = img.height;
155
 
 
156
  if (renderWidth > MAX_IMAGE_SIZE || renderHeight > MAX_IMAGE_SIZE) {
157
  const ratio = renderWidth / renderHeight;
158
  if (renderWidth > renderHeight) {
@@ -164,6 +169,9 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
164
  }
165
  }
166
 
 
 
 
167
  const tempCanvas = document.createElement('canvas');
168
  tempCanvas.width = renderWidth;
169
  tempCanvas.height = renderHeight;
@@ -173,14 +181,13 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
173
  if (textureRef.current) textureRef.current.destroy();
174
  textureRef.current = fxCanvasRef.current.texture(tempCanvas);
175
 
176
- // === 转讬拽讜谉 拽专讬讟讬 诇讟讜砖讬诐 ===
177
- // 讛讙讚专转 讛专讝讜诇讜爪讬讛 讛驻谞讬诪讬转 砖诇 砖谞讬 讛拽谞讘住讬诐 砖转讛讬讛 讝讛讛 诇讞诇讜讟讬谉
178
  fxCanvasRef.current.width = renderWidth;
179
  fxCanvasRef.current.height = renderHeight;
180
  drawingCanvasRef.current.width = renderWidth;
181
  drawingCanvasRef.current.height = renderHeight;
182
 
183
- // 谞讬拽讜讬 拽谞讘住 讛爪讬讜专 讘注转 讟注讬谞转 转诪讜谞讛 讞讚砖讛
184
  const ctx = drawingCanvasRef.current.getContext('2d');
185
  ctx?.clearRect(0, 0, renderWidth, renderHeight);
186
 
@@ -199,9 +206,6 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
199
  }, [originalImage, aiImage]);
200
 
201
 
202
- // 驻讜谞拽爪讬讬转 讛-syncDrawingCanvas 讛讬砖谞讛 讛讜住专讛 讻讬 讛讬讗 讙专诪讛 诇讘注讬讜转.
203
- // 讛专讝讜诇讜爪讬讛 谞拽讘注转 注讻砖讬讜 讗讱 讜专拽 讘-initSystem.
204
-
205
  const applyFilter = (filterId: string) => {
206
  const canvas = fxCanvasRef.current;
207
  const texture = textureRef.current;
@@ -218,7 +222,6 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
218
 
219
  const getCoordinates = (e: React.MouseEvent | React.TouchEvent, canvas: HTMLCanvasElement) => {
220
  const rect = canvas.getBoundingClientRect();
221
- // 讞讬砖讜讘 讬讞住 讘讬谉 讛讙讜讚诇 讛诪讜爪讙 诇讙讜讚诇 讛讗诪讬转讬
222
  const scaleX = canvas.width / rect.width;
223
  const scaleY = canvas.height / rect.height;
224
 
@@ -288,7 +291,6 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
288
 
289
  if (result && result.data && result.data.images && result.data.images[0]) {
290
  const newImageUrl = result.data.images[0].url;
291
-
292
  await new Promise((resolve, reject) => {
293
  const img = new Image();
294
  img.onload = resolve;
@@ -332,10 +334,8 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
332
  if (!ctx) throw new Error("Context error");
333
 
334
  ctx.drawImage(webglCanvas, 0, 0);
335
-
336
- // === 转讬拽讜谉 拽专讬讟讬 讘砖诪讬专讛 ===
337
- // 诪爪讬讬专讬诐 讗转 拽谞讘住 讛爪讬讜专 讘讙讜讚诇 讛诪拽讜专讬 砖诇讜 (1:1)
338
- // 诪讻讬讜讜谉 砖讛砖讜讜讬谞讜 讗转 讛专讝讜诇讜爪讬讜转 讘-initSystem, 讝讛 讬爪讗 诪讚讜讬拽
339
  ctx.drawImage(drawCanvas, 0, 0);
340
 
341
  finalImageBase64 = finalCanvas.toDataURL('image/jpeg', 0.95);
@@ -375,22 +375,20 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
375
  return (
376
  <div className="flex flex-col h-full overflow-y-auto no-scrollbar bg-gray-50">
377
 
378
- {/* 讛拽讜谞讟讬讬谞专 讛专讗砖讬 讛讝讛 讛讜讗 注讻砖讬讜 "讛诪住讙专转 讛诇讘谞讛".
379
- bg-white: 爪讘注 讛专拽注 讛诇讘谉.
380
- p-4: 专讬驻讜讚 砖诇 1rem 诪讻诇 讛爪讚讚讬诐 (讛注讜讘讬 砖诇 讛诪住讙专转).
381
- flex-col: 诪住讚专 讗转 讛转诪讜谞讛 讜讛讟拽住讟 讗讞讚 诪转讞转 诇砖谞讬.
382
- */}
383
  <div
384
  ref={containerRef}
385
- className="relative flex-1 w-full overflow-hidden mb-0 min-h-[50vh] bg-white touch-none flex flex-col p-4 shadow-inner"
386
  >
387
 
388
- {/* 讝讜 "讛拽讜驻住讛" 砖诪讞讝讬拽讛 讗转 讛转诪讜谞讛 讜讛爪讬讜专讬诐.
389
- relative, flex-1, w-full: 转讜驻住转 讗转 讻诇 讛诪拽讜诐 讛驻谞讜讬 讘转讜讱 讛诪住讙专转.
390
- overflow-hidden, rounded-sm: 诪注讙诇 诪注讟 讗转 讛驻讬谞讜转 砖诇 讛转诪讜谞讛 注爪诪讛.
391
- bg-gray-100: 专拽注 讗驻讜专 讘讛讬专 砖讬专讗讛 专拽 讗诐 讛转诪讜谞讛 诇讗 谞讟注谞转 (谞讚讬专).
392
- */}
393
- <div className="relative flex-1 w-full overflow-hidden rounded-sm bg-gray-100">
 
 
394
  {isAiProcessing && (
395
  <div className="absolute inset-0 z-50 bg-black/60 backdrop-blur-sm flex flex-col items-center justify-center text-white">
396
  <Sparkles className="w-12 h-12 animate-spin mb-4 text-brand-orange" />
@@ -399,13 +397,11 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
399
  </div>
400
  )}
401
 
402
- {/* 拽谞讘住 WebGL (讛转诪讜谞讛 讜讛驻讬诇讟专讬诐) - 转讜驻住 讗转 讻诇 讛"拽讜驻住讛" */}
403
  <div
404
  ref={WebGLWrapperRef}
405
- className="absolute inset-0 w-full h-full flex items-center justify-center z-10 [&>canvas]:object-contain [&>canvas]:w-full [&>canvas]:h-full"
406
  />
407
 
408
- {/* 拽谞讘住 爪讬讜专 - 转讜驻住 讗转 讻诇 讛"拽讜驻住讛" */}
409
  <canvas
410
  ref={drawingCanvasRef}
411
  onMouseDown={startDrawing}
@@ -415,12 +411,12 @@ export const EditScreen: React.FC<Props> = ({ originalImage, onRetake, onComplet
415
  onTouchStart={startDrawing}
416
  onTouchMove={draw}
417
  onTouchEnd={stopDrawing}
418
- className={`absolute inset-0 z-20 w-full h-full object-contain ${activeTab === 'paint' ? 'cursor-crosshair pointer-events-auto' : 'pointer-events-none'}`}
419
  />
420
  </div>
421
 
422
- {/* 讛讟拽住讟 讛转讞转讜谉 - 讬讜砖讘 诪转讞转 诇"拽讜驻住讛" 砖诇 讛转诪讜谞讛, 讘转讜讱 讛诪住讙专转 讛诇讘谞讛 讛讻诇诇讬转 */}
423
- <div className="w-full pt-2 pb-1 flex flex-col items-center justify-center">
424
  <span className="text-gray-900 font-black text-sm md:text-base leading-tight">
425
  {frameText.title || '讟讜注谉...'}
426
  </span>
 
16
  }
17
 
18
  const MAX_IMAGE_SIZE = 1024;
19
+ const MAX_PHOTOS_PER_DEVICE = 3;
20
 
21
+ // === 20 驻专讜诪驻讟讬诐 ===
22
  const AI_PRESETS = [
23
  { id: 'hero', name: '讙讬讘讜专讬 注诇', prompt: 'Turn everyone into superheroes. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 35% top padding).' },
24
+ { id: 'gta', name: '驻专注讜谞讬诐 诪爪专讬讬诐', prompt: 'Turn everyone into Ancient Egyptian Pharaohs style, pyramids and desert background, gold jewelry and headdresses, cinematic lighting, golden sands, wide angle, 4k. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
25
+ { id: 'lego', name: '讗诇讬诐 讬讜讜谞讬讬诐', prompt: 'Turn everyone into Ancient Greek Gods and Goddesses style. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
26
  { id: 'simpson', name: '住诪讜专讗讬诐', prompt: 'Turn everyone into realistic Japanese Samurai warriors, wearing traditional armor and kimonos, cherry blossom forest background, 4k. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
27
  { id: 'disney', name: '讚讬住谞讬', prompt: '3D Disney Pixar character style. realistic. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
28
  { id: 'vikings', name: '讜讬拽讬谞讙讬诐', prompt: 'Turn everyone into tough Vikings with furs and helmets. Dramatic lighting. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
 
30
  { id: 'cyber', name: '住讬讬讘专驻讗谞拽', prompt: 'Futuristic cyborgs with neon lights. Neon city background. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
31
  { id: 'sketch', name: '专讬砖讜诐 讘注讬驻专讜谉', prompt: 'Pencil sketch drawing on paper. Black and white artistic style. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
32
  { id: 'joker', name: '讛讙壮讜拽专', prompt: 'Turn everyone into Joker style villains with clown makeup. Dark, dramatic lighting. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
33
+ { id: 'retro', name: '砖谞讜转 讛-90', prompt: 'Vintage 1990s flash photography. Grainy film look overexposed. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
 
34
  { id: 'oil', name: '讜讗谉 讙讜讱', prompt: 'Classical oil painting portrait, Van Gogh style with thick brushstrokes. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 30% top padding).' },
35
  { id: 'matrix', name: '诪讟专讬拽住', prompt: 'Turn everyone into The Matrix style, wearing black trench coats and sunglasses. Green digital code background. Recompose the image so the original content sits lower in the frame, with significant empty margin added above it (approximately 35% top padding).' },
36
  ];
 
104
  const [aiImage, setAiImage] = useState<string | null>(null);
105
  const [isAiProcessing, setIsAiProcessing] = useState(false);
106
  const [hasUsedAI, setHasUsedAI] = useState(false);
107
+
108
+ // 诪砖转谞讛 诇砖诪讬专转 讬讞住 讙讜讘讛-专讜讞讘 讻讚讬 诇讚讬讬拽 讘爪讬讜专
109
+ const [imageAspectRatio, setImageAspectRatio] = useState<number>(3/4);
110
 
111
  const containerRef = useRef<HTMLDivElement>(null);
112
  const WebGLWrapperRef = useRef<HTMLDivElement>(null);
 
135
  let isMounted = true;
136
 
137
  const initSystem = async () => {
138
+ if (!WebGLWrapperRef.current || !drawingCanvasRef.current) return;
139
 
140
  const sourceImage = aiImage || originalImage;
141
  if (!sourceImage) return;
 
157
  let renderWidth = img.width;
158
  let renderHeight = img.height;
159
 
160
+ // 讛拽讟谞讛
161
  if (renderWidth > MAX_IMAGE_SIZE || renderHeight > MAX_IMAGE_SIZE) {
162
  const ratio = renderWidth / renderHeight;
163
  if (renderWidth > renderHeight) {
 
169
  }
170
  }
171
 
172
+ // 讞讬砖讜讘 讬讞住 讙讜讘讛 专讜讞讘 诇-CSS
173
+ setImageAspectRatio(renderWidth / renderHeight);
174
+
175
  const tempCanvas = document.createElement('canvas');
176
  tempCanvas.width = renderWidth;
177
  tempCanvas.height = renderHeight;
 
181
  if (textureRef.current) textureRef.current.destroy();
182
  textureRef.current = fxCanvasRef.current.texture(tempCanvas);
183
 
184
+ // 讛讙讚专转 讛专讝讜诇讜爪讬讛 讛驻谞讬诪讬转
 
185
  fxCanvasRef.current.width = renderWidth;
186
  fxCanvasRef.current.height = renderHeight;
187
  drawingCanvasRef.current.width = renderWidth;
188
  drawingCanvasRef.current.height = renderHeight;
189
 
190
+ // 谞讬拽讜讬 拽谞讘住 讛爪讬讜专
191
  const ctx = drawingCanvasRef.current.getContext('2d');
192
  ctx?.clearRect(0, 0, renderWidth, renderHeight);
193
 
 
206
  }, [originalImage, aiImage]);
207
 
208
 
 
 
 
209
  const applyFilter = (filterId: string) => {
210
  const canvas = fxCanvasRef.current;
211
  const texture = textureRef.current;
 
222
 
223
  const getCoordinates = (e: React.MouseEvent | React.TouchEvent, canvas: HTMLCanvasElement) => {
224
  const rect = canvas.getBoundingClientRect();
 
225
  const scaleX = canvas.width / rect.width;
226
  const scaleY = canvas.height / rect.height;
227
 
 
291
 
292
  if (result && result.data && result.data.images && result.data.images[0]) {
293
  const newImageUrl = result.data.images[0].url;
 
294
  await new Promise((resolve, reject) => {
295
  const img = new Image();
296
  img.onload = resolve;
 
334
  if (!ctx) throw new Error("Context error");
335
 
336
  ctx.drawImage(webglCanvas, 0, 0);
337
+
338
+ // 砖诪讬专讛 1:1, 诇诇讗 诪转讬讞讛
 
 
339
  ctx.drawImage(drawCanvas, 0, 0);
340
 
341
  finalImageBase64 = finalCanvas.toDataURL('image/jpeg', 0.95);
 
375
  return (
376
  <div className="flex flex-col h-full overflow-y-auto no-scrollbar bg-gray-50">
377
 
378
+ {/* 诪住讙专转 诇讘谞讛 专讗砖讬转 */}
 
 
 
 
379
  <div
380
  ref={containerRef}
381
+ className="relative flex-1 w-full overflow-hidden mb-0 min-h-[50vh] bg-white touch-none flex flex-col items-center justify-center p-4 shadow-inner"
382
  >
383
 
384
+ {/* 拽讜驻住讛 砖砖讜诪专转 注诇 讬讞住 讙讜讘讛-专讜讞讘 讜诪讻讬诇讛 讗转 讛拽谞讘住讬诐 */}
385
+ <div
386
+ className="relative w-full max-h-full bg-gray-100 overflow-hidden shadow-sm"
387
+ style={{
388
+ aspectRatio: imageAspectRatio,
389
+ flex: '0 1 auto' // 诪讗驻砖专 诇讛转讻讜讜抓 讗诐 爪专讬讱
390
+ }}
391
+ >
392
  {isAiProcessing && (
393
  <div className="absolute inset-0 z-50 bg-black/60 backdrop-blur-sm flex flex-col items-center justify-center text-white">
394
  <Sparkles className="w-12 h-12 animate-spin mb-4 text-brand-orange" />
 
397
  </div>
398
  )}
399
 
 
400
  <div
401
  ref={WebGLWrapperRef}
402
+ className="absolute inset-0 w-full h-full [&>canvas]:w-full [&>canvas]:h-full"
403
  />
404
 
 
405
  <canvas
406
  ref={drawingCanvasRef}
407
  onMouseDown={startDrawing}
 
411
  onTouchStart={startDrawing}
412
  onTouchMove={draw}
413
  onTouchEnd={stopDrawing}
414
+ className={`absolute inset-0 z-20 w-full h-full touch-none ${activeTab === 'paint' ? 'cursor-crosshair' : 'pointer-events-none'}`}
415
  />
416
  </div>
417
 
418
+ {/* 驻讜讟专 讟拽住讟 - 讞诇拽 诪讛诪住讙专转 讛诇讘谞讛 */}
419
+ <div className="w-full pt-4 pb-2 flex flex-col items-center justify-center text-center">
420
  <span className="text-gray-900 font-black text-sm md:text-base leading-tight">
421
  {frameText.title || '讟讜注谉...'}
422
  </span>