Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat: update default wallpaper selection and add camera overlay utility functions

CristianOlivera1c41a7dc5a947
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsx
index 2310497..b941727 100644
--- a/app/[locale]/(editor)/editor/page.tsx
+++ b/app/[locale]/(editor)/editor/page.tsx
@@ -153,7 +153,7 @@ export default function Editor() {
const [activeTool, setActiveTool] = useActiveTool();
const [elementsTextTabTrigger] = useState(0);
const [backgroundTab, setBackgroundTab] = useState<BackgroundTab>("wallpaper");
- const [selectedWallpaper, setSelectedWallpaper] = useState(0);
+ const [selectedWallpaper, setSelectedWallpaper] = useState(8);
const [backgroundBlur, setBackgroundBlur] = useState(0);
const [padding, setPadding] = useState(10);
const [roundedCorners, setRoundedCorners] = useState(10);
@@ -508,7 +508,7 @@ export default function Editor() {
setImageDimensions(null);
// Reset to default state
setBackgroundTab("wallpaper");
- setSelectedWallpaper(0);
+ setSelectedWallpaper(8);
setBackgroundBlur(0);
setPadding(10);
setRoundedCorners(10);
diff --git a/lib/camera-overlay.utils.ts b/lib/camera-overlay.utils.ts
new file mode 100644
index 0000000..b6fb8d2
--- /dev/null
+++ b/lib/camera-overlay.utils.ts
@@ -0,0 +1,96 @@
+import { getCameraLayout } from "@/types/camera.types";
+import type { CameraConfig } from "@/types/camera.types";
+import { drawRoundedRect } from "@/lib/canvas.utils";
+
+export async function drawCameraOverlayToCtx(
+ ctx: CanvasRenderingContext2D,
+ canvasWidth: number,
+ canvasHeight: number,
+ camVideo: HTMLVideoElement | null,
+ mainVideo: HTMLVideoElement | null,
+ cameraConfig: CameraConfig | null,
+) {
+ if (!camVideo || !cameraConfig || !cameraConfig.enabled) return;
+ if (!camVideo.videoWidth || !camVideo.videoHeight) return;
+
+ if (mainVideo && camVideo.paused) {
+ const targetTime = Math.min(mainVideo.currentTime, Math.max(0, camVideo.duration - 0.1));
+ if (Math.abs(camVideo.currentTime - targetTime) > 0.05) {
+ try {
+ camVideo.currentTime = targetTime;
+ await new Promise<void>((resolve) => {
+ const timeoutId = setTimeout(() => {
+ camVideo.removeEventListener("seeked", onSeeked);
+ resolve();
+ }, 2000);
+ const onSeeked = () => {
+ camVideo.removeEventListener("seeked", onSeeked);
+ const checkReady = setInterval(() => {
+ if (camVideo.readyState >= 2) {
+ clearInterval(checkReady);
+ clearTimeout(timeoutId);
+ resolve();
+ }
+ }, 10);
+ };
+ camVideo.addEventListener("seeked", onSeeked);
+ });
+ } catch (e) {
+ console.warn("Error en seek de la cámara:", e);
+ }
+ }
+ }
+
+ const { size, left: drawX, top: drawY } = getCameraLayout(cameraConfig, canvasWidth, canvasHeight);
+ if (size <= 0) return;
+
+ const shortSide = Math.min(canvasWidth, canvasHeight);
+ const sizePercent = cameraConfig.size * 100;
+ const sizeMultiplier = 0.5 + (sizePercent - 20) / 40;
+
+ const srcShort = Math.min(camVideo.videoWidth, camVideo.videoHeight);
+ const sx = (camVideo.videoWidth - srcShort) / 2;
+ const sy = (camVideo.videoHeight - srcShort) / 2;
+
+ ctx.save();
+ ctx.shadowColor = "rgba(0, 0, 0, 0.55)";
+ ctx.shadowBlur = shortSide * 0.02;
+ ctx.shadowOffsetY = shortSide * 0.008;
+
+ if (cameraConfig.shape === "circle") {
+ const centerX = drawX + size / 2;
+ const centerY = drawY + size / 2;
+ const radius = size / 2;
+ ctx.beginPath();
+ ctx.arc(centerX, centerY, radius, 0, Math.PI * 2);
+ ctx.fill();
+ ctx.shadowColor = "transparent";
+ ctx.shadowBlur = 0;
+ ctx.shadowOffsetY = 0;
+ ctx.beginPath();
+ ctx.arc(centerX, centerY, radius, 0, Math.PI * 2);
+ ctx.clip();
+ } else {
+ const radius = cameraConfig.shape === "squircle"
+ ? Math.round(85 * sizeMultiplier)
+ : Math.round(6 * sizeMultiplier);
+ drawRoundedRect(ctx, drawX, drawY, size, size, radius);
+ ctx.fill();
+ ctx.shadowColor = "transparent";
+ ctx.shadowBlur = 0;
+ ctx.shadowOffsetY = 0;
+ drawRoundedRect(ctx, drawX, drawY, size, size, radius);
+ ctx.clip();
+ }
+
+ if (camVideo.readyState >= 2) {
+ if (cameraConfig.mirror) {
+ ctx.translate(drawX + size, drawY);
+ ctx.scale(-1, 1);
+ ctx.drawImage(camVideo, sx, sy, srcShort, srcShort, 0, 0, size, size);
+ } else {
+ ctx.drawImage(camVideo, sx, sy, srcShort, srcShort, drawX, drawY, size, size);
+ }
+ }
+ ctx.restore();
+}
\ No newline at end of file
diff --git a/lib/wallpaper.utils.ts b/lib/wallpaper.utils.ts
index cd6bd39..9843fc3 100644
--- a/lib/wallpaper.utils.ts
+++ b/lib/wallpaper.utils.ts
@@ -3,9 +3,4 @@ import { getWallpaperByIndex } from './wallpaper.catalog';
export function getWallpaperUrl(index: number): string {
if (index < 0) return "";
return getWallpaperByIndex(index)?.fullUrl ?? "";
-}
-
-export function getWallpaperPreviewUrl(index: number): string {
- if (index < 0) return "";
- return getWallpaperByIndex(index)?.previewUrl ?? "";
-}
+}
\ No newline at end of file
diff --git a/public/images/backgrounds/desktop/desktop-09.avif b/public/images/backgrounds/desktop/desktop-09.avif
index 5c098ff..0776a5a 100644
Binary files a/public/images/backgrounds/desktop/desktop-09.avif and b/public/images/backgrounds/desktop/desktop-09.avif differ
diff --git a/public/images/backgrounds/desktop/desktop-09.jpg b/public/images/backgrounds/desktop/desktop-09.jpg
index 209b831..9aa4f51 100644
Binary files a/public/images/backgrounds/desktop/desktop-09.jpg and b/public/images/backgrounds/desktop/desktop-09.jpg differ
diff --git a/public/images/backgrounds/desktop/desktop-75.avif b/public/images/backgrounds/desktop/desktop-75.avif
index 0776a5a..5c098ff 100644
Binary files a/public/images/backgrounds/desktop/desktop-75.avif and b/public/images/backgrounds/desktop/desktop-75.avif differ
diff --git a/public/images/backgrounds/desktop/desktop-75.jpg b/public/images/backgrounds/desktop/desktop-75.jpg
index 9aa4f51..209b831 100644
Binary files a/public/images/backgrounds/desktop/desktop-75.jpg and b/public/images/backgrounds/desktop/desktop-75.jpg differ