Changed around line 1
+ let stream;
+ let currentCamera = 'user';
+ const frames = [
+ 'url("data:image/svg+xml,%3Csvg width=\'100%25\' height=\'100%25\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Crect width=\'100%25\' height=\'100%25\' fill=\'none\' stroke=\'white\' stroke-width=\'4\' stroke-dasharray=\'20,20\' /%3E%3C/svg%3E")',
+ 'url("data:image/svg+xml,%3Csvg width=\'100%25\' height=\'100%25\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Crect width=\'100%25\' height=\'100%25\' fill=\'none\' stroke=\'gold\' stroke-width=\'8\' rx=\'20\' /%3E%3C/svg%3E")',
+ 'none'
+ ];
+ let currentFrame = 0;
+
+ async function initCamera() {
+ try {
+ stream = await navigator.mediaDevices.getUserMedia({
+ video: { facingMode: currentCamera }
+ });
+ document.getElementById('camera').srcObject = stream;
+ } catch (err) {
+ console.error('Camera error:', err);
+ alert('Unable to access camera. Please check permissions.');
+ }
+ }
+
+ function switchCamera() {
+ if (stream) {
+ stream.getTracks().forEach(track => track.stop());
+ currentCamera = currentCamera === 'user' ? 'environment' : 'user';
+ initCamera();
+ }
+ }
+
+ function capturePhoto() {
+ const video = document.getElementById('camera');
+ const canvas = document.getElementById('canvas');
+ const context = canvas.getContext('2d');
+
+ canvas.width = video.videoWidth;
+ canvas.height = video.videoHeight;
+
+ context.drawImage(video, 0, 0);
+
+ const frame = document.getElementById('frame-overlay');
+ if (frame.style.backgroundImage) {
+ context.drawImage(frame, 0, 0);
+ }
+
+ const photo = canvas.toDataURL('image/jpeg');
+ addToGallery(photo);
+ }
+
+ function addToGallery(photoUrl) {
+ const grid = document.getElementById('photosGrid');
+ const photoDiv = document.createElement('div');
+ photoDiv.className = 'photo-item';
+
+ const img = document.createElement('img');
+ img.src = photoUrl;
+ img.alt = 'Captured photo';
+
+ photoDiv.appendChild(img);
+ grid.insertBefore(photoDiv, grid.firstChild);
+ }
+
+ function changeFrame() {
+ currentFrame = (currentFrame + 1) % frames.length;
+ document.getElementById('frame-overlay').style.backgroundImage = frames[currentFrame];
+ }
+
+ function toggleTheme() {
+ document.body.classList.toggle('dark-mode');
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ initCamera();
+
+ document.getElementById('switchCamera').addEventListener('click', switchCamera);
+ document.getElementById('captureBtn').addEventListener('click', capturePhoto);
+ document.getElementById('frameBtn').addEventListener('click', changeFrame);
+ document.querySelector('.theme-toggle').addEventListener('click', toggleTheme);
+ });