Skip to content

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

fix: correct tool name from "videos" to "video" in type definitions and related functions feat: enhance macOS mockup with dynamic navigation icon visibility and improved URL bar handling

CristianOlivera1e840719bd0b3
diff --git a/hooks/useActiveTool.ts b/hooks/useActiveTool.ts
index 7ff163b..e15810a 100644
--- a/hooks/useActiveTool.ts
+++ b/hooks/useActiveTool.ts
@@ -11,7 +11,7 @@ const VALID_TOOLS: ReadonlySet<Tool> = new Set<Tool>([
"zoom",
"mockup",
"cursor",
- "videos",
+ "video",
"camera",
"history",
"motion",
@@ -29,11 +29,11 @@ export function useActiveTool(): [Tool, (next: Tool) => void] {
const pathname = usePathname();
const searchParams = useSearchParams();
- const tool = parseTool(searchParams.get("m"));
+ const tool = parseTool(searchParams.get("menu"));
const setTool = useCallback((next: Tool) => {
const params = new URLSearchParams(searchParams.toString());
- params.set("m", next);
+ params.set("menu", next);
router.replace(`${pathname}?${params.toString()}`);
}, [router, pathname, searchParams]);
diff --git a/lib/canvas.utils.ts b/lib/canvas.utils.ts
index a3984da..55e9faa 100644
--- a/lib/canvas.utils.ts
+++ b/lib/canvas.utils.ts
@@ -360,8 +360,4 @@ export function snapRotation(
return { angle: nearestSnap, snapped: true };
}
return { angle, snapped: false };
-}
-
-export function normalizeAngle(angle: number): number {
- return ((angle % 360) + 360) % 360;
}
\ No newline at end of file
diff --git a/lib/mockup-canvas/macos.ts b/lib/mockup-canvas/macos.ts
index 4c3d3a3..61bb766 100644
--- a/lib/mockup-canvas/macos.ts
+++ b/lib/mockup-canvas/macos.ts
@@ -16,11 +16,11 @@ import { drawRoundedRectPath, drawMockupShadow } from "./shared";
export function drawMacosMockup(context: MockupCanvasContext): MockupDrawResult {
const { ctx, x, y, width, height, config, cornerRadius, shadowBlur } = context;
+
const isDark = config.darkMode;
const frameColor = config.frameColor;
const url = config.url || "https://openvid.dev";
const headerOpacity = config.headerOpacity ?? 100;
-
const headerScale = (config.headerScale || 100) / 100;
const headerHeight = 36 * headerScale;
@@ -74,6 +74,25 @@ export function drawMacosMockup(context: MockupCanvasContext): MockupDrawResult
ctx.stroke();
ctx.restore();
+ const navGap = 6 * headerScale;
+ const trafficWidth = buttonLeftPadding + 3 * buttonSize + 2 * buttonGap;
+ const navWidth = iconSize * 3 + navGap * 2 + 6 * headerScale;
+ const leftToolsWidth = trafficWidth + navWidth;
+
+ const iconsRightPadding = 12 * headerScale;
+ const iconGap = 10 * headerScale;
+ const rightToolsWidth = iconSize * 4 + iconGap * 3 + iconsRightPadding;
+
+ let showNavIcons = true;
+ let showRightIcons = true;
+
+ if (width < leftToolsWidth + rightToolsWidth + 100 * headerScale) {
+ showRightIcons = false;
+ }
+ if (width < trafficWidth + navWidth + 50 * headerScale) {
+ showNavIcons = false;
+ }
+
const buttonY = y + (headerHeight - buttonSize) / 2;
const buttons = [
{ color: "#FF5F56", border: "#E0443E" },
@@ -94,61 +113,89 @@ export function drawMacosMockup(context: MockupCanvasContext): MockupDrawResult
ctx.restore();
});
- const navStartX = x + buttonLeftPadding + 3 * (buttonSize + buttonGap) + buttonGap * 2;
const iconY = y + (headerHeight - iconSize) / 2;
- const navGap = 6 * headerScale;
+ if (showNavIcons) {
+ const navStartX = x + trafficWidth + navGap;
+ drawMenuIcon(ctx, navStartX, iconY, iconSize, iconColor);
+ const chevronStartX = navStartX + iconSize + navGap;
+ drawChevronLeft(ctx, chevronStartX, iconY, iconSize, iconColor);
+ drawChevronRight(ctx, chevronStartX + iconSize + 6 * headerScale, iconY, iconSize, iconColor);
+ }
- drawMenuIcon(ctx, navStartX, iconY, iconSize, iconColor);
+ const maxUrlBarWidth = 576 * headerScale;
+ const idealUrlBarWidth = Math.min(width * 0.5, maxUrlBarWidth);
+ const urlBarX = x + (width - idealUrlBarWidth) / 2;
- const chevronStartX = navStartX + iconSize + navGap;
- drawChevronLeft(ctx, chevronStartX, iconY, iconSize, iconColor);
- drawChevronRight(ctx, chevronStartX + iconSize + 6 * headerScale, iconY, iconSize, iconColor);
+ const urlBoundLeft = x + trafficWidth + (showNavIcons ? navWidth : 0) + 16 * headerScale;
+ const urlBoundRight = x + width - (showRightIcons ? rightToolsWidth : 0) - 16 * headerScale;
+ const availableUrlSpace = urlBoundRight - urlBoundLeft;
+
+ let finalUrlBarWidth = idealUrlBarWidth;
+ let finalUrlBarX = urlBarX;
+
+ if (finalUrlBarX < urlBoundLeft || (finalUrlBarX + finalUrlBarWidth) > urlBoundRight) {
+ finalUrlBarWidth = Math.min(availableUrlSpace, maxUrlBarWidth);
+ finalUrlBarX = urlBoundLeft + Math.max(0, availableUrlSpace - finalUrlBarWidth) / 2;
+ }
+
+ finalUrlBarWidth = Math.max(finalUrlBarWidth, 40 * headerScale);
- const maxUrlBarWidth = 576 * headerScale;
- const urlBarWidth = Math.min(width * 0.5, maxUrlBarWidth);
- const urlBarX = x + (width - urlBarWidth) / 2;
const urlBarY = y + (headerHeight - urlBarHeight) / 2;
const urlBarPadding = 8 * headerScale;
-
const urlBarBgBase = deriveSearchBg(frameColor);
ctx.save();
- drawRoundedRectPath(ctx, urlBarX, urlBarY, urlBarWidth, urlBarHeight, 4 * headerScale);
+ drawRoundedRectPath(ctx, finalUrlBarX, urlBarY, finalUrlBarWidth, urlBarHeight, 4 * headerScale);
ctx.fillStyle = hexToRgba(urlBarBgBase, headerOpacity);
ctx.fill();
ctx.restore();
const lockIconSize = buttonSize;
- const lockIconX = urlBarX + urlBarPadding;
+ const lockIconX = finalUrlBarX + urlBarPadding;
const lockIconY = urlBarY + (urlBarHeight - lockIconSize) / 2;
- drawLockIcon(ctx, lockIconX, lockIconY, lockIconSize, iconColor + "99");
- ctx.save();
- ctx.font = `${fontSize}px "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;
- ctx.fillStyle = textColor;
- ctx.textAlign = "center";
- ctx.textBaseline = "middle";
- const displayUrl = url.replace(/^https?:\/\//, "").substring(0, 40);
- ctx.fillText(displayUrl, urlBarX + urlBarWidth / 2, urlBarY + urlBarHeight / 2);
- ctx.restore();
+ if (finalUrlBarWidth > 50 * headerScale) {
+ drawLockIcon(ctx, lockIconX, lockIconY, lockIconSize, iconColor + "99");
+ }
const refreshIconSize = buttonSize;
- const refreshIconX = urlBarX + urlBarWidth - urlBarPadding - refreshIconSize;
+ const refreshIconX = finalUrlBarX + finalUrlBarWidth - urlBarPadding - refreshIconSize;
const refreshIconY = urlBarY + (urlBarHeight - refreshIconSize) / 2;
- drawRefreshIcon(ctx, refreshIconX, refreshIconY, refreshIconSize, iconColor + "99");
- const iconsRightPadding = 12 * headerScale;
- const iconGap = 10 * headerScale;
+ if (finalUrlBarWidth > 75 * headerScale) {
+ drawRefreshIcon(ctx, refreshIconX, refreshIconY, refreshIconSize, iconColor + "99");
+ }
+
+ if (finalUrlBarWidth > 90 * headerScale) {
+ ctx.save();
+ ctx.font = `${fontSize}px "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;
+ ctx.fillStyle = textColor;
+ ctx.textAlign = "center";
+ ctx.textBaseline = "middle";
+
+ const displayUrl = url.replace(/^https?:\/\//, "").substring(0, 40);
+
+ ctx.beginPath();
+ const textClipX = finalUrlBarX + lockIconSize + urlBarPadding + 4 * headerScale;
+ const textClipWidth = finalUrlBarWidth - lockIconSize - refreshIconSize - urlBarPadding * 2 - 8 * headerScale;
+ ctx.rect(textClipX, urlBarY, Math.max(0, textClipWidth), urlBarHeight);
+ ctx.clip();
+
+ ctx.fillText(displayUrl, finalUrlBarX + finalUrlBarWidth / 2, urlBarY + urlBarHeight / 2);
+ ctx.restore();
+ }
- const copyIconX = x + width - iconsRightPadding - iconSize;
- const plusIconX = copyIconX - iconSize - iconGap;
- const uploadIconX = plusIconX - iconSize - iconGap;
- const downloadIconX = uploadIconX - iconSize - iconGap;
+ if (showRightIcons) {
+ const copyIconX = x + width - iconsRightPadding - iconSize;
+ const plusIconX = copyIconX - iconSize - iconGap;
+ const uploadIconX = plusIconX - iconSize - iconGap;
+ const downloadIconX = uploadIconX - iconSize - iconGap;
- drawCopyIcon(ctx, copyIconX, iconY, iconSize, iconColor);
- drawPlusIcon(ctx, plusIconX, iconY, iconSize, iconColor);
- drawUploadIcon(ctx, uploadIconX, iconY, iconSize, iconColor);
- drawDownloadIcon(ctx, downloadIconX, iconY, iconSize, iconColor);
+ drawCopyIcon(ctx, copyIconX, iconY, iconSize, iconColor);
+ drawPlusIcon(ctx, plusIconX, iconY, iconSize, iconColor);
+ drawUploadIcon(ctx, uploadIconX, iconY, iconSize, iconColor);
+ drawDownloadIcon(ctx, downloadIconX, iconY, iconSize, iconColor);
+ }
return {
contentX: x,
@@ -156,4 +203,4 @@ export function drawMacosMockup(context: MockupCanvasContext): MockupDrawResult
contentWidth: width,
contentHeight: height - headerHeight,
};
-}
+}
\ No newline at end of file
diff --git a/lib/mockup-data.tsx b/lib/mockup-data.tsx
index d775115..18d3c07 100644
--- a/lib/mockup-data.tsx
+++ b/lib/mockup-data.tsx
@@ -409,7 +409,7 @@ export const MOCKUPS: Mockup[] = [
},
{
id: "macos-dark-ide",
- name: "VS CODE Dark",
+ name: "VS CODE macos",
category: "ide",
features: {
hasDarkMode: true,
diff --git a/types/editor.types.ts b/types/editor.types.ts
index eb35c66..6b4f82d 100644
--- a/types/editor.types.ts
+++ b/types/editor.types.ts
@@ -2,7 +2,7 @@ import type { ZoomFragment } from "./zoom.types";
import type { CanvasElement } from "./canvas-elements.types";
import type { CursorConfig, CursorRecordingData } from "./cursor.types";
-export type Tool = "screenshot" | "elements" | "audio" | "zoom" | "mockup" | "cursor" | "videos" | "camera" | "history" | "motion";
+export type Tool = "screenshot" | "elements" | "audio" | "zoom" | "mockup" | "cursor" | "video" | "camera" | "history" | "motion";
export type BackgroundTab = "wallpaper" | "image" | "color";