Tina Tarighian
commited on
Commit
·
3fdfac3
1
Parent(s):
987ec04
fix
Browse files- components/CameraSetup.js +10 -18
- components/HandDetector.js +2 -2
- components/MainContent.js +2 -6
- components/PromptEditor.js +1 -1
- hooks/useDeviceAndCanvas.js +5 -28
- pages/index.js +1 -1
- styles/globals.css +0 -29
components/CameraSetup.js
CHANGED
|
@@ -35,19 +35,15 @@ const CameraSetup = ({
|
|
| 35 |
tracks.forEach(track => track.stop());
|
| 36 |
}
|
| 37 |
|
| 38 |
-
//
|
| 39 |
-
const
|
| 40 |
-
video: {
|
| 41 |
facingMode: facingMode,
|
| 42 |
-
width: { ideal:
|
| 43 |
-
height: { ideal:
|
| 44 |
-
aspectRatio: isMobile ? { ideal: 4/3 } : undefined // Prefer 4:3 on mobile
|
| 45 |
},
|
| 46 |
audio: false
|
| 47 |
-
};
|
| 48 |
-
|
| 49 |
-
// Get camera stream
|
| 50 |
-
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
| 51 |
|
| 52 |
// Check if component is still mounted before continuing
|
| 53 |
if (!isMounted.current) {
|
|
@@ -75,9 +71,6 @@ const CameraSetup = ({
|
|
| 75 |
const videoWidth = videoRef.current.videoWidth;
|
| 76 |
const videoHeight = videoRef.current.videoHeight;
|
| 77 |
const aspectRatio = videoWidth / videoHeight;
|
| 78 |
-
|
| 79 |
-
console.log(`Camera dimensions: ${videoWidth}x${videoHeight}, aspect ratio: ${aspectRatio}`);
|
| 80 |
-
|
| 81 |
setVideoAspectRatio(aspectRatio);
|
| 82 |
|
| 83 |
// Update canvas size with the correct aspect ratio
|
|
@@ -110,7 +103,7 @@ const CameraSetup = ({
|
|
| 110 |
tracks.forEach(track => track.stop());
|
| 111 |
}
|
| 112 |
};
|
| 113 |
-
}, [videoRef, canvasRef, containerRef, facingMode, setCameraError, setVideoAspectRatio, updateCanvasSize
|
| 114 |
|
| 115 |
// Function to switch camera
|
| 116 |
const switchCamera = async () => {
|
|
@@ -133,9 +126,8 @@ const CameraSetup = ({
|
|
| 133 |
const stream = await navigator.mediaDevices.getUserMedia({
|
| 134 |
video: {
|
| 135 |
facingMode: newFacingMode,
|
| 136 |
-
width: { ideal:
|
| 137 |
-
height: { ideal:
|
| 138 |
-
aspectRatio: isMobile ? { ideal: 4/3 } : undefined
|
| 139 |
},
|
| 140 |
audio: false
|
| 141 |
});
|
|
@@ -193,7 +185,7 @@ const CameraSetup = ({
|
|
| 193 |
<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 text-gray-800" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 194 |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z" />
|
| 195 |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 13a3 3 0 11-6 0 3 3 0 016 0z" />
|
| 196 |
-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="
|
| 197 |
</svg>
|
| 198 |
</button>
|
| 199 |
)}
|
|
|
|
| 35 |
tracks.forEach(track => track.stop());
|
| 36 |
}
|
| 37 |
|
| 38 |
+
// Get camera stream
|
| 39 |
+
const stream = await navigator.mediaDevices.getUserMedia({
|
| 40 |
+
video: {
|
| 41 |
facingMode: facingMode,
|
| 42 |
+
width: { ideal: 1920 },
|
| 43 |
+
height: { ideal: 1080 }
|
|
|
|
| 44 |
},
|
| 45 |
audio: false
|
| 46 |
+
});
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
// Check if component is still mounted before continuing
|
| 49 |
if (!isMounted.current) {
|
|
|
|
| 71 |
const videoWidth = videoRef.current.videoWidth;
|
| 72 |
const videoHeight = videoRef.current.videoHeight;
|
| 73 |
const aspectRatio = videoWidth / videoHeight;
|
|
|
|
|
|
|
|
|
|
| 74 |
setVideoAspectRatio(aspectRatio);
|
| 75 |
|
| 76 |
// Update canvas size with the correct aspect ratio
|
|
|
|
| 103 |
tracks.forEach(track => track.stop());
|
| 104 |
}
|
| 105 |
};
|
| 106 |
+
}, [videoRef, canvasRef, containerRef, facingMode, setCameraError, setVideoAspectRatio, updateCanvasSize]);
|
| 107 |
|
| 108 |
// Function to switch camera
|
| 109 |
const switchCamera = async () => {
|
|
|
|
| 126 |
const stream = await navigator.mediaDevices.getUserMedia({
|
| 127 |
video: {
|
| 128 |
facingMode: newFacingMode,
|
| 129 |
+
width: { ideal: 1920 },
|
| 130 |
+
height: { ideal: 1080 }
|
|
|
|
| 131 |
},
|
| 132 |
audio: false
|
| 133 |
});
|
|
|
|
| 185 |
<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 text-gray-800" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 186 |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z" />
|
| 187 |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 13a3 3 0 11-6 0 3 3 0 016 0z" />
|
| 188 |
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M14.5 7.5L9.5 12.5" />
|
| 189 |
</svg>
|
| 190 |
</button>
|
| 191 |
)}
|
components/HandDetector.js
CHANGED
|
@@ -12,8 +12,8 @@ const HandDetector = () => {
|
|
| 12 |
const canvasRef = useRef(null);
|
| 13 |
const containerRef = useRef(null);
|
| 14 |
|
| 15 |
-
// Camera state
|
| 16 |
-
const [facingMode, setFacingMode] = useState('
|
| 17 |
const [cameraError, setCameraError] = useState(false);
|
| 18 |
|
| 19 |
// Prompt state
|
|
|
|
| 12 |
const canvasRef = useRef(null);
|
| 13 |
const containerRef = useRef(null);
|
| 14 |
|
| 15 |
+
// Camera state
|
| 16 |
+
const [facingMode, setFacingMode] = useState('user'); // 'user' for front camera, 'environment' for back camera
|
| 17 |
const [cameraError, setCameraError] = useState(false);
|
| 18 |
|
| 19 |
// Prompt state
|
components/MainContent.js
CHANGED
|
@@ -59,12 +59,8 @@ const MainContent = ({
|
|
| 59 |
{/* Canvas for hand detection */}
|
| 60 |
<canvas
|
| 61 |
ref={canvasRef}
|
| 62 |
-
className="rounded-lg shadow-lg w-full
|
| 63 |
-
style={{
|
| 64 |
-
height: `${canvasHeight}px`,
|
| 65 |
-
maxHeight: isMobile ? '70vh' : 'none',
|
| 66 |
-
objectFit: 'contain'
|
| 67 |
-
}}
|
| 68 |
width={canvasWidth}
|
| 69 |
height={canvasHeight}
|
| 70 |
/>
|
|
|
|
| 59 |
{/* Canvas for hand detection */}
|
| 60 |
<canvas
|
| 61 |
ref={canvasRef}
|
| 62 |
+
className="rounded-lg shadow-lg w-full"
|
| 63 |
+
style={{ height: `${canvasHeight}px` }}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
width={canvasWidth}
|
| 65 |
height={canvasHeight}
|
| 66 |
/>
|
components/PromptEditor.js
CHANGED
|
@@ -66,7 +66,7 @@ const PromptEditor = ({ customPrompt, setCustomPrompt, isMac }) => {
|
|
| 66 |
</div>
|
| 67 |
</div>
|
| 68 |
) : (
|
| 69 |
-
<div className="p-3 bg-gray-50 border border-gray-200 rounded-lg text-
|
| 70 |
{customPrompt}
|
| 71 |
</div>
|
| 72 |
)}
|
|
|
|
| 66 |
</div>
|
| 67 |
</div>
|
| 68 |
) : (
|
| 69 |
+
<div className="p-3 bg-gray-50 border border-gray-200 rounded-lg text-sm text-gray-800 whitespace-pre-wrap">
|
| 70 |
{customPrompt}
|
| 71 |
</div>
|
| 72 |
)}
|
hooks/useDeviceAndCanvas.js
CHANGED
|
@@ -43,35 +43,12 @@ const useDeviceAndCanvas = () => {
|
|
| 43 |
if (!isComponentMounted.current) return;
|
| 44 |
|
| 45 |
const containerWidth = document.querySelector('.canvas-container')?.clientWidth || window.innerWidth;
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
if (isMobile) {
|
| 50 |
-
// On mobile, use a smaller canvas size to prevent it from being too tall
|
| 51 |
-
maxWidth = Math.min(containerWidth, 400);
|
| 52 |
-
|
| 53 |
-
// Ensure we maintain the correct aspect ratio
|
| 54 |
-
// For mobile, we want to ensure the height isn't too tall
|
| 55 |
-
// Most phone cameras have aspect ratios around 4:3 or 16:9
|
| 56 |
-
// If the aspect ratio is very wide or very tall, we'll normalize it
|
| 57 |
-
let normalizedAspectRatio = aspectRatio;
|
| 58 |
-
|
| 59 |
-
// If aspect ratio is extreme, normalize it to prevent stretching
|
| 60 |
-
if (aspectRatio < 0.5) normalizedAspectRatio = 0.5; // Very tall
|
| 61 |
-
if (aspectRatio > 2) normalizedAspectRatio = 2; // Very wide
|
| 62 |
-
|
| 63 |
-
const height = maxWidth / normalizedAspectRatio;
|
| 64 |
-
|
| 65 |
-
setCanvasWidth(maxWidth);
|
| 66 |
-
setCanvasHeight(height);
|
| 67 |
-
} else {
|
| 68 |
-
// On desktop, use a larger canvas size
|
| 69 |
-
maxWidth = Math.min(containerWidth, 960);
|
| 70 |
-
const height = maxWidth / aspectRatio;
|
| 71 |
-
|
| 72 |
-
setCanvasWidth(maxWidth);
|
| 73 |
-
setCanvasHeight(height);
|
| 74 |
-
}
|
| 75 |
}, [isMobile]);
|
| 76 |
|
| 77 |
return {
|
|
|
|
| 43 |
if (!isComponentMounted.current) return;
|
| 44 |
|
| 45 |
const containerWidth = document.querySelector('.canvas-container')?.clientWidth || window.innerWidth;
|
| 46 |
+
// Set maximum width for the canvas - increased for desktop
|
| 47 |
+
const maxWidth = Math.min(containerWidth, isMobile ? 640 : 960);
|
| 48 |
+
const height = maxWidth / aspectRatio;
|
| 49 |
|
| 50 |
+
setCanvasWidth(maxWidth);
|
| 51 |
+
setCanvasHeight(height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
}, [isMobile]);
|
| 53 |
|
| 54 |
return {
|
pages/index.js
CHANGED
|
@@ -47,7 +47,7 @@ export default function Home() {
|
|
| 47 |
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap" />
|
| 48 |
</Head>
|
| 49 |
<Header />
|
| 50 |
-
<main className="flex min-h-screen flex-col items-center justify-
|
| 51 |
<HandDetector />
|
| 52 |
</main>
|
| 53 |
</>
|
|
|
|
| 47 |
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap" />
|
| 48 |
</Head>
|
| 49 |
<Header />
|
| 50 |
+
<main className="flex min-h-screen flex-col items-center justify-center p-4 bg-white font-['Google_Sans',sans-serif] pt-20">
|
| 51 |
<HandDetector />
|
| 52 |
</main>
|
| 53 |
</>
|
styles/globals.css
CHANGED
|
@@ -16,39 +16,10 @@
|
|
| 16 |
}
|
| 17 |
}
|
| 18 |
|
| 19 |
-
html, body {
|
| 20 |
-
height: 100%;
|
| 21 |
-
overflow-x: hidden;
|
| 22 |
-
overflow-y: auto;
|
| 23 |
-
-webkit-overflow-scrolling: touch;
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
body {
|
| 27 |
color: var(--foreground);
|
| 28 |
background: var(--background);
|
| 29 |
font-family: 'Google Sans', Arial, Helvetica, sans-serif;
|
| 30 |
-
position: relative;
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
/* Canvas container styling */
|
| 34 |
-
.canvas-container {
|
| 35 |
-
display: flex;
|
| 36 |
-
justify-content: center;
|
| 37 |
-
align-items: center;
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
.canvas-container canvas {
|
| 41 |
-
object-fit: contain;
|
| 42 |
-
max-width: 100%;
|
| 43 |
-
height: auto;
|
| 44 |
-
aspect-ratio: auto;
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
/* Prevent stretching on mobile */
|
| 48 |
-
@media (max-width: 767px) {
|
| 49 |
-
.canvas-container canvas {
|
| 50 |
-
max-height: 70vh;
|
| 51 |
-
}
|
| 52 |
}
|
| 53 |
|
| 54 |
/* Minimal thought bubble styling */
|
|
|
|
| 16 |
}
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
body {
|
| 20 |
color: var(--foreground);
|
| 21 |
background: var(--background);
|
| 22 |
font-family: 'Google Sans', Arial, Helvetica, sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
|
| 25 |
/* Minimal thought bubble styling */
|