Skip to content

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

Refactor MacOS Glass Mockup and Canvas Utilities

CristianOlivera11a39faf263f3
diff --git a/app/components/ui/editor/mockups/MacosGlassMockup.tsx b/app/components/ui/editor/mockups/MacosGlassMockup.tsx
index bd7b969..78f22e2 100644
--- a/app/components/ui/editor/mockups/MacosGlassMockup.tsx
+++ b/app/components/ui/editor/mockups/MacosGlassMockup.tsx
@@ -5,140 +5,144 @@ import { hexToRgba } from "@/lib/utils";
import { deriveSearchBg } from "@/lib/color.utils";
interface MacosMockupProps extends MockupRenderProps {
- shadows?: number;
- roundedCorners?: number;
+ shadows?: number;
+ roundedCorners?: number;
}
export function MacosGlassMockup({
- children,
- config,
- className = "",
- shadows = 20,
- roundedCorners,
- maskStyles,
+ children,
+ config,
+ className = "",
+ shadows = 20,
+ roundedCorners,
+ maskStyles,
}: MacosMockupProps) {
- const isDark = config.darkMode;
- const frameColor = config.frameColor;
- const url = config.url;
- const cornerRadius = roundedCorners ?? config.cornerRadius;
+ const isDark = config.darkMode;
+ const frameColor = config.frameColor;
+ const url = config.url;
+ const cornerRadius = roundedCorners ?? config.cornerRadius;
- const headerOpacity = config.headerOpacity ?? 100;
- const headerScale = (config.headerScale || 100) / 100;
+ const headerOpacity = config.headerOpacity ?? 100;
+ const headerScale = (config.headerScale || 100) / 100;
- const bgColor = isDark ? "#1e1e1e" : "#f9f9f9";
- const borderColor = isDark ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)";
- const textColor = isDark ? "#9ca3af" : "#6b7280";
- const urlBarBorder = isDark ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.15)";
- const urlBarBgBase = deriveSearchBg(frameColor);
+ const bgColor = isDark ? "#1e1e1e" : "#f9f9f9";
+ const borderColor = isDark ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)";
+ const textColor = isDark ? "#9ca3af" : "#6b7280";
+ const urlBarBorder = isDark ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.15)";
+ const urlBarBgBase = deriveSearchBg(frameColor);
- const baseHeight = 36;
- const basePadding = 12;
- const baseGap = 12;
- const baseButtonSize = 10;
- const baseIconSize = 14;
- const baseUrlBarHeight = 24;
- const baseFontSize = 12;
+ const baseHeight = 36;
+ const basePadding = 12;
+ const baseGap = 12;
+ const baseButtonSize = 10;
+ const baseIconSize = 14;
+ const baseUrlBarHeight = 24;
+ const baseFontSize = 12;
- const headerHeight = baseHeight * headerScale;
- const headerPadding = basePadding * headerScale;
- const buttonGroupGap = 6 * headerScale;
- const navGap = 6 * headerScale;
- const buttonSize = baseButtonSize * headerScale;
- const iconSize = baseIconSize * headerScale;
- const urlBarHeight = baseUrlBarHeight * headerScale;
- const fontSize = baseFontSize * headerScale;
- const urlBarPadding = 8 * headerScale;
- const urlBarMargin = 16 * headerScale;
- const rightGroupGap = 10 * headerScale;
+ const headerHeight = baseHeight * headerScale;
+ const headerPadding = basePadding * headerScale;
+ const buttonGroupGap = 6 * headerScale;
+ const navGap = 6 * headerScale;
+ const buttonSize = baseButtonSize * headerScale;
+ const iconSize = baseIconSize * headerScale;
+ const urlBarHeight = baseUrlBarHeight * headerScale;
+ const fontSize = baseFontSize * headerScale;
+ const urlBarPadding = 8 * headerScale;
+ const urlBarMargin = 16 * headerScale;
+ const rightGroupGap = 10 * headerScale;
- return (
- <div className={`relative w-full h-full ${className}`}>
- <div
- className="absolute inset-0 pointer-events-none"
- style={{
- borderRadius: `${cornerRadius}px`,
- boxShadow: shadows > 0 ? `0 ${shadows * 0.3}px ${shadows}px rgba(0,0,0,1)` : 'none',
- }}
- />
+ return (
+ <div className={`relative w-full h-full flex flex-col ${className}`}>
+
+ {/* Capa de Sombra interna (evita oscurecer el borde glass exterior) */}
+ <div
+ className="absolute pointer-events-none"
+ style={{
+ top: '7px', left: '7px', right: '7px', bottom: '7px',
+ borderRadius: `${Math.max(0, cornerRadius + 4)}px`,
+ boxShadow: shadows > 0 ? `0 ${shadows * 0.3}px ${shadows}px rgba(0,0,0,1)` : 'none',
+ }}
+ />
+
+ {/* Capa principal */}
+ <div
+ className="relative w-full h-full overflow-hidden"
+ style={{
+ ...maskStyles,
+ borderRadius: `${cornerRadius}px`,
+ }}
+ >
+ <div
+ className="glass-border w-full h-full flex flex-col overflow-hidden relative z-10"
+ style={{
+ borderRadius: `${cornerRadius}px`,
+ borderTop: "1px solid rgba(255,255,255,0.6)",
+ borderLeft: "1px solid rgba(255,255,255,0.6)",
+ }}
+ >
+ <div
+ className="flex items-center justify-between select-none shrink-0"
+ style={{
+ height: `${headerHeight}px`,
+ padding: `0 ${headerPadding}px`,
+ backgroundColor: hexToRgba(frameColor, headerOpacity),
+ borderBottom: `1px solid ${borderColor}`,
+ borderTopLeftRadius: `${Math.max(0, cornerRadius - 4)}px`,
+ borderTopRightRadius: `${Math.max(0, cornerRadius - 4)}px`,
+ }}
+ >
+ <div className="flex items-center" style={{ gap: `${baseGap * headerScale}px` }}>
+ <div className="flex" style={{ gap: `${buttonGroupGap}px` }}>
+ <div className="rounded-full bg-[#FF5F56] border border-[#E0443E]" style={{ width: `${buttonSize}px`, height: `${buttonSize}px` }} />
+ <div className="rounded-full bg-[#FFBD2E] border border-[#DEA123]" style={{ width: `${buttonSize}px`, height: `${buttonSize}px` }} />
+ <div className="rounded-full bg-[#27C93F] border border-[#1AAB29]" style={{ width: `${buttonSize}px`, height: `${buttonSize}px` }} />
+ </div>
+ <div className="flex items-center" style={{ gap: `${navGap}px`, color: textColor }}>
+ <Icon icon="mdi:menu" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
+ <Icon icon="mdi:chevron-left" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
+ <Icon icon="mdi:chevron-right" className="opacity-40" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
+ </div>
+ </div>
- <div
- className="relative w-full h-full overflow-hidden"
+ <div className="flex-1 max-w-xl" style={{ margin: `0 ${urlBarMargin}px` }}>
+ <div
+ className="rounded w-full flex items-center justify-between"
style={{
- ...maskStyles,
- borderRadius: `${cornerRadius}px`,
+ height: `${urlBarHeight}px`,
+ padding: `0 ${urlBarPadding}px`,
+ backgroundColor: hexToRgba(urlBarBgBase, headerOpacity),
+ border: `1px solid ${urlBarBorder}`,
+ color: textColor,
}}
- >
- <div
- className="glass-border w-full h-full flex flex-col overflow-hidden"
- style={{
- borderRadius: `${cornerRadius}px`,
- borderTop: "1px solid rgba(255,255,255,0.6)",
- borderLeft: "1px solid rgba(255,255,255,0.6)",
- }}
- >
- <div
- className="flex items-center justify-between select-none shrink-0"
- style={{
- height: `${headerHeight}px`,
- padding: `0 ${headerPadding}px`,
- backgroundColor: hexToRgba(frameColor, headerOpacity),
- borderBottom: `1px solid ${borderColor}`,
- borderTopLeftRadius: `${cornerRadius}px`,
- borderTopRightRadius: `${cornerRadius}px`,
- }}
- >
- <div className="flex items-center" style={{ gap: `${baseGap * headerScale}px` }}>
- <div className="flex" style={{ gap: `${buttonGroupGap}px` }}>
- <div className="rounded-full bg-[#FF5F56] border border-[#E0443E]" style={{ width: `${buttonSize}px`, height: `${buttonSize}px` }} />
- <div className="rounded-full bg-[#FFBD2E] border border-[#DEA123]" style={{ width: `${buttonSize}px`, height: `${buttonSize}px` }} />
- <div className="rounded-full bg-[#27C93F] border border-[#1AAB29]" style={{ width: `${buttonSize}px`, height: `${buttonSize}px` }} />
- </div>
- <div className="flex items-center" style={{ gap: `${navGap}px`, color: textColor }}>
- <Icon icon="mdi:menu" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
- <Icon icon="mdi:chevron-left" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
- <Icon icon="mdi:chevron-right" className="opacity-40" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
- </div>
- </div>
-
- <div className="flex-1 max-w-xl" style={{ margin: `0 ${urlBarMargin}px` }}>
- <div
- className="rounded w-full flex items-center justify-between"
- style={{
- height: `${urlBarHeight}px`,
- padding: `0 ${urlBarPadding}px`,
- backgroundColor: hexToRgba(urlBarBgBase, headerOpacity),
- border: `1px solid ${urlBarBorder}`,
- color: textColor,
- }}
- >
- <Icon icon="mdi:lock" className="opacity-60" style={{ width: `${buttonSize}px`, height: `${buttonSize}px`, flexShrink: 0 }} />
- <span className="flex-1 text-center font-medium truncate" style={{ fontSize: `${fontSize}px`, padding: `0 ${urlBarPadding}px` }}>
- {url}
- </span>
- <Icon icon="mdi:refresh" className="opacity-60" style={{ width: `${buttonSize}px`, height: `${buttonSize}px`, flexShrink: 0 }} />
- </div>
- </div>
-
- <div className="flex items-center" style={{ gap: `${rightGroupGap}px`, color: textColor }}>
- <Icon icon="mdi:download" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
- <Icon icon="mdi:upload" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
- <Icon icon="mdi:plus" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
- <Icon icon="mdi:content-copy" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
- </div>
- </div>
+ >
+ <Icon icon="mdi:lock" className="opacity-60" style={{ width: `${buttonSize}px`, height: `${buttonSize}px`, flexShrink: 0 }} />
+ <span className="flex-1 text-center font-medium truncate" style={{ fontSize: `${fontSize}px`, padding: `0 ${urlBarPadding}px` }}>
+ {url}
+ </span>
+ <Icon icon="mdi:refresh" className="opacity-60" style={{ width: `${buttonSize}px`, height: `${buttonSize}px`, flexShrink: 0 }} />
+ </div>
+ </div>
- <div
- className="flex-1 relative overflow-hidden"
- style={{
- backgroundColor: bgColor,
- borderBottomLeftRadius: `${Math.max(0, cornerRadius - 3)}px`,
- borderBottomRightRadius: `${Math.max(0, cornerRadius - 3)}px`,
- }}
- >
- {children}
- </div>
- </div>
+ <div className="flex items-center" style={{ gap: `${rightGroupGap}px`, color: textColor }}>
+ <Icon icon="mdi:download" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
+ <Icon icon="mdi:upload" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
+ <Icon icon="mdi:plus" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
+ <Icon icon="mdi:content-copy" style={{ width: `${iconSize}px`, height: `${iconSize}px` }} />
</div>
+ </div>
+
+ <div
+ className="flex-1 relative overflow-hidden"
+ style={{
+ backgroundColor: bgColor,
+ borderBottomLeftRadius: `${Math.max(0, cornerRadius - 4)}px`,
+ borderBottomRightRadius: `${Math.max(0, cornerRadius - 4)}px`,
+ }}
+ >
+ {children}
+ </div>
</div>
- );
+ </div>
+ </div>
+ );
}
\ No newline at end of file
diff --git a/lib/canvas.utils.ts b/lib/canvas.utils.ts
index b2da080..2e18344 100644
--- a/lib/canvas.utils.ts
+++ b/lib/canvas.utils.ts
@@ -166,7 +166,7 @@ export function applyCanvasBackground(
if (stops.length >= 2) {
const centerX = width * originX;
const centerY = height * originY;
- const startAngle = (angle - 90) * Math.PI / 180; // Convertir a radianes y ajustar para que 0° sea arriba
+ const startAngle = (angle - 90) * Math.PI / 180;
const gradient = ctx.createConicGradient(startAngle, centerX, centerY);
stops.forEach(stop => gradient.addColorStop(stop.position, stop.color));
@@ -203,122 +203,120 @@ export interface ZoomStateCanvasExport extends ZoomStateCanvas {
* movement-end focus) by the time frameTime reaches endTime.
*/
export function calculateSmoothZoom(
- frameTime: number,
- zoomFragments: ZoomFragment[]
+ frameTime: number,
+ zoomFragments: ZoomFragment[]
): ZoomStateCanvasExport {
- const DEFAULT_STATE: ZoomStateCanvasExport = {
- scale: 1,
- focusX: 50,
- focusY: 50,
- rotateX: 0,
- rotateY: 0,
- perspective: 0,
- };
-
- if (!zoomFragments.length) return DEFAULT_STATE;
-
- const sortedFragments = [...zoomFragments].sort((a, b) => a.startTime - b.startTime);
-
- const activeFragment = sortedFragments.find(
- f => frameTime >= f.startTime && frameTime <= f.endTime
- );
-
- const previousFragment = sortedFragments
- .filter(f => f.endTime < frameTime)
- .sort((a, b) => b.endTime - a.endTime)[0];
-
- const isAdvancedZoom = (f: ZoomFragment) => f.enable3D || f.movementEnabled;
-
- // Shared scale curve: entry ramps INSIDE the fragment, then holds flat.
- // Used for BOTH simple and advanced zoom while the fragment is active.
- const computeHeldScale = (fragment: ZoomFragment, time: number): number => {
- const transitionSec = speedToTransitionMs(fragment.speed) / 1000;
- const targetScale = zoomLevelToFactor(fragment.zoomLevel);
- const timeIntoFragment = time - fragment.startTime;
- if (transitionSec > 0 && timeIntoFragment < transitionSec) {
- const progress = Math.min(1, Math.max(0, timeIntoFragment / transitionSec));
- return 1 + (targetScale - 1) * easeOutQuart(progress);
- }
- return targetScale;
- };
-
- // Shared exit curve: decays AFTER the fragment ends. Returns null once
- // the exit transition has fully finished (caller falls through to default).
- const computeExitScale = (fragment: ZoomFragment, time: number): number | null => {
- const transitionSec = speedToTransitionMs(fragment.speed) / 1000;
- if (transitionSec <= 0) return null;
- const timeSinceEnd = time - fragment.endTime;
- if (timeSinceEnd >= transitionSec) return null;
- const targetScale = zoomLevelToFactor(fragment.zoomLevel);
- const progress = Math.min(1, Math.max(0, timeSinceEnd / transitionSec));
- const easedProgress = easeOutQuart(progress);
- return targetScale - (targetScale - 1) * easedProgress;
- };
-
- if (activeFragment) {
- const scale = computeHeldScale(activeFragment, frameTime);
-
- if (isAdvancedZoom(activeFragment)) {
- // Rotation + focus/movement still use the existing 3-phase system —
- // that part already matches preview, we only override `scale`.
- const phaseState = calculateZoomPhaseState(activeFragment, frameTime, true);
- return {
- scale,
- focusX: phaseState.focusX,
- focusY: phaseState.focusY,
- rotateX: phaseState.rotateX,
- rotateY: phaseState.rotateY,
- perspective: phaseState.perspective,
- };
- }
+ const DEFAULT_STATE: ZoomStateCanvasExport = {
+ scale: 1,
+ focusX: 50,
+ focusY: 50,
+ rotateX: 0,
+ rotateY: 0,
+ perspective: 0,
+ };
+
+ if (!zoomFragments.length) return DEFAULT_STATE;
+
+ const sortedFragments = [...zoomFragments].sort((a, b) => a.startTime - b.startTime);
+
+ const activeFragment = sortedFragments.find(
+ f => frameTime >= f.startTime && frameTime <= f.endTime
+ );
+
+ const previousFragment = sortedFragments
+ .filter(f => f.endTime < frameTime)
+ .sort((a, b) => b.endTime - a.endTime)[0];
+
+ const isAdvancedZoom = (f: ZoomFragment) => f.enable3D || f.movementEnabled;
- return {
- scale,
- focusX: activeFragment.focusX,
- focusY: activeFragment.focusY,
- rotateX: 0,
- rotateY: 0,
- perspective: 0,
+ // Shared scale curve: entry ramps INSIDE the fragment, then holds flat.
+ // Used for BOTH simple and advanced zoom while the fragment is active.
+ const computeHeldScale = (fragment: ZoomFragment, time: number): number => {
+ const transitionSec = speedToTransitionMs(fragment.speed) / 1000;
+ const targetScale = zoomLevelToFactor(fragment.zoomLevel);
+ const timeIntoFragment = time - fragment.startTime;
+ if (transitionSec > 0 && timeIntoFragment < transitionSec) {
+ const progress = Math.min(1, Math.max(0, timeIntoFragment / transitionSec));
+ return 1 + (targetScale - 1) * easeOutQuart(progress);
+ }
+ return targetScale;
+ };
+
+ // Shared exit curve: decays AFTER the fragment ends. Returns null once
+ // the exit transition has fully finished (caller falls through to default).
+ const computeExitScale = (fragment: ZoomFragment, time: number): number | null => {
+ const transitionSec = speedToTransitionMs(fragment.speed) / 1000;
+ if (transitionSec <= 0) return null;
+ const timeSinceEnd = time - fragment.endTime;
+ if (timeSinceEnd >= transitionSec) return null;
+ const targetScale = zoomLevelToFactor(fragment.zoomLevel);
+ const progress = Math.min(1, Math.max(0, timeSinceEnd / transitionSec));
+ const easedProgress = easeOutQuart(progress);
+ return targetScale - (targetScale - 1) * easedProgress;
};
- }
-
- // Not inside any fragment — check exit transition from previous fragment.
- if (previousFragment) {
- const exitScale = computeExitScale(previousFragment, frameTime);
- if (exitScale !== null) {
- if (isAdvancedZoom(previousFragment)) {
- // By the time frameTime > endTime, rotation has already settled to 0
- // (calculateZoomPhaseState's exit fade completes before endTime) and
- // focus has already settled to its movement-end value — so we just
- // keep those static while the scale finishes decaying.
- const focusX = previousFragment.movementEnabled
- ? (previousFragment.movementEndX ?? previousFragment.focusX)
- : previousFragment.focusX;
- const focusY = previousFragment.movementEnabled
- ? (previousFragment.movementEndY ?? previousFragment.focusY)
- : previousFragment.focusY;
+
+ if (activeFragment) {
+ const scale = computeHeldScale(activeFragment, frameTime);
+
+ if (isAdvancedZoom(activeFragment)) {
+ // Rotation + focus/movement still use the existing 3-phase system —
+ // that part already matches preview, we only override `scale`.
+ const phaseState = calculateZoomPhaseState(activeFragment, frameTime, true);
+ return {
+ scale,
+ focusX: phaseState.focusX,
+ focusY: phaseState.focusY,
+ rotateX: phaseState.rotateX,
+ rotateY: phaseState.rotateY,
+ perspective: phaseState.perspective,
+ };
+ }
+
return {
- scale: exitScale,
- focusX,
- focusY,
- rotateX: 0,
- rotateY: 0,
- perspective: 0,
+ scale,
+ focusX: activeFragment.focusX,
+ focusY: activeFragment.focusY,
+ rotateX: 0,
+ rotateY: 0,
+ perspective: 0,
};
- }
+ }
- return {
- scale: exitScale,
- focusX: previousFragment.focusX,
- focusY: previousFragment.focusY,
- rotateX: 0,
- rotateY: 0,
- perspective: 0,
- };
+ if (previousFragment) {
+ const exitScale = computeExitScale(previousFragment, frameTime);
+ if (exitScale !== null) {
+ if (isAdvancedZoom(previousFragment)) {
+ const phaseState = calculateZoomPhaseState(previousFragment, frameTime, true);
+
+ const focusX = previousFragment.movementEnabled
+ ? (previousFragment.movementEndX ?? previousFragment.focusX)
+ : previousFragment.focusX;
+ const focusY = previousFragment.movementEnabled
+ ? (previousFragment.movementEndY ?? previousFragment.focusY)
+ : previousFragment.focusY;
+
+ return {
+ scale: exitScale,
+ focusX,
+ focusY,
+ rotateX: phaseState.rotateX,
+ rotateY: phaseState.rotateY,
+ perspective: phaseState.perspective,
+ };
+ }
+
+ return {
+ scale: exitScale,
+ focusX: previousFragment.focusX,
+ focusY: previousFragment.focusY,
+ rotateX: 0,
+ rotateY: 0,
+ perspective: 0,
+ };
+ }
}
- }
- return DEFAULT_STATE;
+ return DEFAULT_STATE;
}
// Functions to determine nearest corner and corner styles for rotating elements
diff --git a/lib/mockup-canvas/macos-glass.ts b/lib/mockup-canvas/macos-glass.ts
index 460fa83..cec9a47 100644
--- a/lib/mockup-canvas/macos-glass.ts
+++ b/lib/mockup-canvas/macos-glass.ts
@@ -1,203 +1,196 @@
import { hexToRgba } from "@/lib/utils";
import { deriveSearchBg } from "@/lib/color.utils";
import {
- drawChevronLeft,
- drawChevronRight,
- drawMenuIcon,
- drawLockIcon,
- drawRefreshIcon,
- drawDownloadIcon,
- drawUploadIcon,
- drawCopyIcon,
- drawPlusIcon,
+ drawChevronLeft,
+ drawChevronRight,
+ drawMenuIcon,
+ drawLockIcon,
+ drawRefreshIcon,
+ drawDownloadIcon,
+ drawUploadIcon,
+ drawCopyIcon,
+ drawPlusIcon,
} from "@/lib/canvas-icons";
import type { MockupCanvasContext, MockupDrawResult } from "./types";
import { drawRoundedRectPath, drawMockupShadow } from "./shared";
export function drawMacosGlassMockup(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 glassPadding = 12;
- const glassCornerRadius = cornerRadius;
-
- const headerHeight = 36 * headerScale;
- const buttonSize = 10 * headerScale;
- const buttonGap = 6 * headerScale;
- const buttonLeftPadding = 12 * headerScale;
- const urlBarHeight = 18 * headerScale;
- const fontSize = 11 * headerScale;
- const iconSize = 14 * headerScale;
-
- const bgColor = isDark ? "#262626" : "#ffffff";
- const borderColor = isDark ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)";
- const textColor = isDark ? "#cccccc" : "#555555";
- const iconColor = isDark ? "rgba(255,255,255,0.5)" : "rgba(0,0,0,0.4)";
-
- drawMockupShadow(ctx, x, y, width, height, glassCornerRadius, shadowBlur);
-
- const innerX = x + glassPadding;
- const innerY = y + glassPadding;
- const innerWidth = width - glassPadding * 2;
- const innerHeight = height - glassPadding * 2;
- const innerCornerRadius = Math.max(0, glassCornerRadius + 4);
-
+ 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 glassPadding = 8;
+ const glassCornerRadius = cornerRadius;
+
+ const headerHeight = 36 * headerScale;
+ const buttonSize = 10 * headerScale;
+ const buttonGap = 6 * headerScale;
+ const buttonLeftPadding = 12 * headerScale;
+ const urlBarHeight = 18 * headerScale;
+ const fontSize = 11 * headerScale;
+ const iconSize = 14 * headerScale;
+
+ const bgColor = isDark ? "#262626" : "#ffffff";
+ const borderColor = isDark ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.1)";
+ const textColor = isDark ? "#cccccc" : "#555555";
+ const iconColor = isDark ? "rgba(255,255,255,0.5)" : "rgba(0,0,0,0.4)";
+
+ const innerX = x + glassPadding;
+ const innerY = y + glassPadding;
+ const innerWidth = width - glassPadding * 2;
+ const innerHeight = height - glassPadding * 2;
+ const innerCornerRadius = Math.max(0, glassCornerRadius + 4);
+
+ drawMockupShadow(ctx, innerX, innerY, innerWidth, innerHeight, innerCornerRadius, shadowBlur);
+
+ ctx.save();
+ drawRoundedRectPath(ctx, x, y, width, height, glassCornerRadius);
+ ctx.moveTo(innerX + innerCornerRadius, innerY);
+ ctx.lineTo(innerX + innerWidth - innerCornerRadius, innerY);
+ ctx.quadraticCurveTo(innerX + innerWidth, innerY, innerX + innerWidth, innerY + innerCornerRadius);
+ ctx.lineTo(innerX + innerWidth, innerY + innerHeight - innerCornerRadius);
+ ctx.quadraticCurveTo(innerX + innerWidth, innerY + innerHeight, innerX + innerWidth - innerCornerRadius, innerY + innerHeight);
+ ctx.lineTo(innerX + innerCornerRadius, innerY + innerHeight);
+ ctx.quadraticCurveTo(innerX, innerY + innerHeight, innerX, innerY + innerHeight - innerCornerRadius);
+ ctx.lineTo(innerX, innerY + innerCornerRadius);
+ ctx.quadraticCurveTo(innerX, innerY, innerX + innerCornerRadius, innerY);
+ ctx.closePath();
+
+ const gradient = ctx.createLinearGradient(x, y, x + width, y + height);
+ gradient.addColorStop(0, 'rgba(255, 255, 255, 0.35)');
+ gradient.addColorStop(1, 'rgba(255, 255, 255, 0.45)');
+ ctx.fillStyle = gradient;
+ ctx.fill('evenodd');
+
+ ctx.strokeStyle = 'rgba(255, 255, 255, 0.8)';
+ ctx.lineWidth = 0.5;
+
+ ctx.beginPath();
+ ctx.moveTo(x + glassCornerRadius, y);
+ ctx.lineTo(x + width - glassCornerRadius, y);
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.moveTo(x, y + glassCornerRadius);
+ ctx.lineTo(x, y + height - glassCornerRadius);
+ ctx.stroke();
+ ctx.restore();
+
+ ctx.save();
+ ctx.beginPath();
+ ctx.moveTo(innerX, innerY + headerHeight);
+ ctx.lineTo(innerX + innerWidth, innerY + headerHeight);
+ ctx.lineTo(innerX + innerWidth, innerY + innerHeight - innerCornerRadius);
+ ctx.quadraticCurveTo(innerX + innerWidth, innerY + innerHeight, innerX + innerWidth - innerCornerRadius, innerY + innerHeight);
+ ctx.lineTo(innerX + innerCornerRadius, innerY + innerHeight);
+ ctx.quadraticCurveTo(innerX, innerY + innerHeight, innerX, innerY + innerHeight - innerCornerRadius);
+ ctx.closePath();
+ ctx.fillStyle = bgColor;
+ ctx.fill();
+ ctx.restore();
+
+ ctx.save();
+ ctx.beginPath();
+ ctx.moveTo(innerX + innerCornerRadius, innerY);
+ ctx.lineTo(innerX + innerWidth - innerCornerRadius, innerY);
+ ctx.quadraticCurveTo(innerX + innerWidth, innerY, innerX + innerWidth, innerY + innerCornerRadius);
+ ctx.lineTo(innerX + innerWidth, innerY + headerHeight);
+ ctx.lineTo(innerX, innerY + headerHeight);
+ ctx.lineTo(innerX, innerY + innerCornerRadius);
+ ctx.quadraticCurveTo(innerX, innerY, innerX + innerCornerRadius, innerY);
+ ctx.closePath();
+ ctx.fillStyle = hexToRgba(frameColor, headerOpacity);
+ ctx.fill();
+ ctx.restore();
+
+ ctx.save();
+ ctx.strokeStyle = borderColor;
+ ctx.lineWidth = 1;
+ ctx.beginPath();
+ ctx.moveTo(innerX, innerY + headerHeight);
+ ctx.lineTo(innerX + innerWidth, innerY + headerHeight);
+ ctx.stroke();
+ ctx.restore();
+
+ const buttonY = innerY + (headerHeight - buttonSize) / 2;
+ const buttons = [
+ { color: "#FF5F56", border: "#E0443E" },
+ { color: "#FFBD2E", border: "#DEA123" },
+ { color: "#27C93F", border: "#1AAB29" },
+ ];
+ buttons.forEach((btn, i) => {
+ const btnX = innerX + buttonLeftPadding + i * (buttonSize + buttonGap);
ctx.save();
-
- drawRoundedRectPath(ctx, x, y, width, height, glassCornerRadius);
-
- ctx.moveTo(innerX + innerCornerRadius, innerY);
- ctx.lineTo(innerX + innerWidth - innerCornerRadius, innerY);
- ctx.quadraticCurveTo(innerX + innerWidth, innerY, innerX + innerWidth, innerY + innerCornerRadius);
- ctx.lineTo(innerX + innerWidth, innerY + innerHeight - innerCornerRadius);
- ctx.quadraticCurveTo(innerX + innerWidth, innerY + innerHeight, innerX + innerWidth - innerCornerRadius, innerY + innerHeight);
- ctx.lineTo(innerX + innerCornerRadius, innerY + innerHeight);
- ctx.quadraticCurveTo(innerX, innerY + innerHeight, innerX, innerY + innerHeight - innerCornerRadius);
- ctx.lineTo(innerX, innerY + innerCornerRadius);
- ctx.quadraticCurveTo(innerX, innerY, innerX + innerCornerRadius, innerY);
- ctx.closePath();
-
- const gradient = ctx.createLinearGradient(x, y, x + width, y + height);
- gradient.addColorStop(0, 'rgba(255, 255, 255, 0.35)');
- gradient.addColorStop(1, 'rgba(255, 255, 255, 0.45)');
- ctx.fillStyle = gradient;
- ctx.fill('evenodd'); // Use evenodd to create the "donut" cutout effect
-
- ctx.strokeStyle = 'rgba(255, 255, 255)';
- ctx.lineWidth = 0.5;
-
- ctx.beginPath();
- ctx.moveTo(x + glassCornerRadius, y);
- ctx.lineTo(x + width - glassCornerRadius, y);
- ctx.stroke();
-
ctx.beginPath();
- ctx.moveTo(x, y + glassCornerRadius);
- ctx.lineTo(x, y + height - glassCornerRadius);
- ctx.stroke();
- ctx.restore();
-
- ctx.save();
- ctx.beginPath();
- ctx.moveTo(innerX, innerY + headerHeight);
- ctx.lineTo(innerX + innerWidth, innerY + headerHeight);
- ctx.lineTo(innerX + innerWidth, innerY + innerHeight - innerCornerRadius);
- ctx.quadraticCurveTo(innerX + innerWidth, innerY + innerHeight, innerX + innerWidth - innerCornerRadius, innerY + innerHeight);
- ctx.lineTo(innerX + innerCornerRadius, innerY + innerHeight);
- ctx.quadraticCurveTo(innerX, innerY + innerHeight, innerX, innerY + innerHeight - innerCornerRadius);
- ctx.closePath();
- ctx.fillStyle = bgColor;
+ ctx.arc(btnX + buttonSize / 2, buttonY + buttonSize / 2, buttonSize / 2, 0, Math.PI * 2);
+ ctx.fillStyle = btn.color;
ctx.fill();
- ctx.restore();
-
- ctx.save();
- ctx.beginPath();
- ctx.moveTo(innerX + innerCornerRadius, innerY);
- ctx.lineTo(innerX + innerWidth - innerCornerRadius, innerY);
- ctx.quadraticCurveTo(innerX + innerWidth, innerY, innerX + innerWidth, innerY + innerCornerRadius);
- ctx.lineTo(innerX + innerWidth, innerY + headerHeight);
- ctx.lineTo(innerX, innerY + headerHeight);
- ctx.lineTo(innerX, innerY + innerCornerRadius);
- ctx.quadraticCurveTo(innerX, innerY, innerX + innerCornerRadius, innerY);
- ctx.closePath();
- ctx.fillStyle = hexToRgba(frameColor, headerOpacity);
- ctx.fill();
- ctx.restore();
-
- ctx.save();
- ctx.strokeStyle = borderColor;
- ctx.lineWidth = 1;
- ctx.beginPath();
- ctx.moveTo(innerX, innerY + headerHeight);
- ctx.lineTo(innerX + innerWidth, innerY + headerHeight);
+ ctx.strokeStyle = btn.border;
+ ctx.lineWidth = 0.5;
ctx.stroke();
ctx.restore();
-
- const buttonY = innerY + (headerHeight - buttonSize) / 2;
- const buttons = [
- { color: "#FF5F56", border: "#E0443E" },
- { color: "#FFBD2E", border: "#DEA123" },
- { color: "#27C93F", border: "#1AAB29" },
- ];
-
- buttons.forEach((btn, i) => {
- const btnX = innerX + buttonLeftPadding + i * (buttonSize + buttonGap);
- ctx.save();
- ctx.beginPath();
- ctx.arc(btnX + buttonSize / 2, buttonY + buttonSize / 2, buttonSize / 2, 0, Math.PI * 2);
- ctx.fillStyle = btn.color;
- ctx.fill();
- ctx.strokeStyle = btn.border;
- ctx.lineWidth = 0.5;
- ctx.stroke();
- ctx.restore();
- });
-
- const navStartX = innerX + buttonLeftPadding + 3 * (buttonSize + buttonGap) + buttonGap * 2;
- const iconY = innerY + (headerHeight - iconSize) / 2;
- const navGap = 6 * headerScale;
-
- 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);
-
- const maxUrlBarWidth = 576 * headerScale;
- const urlBarWidth = Math.min(innerWidth * 0.5, maxUrlBarWidth);
- const urlBarX = innerX + (innerWidth - urlBarWidth) / 2;
- const urlBarY = innerY + (headerHeight - urlBarHeight) / 2;
- const urlBarPadding = 8 * headerScale;
-
- const urlBarBgBase = deriveSearchBg(frameColor);
-
- ctx.save();
- drawRoundedRectPath(ctx, urlBarX, urlBarY, urlBarWidth, urlBarHeight, 4 * headerScale);
- ctx.fillStyle = hexToRgba(urlBarBgBase, headerOpacity);
- ctx.fill();
- ctx.restore();
-
- const lockIconSize = buttonSize;
- const lockIconX = urlBarX + 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();
-
- const refreshIconSize = buttonSize;
- const refreshIconX = urlBarX + urlBarWidth - urlBarPadding - refreshIconSize;
- const refreshIconY = urlBarY + (urlBarHeight - refreshIconSize) / 2;
- drawRefreshIcon(ctx, refreshIconX, refreshIconY, refreshIconSize, iconColor + "99");
-
- const iconsRightPadding = 12 * headerScale;
- const iconGap = 10 * headerScale;
-
- const copyIconX = innerX + innerWidth - 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);
-
- return {
- contentX: innerX,
- contentY: innerY + headerHeight,
- contentWidth: innerWidth,
- contentHeight: innerHeight - headerHeight,
- };
-}
+ });
+
+ const navStartX = innerX + buttonLeftPadding + 3 * (buttonSize + buttonGap) + buttonGap * 2;
+ const iconY = innerY + (headerHeight - iconSize) / 2;
+ const navGap = 6 * headerScale;
+ 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);
+
+ const maxUrlBarWidth = 576 * headerScale;
+ const urlBarWidth = Math.min(innerWidth * 0.5, maxUrlBarWidth);
+ const urlBarX = innerX + (innerWidth - urlBarWidth) / 2;
+ const urlBarY = innerY + (headerHeight - urlBarHeight) / 2;
+ const urlBarPadding = 8 * headerScale;
+ const urlBarBgBase = deriveSearchBg(frameColor);
+
+ ctx.save();
+ drawRoundedRectPath(ctx, urlBarX, urlBarY, urlBarWidth, urlBarHeight, 4 * headerScale);
+ ctx.fillStyle = hexToRgba(urlBarBgBase, headerOpacity);
+ ctx.fill();
+ ctx.restore();
+
+ const lockIconSize = buttonSize;
+ const lockIconX = urlBarX + 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();
+
+ const refreshIconSize = buttonSize;
+ const refreshIconX = urlBarX + urlBarWidth - urlBarPadding - refreshIconSize;
+ const refreshIconY = urlBarY + (urlBarHeight - refreshIconSize) / 2;
+ drawRefreshIcon(ctx, refreshIconX, refreshIconY, refreshIconSize, iconColor + "99");
+
+ const iconsRightPadding = 12 * headerScale;
+ const iconGap = 10 * headerScale;
+ const copyIconX = innerX + innerWidth - 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);
+
+ return {
+ contentX: innerX,
+ contentY: innerY + headerHeight,
+ contentWidth: innerWidth,
+ contentHeight: innerHeight - headerHeight,
+ };
+}
\ No newline at end of file
diff --git a/lib/perspective3d.ts b/lib/perspective3d.ts
index f094908..d7f6dce 100644
--- a/lib/perspective3d.ts
+++ b/lib/perspective3d.ts
@@ -14,7 +14,7 @@ function buildRenderer(): THREE.WebGLRenderer {
alpha: true,
antialias: true,
preserveDrawingBuffer: true,
- premultipliedAlpha: false,
+ premultipliedAlpha: true,
});
r.outputColorSpace = THREE.SRGBColorSpace;
r.toneMapping = THREE.NoToneMapping;
@@ -31,12 +31,14 @@ function ensureScene(aspect: number): { scene: THREE.Scene; plane: THREE.Mesh }
_offscreen = document.createElement("canvas");
_texture = new THREE.CanvasTexture(_offscreen);
_texture.colorSpace = THREE.SRGBColorSpace;
- _texture.generateMipmaps = true;
- _texture.minFilter = THREE.LinearMipmapLinearFilter;
+
+ _texture.generateMipmaps = true; // Cambiar a true
+ _texture.minFilter = THREE.LinearMipmapLinearFilter; // Usar filtro con Mipmap
_texture.magFilter = THREE.LinearFilter;
+
_texture.wrapS = THREE.ClampToEdgeWrapping;
_texture.wrapT = THREE.ClampToEdgeWrapping;
- _texture.premultiplyAlpha = true;
+ _texture.premultiplyAlpha = false;
}
if (!_material) {
@@ -46,8 +48,12 @@ function ensureScene(aspect: number): { scene: THREE.Scene; plane: THREE.Mesh }
side: THREE.FrontSide,
depthTest: false,
depthWrite: false,
+ blending: THREE.CustomBlending,
+ blendEquation: THREE.AddEquation,
+ blendSrc: THREE.SrcAlphaFactor,
+ blendDst: THREE.OneMinusSrcAlphaFactor
});
- _material.premultipliedAlpha = true;
+ _material.premultipliedAlpha = false;
}
if (!_plane || Math.abs(_lastAspect - aspect) > 0.0001) {
@@ -80,7 +86,7 @@ export function applyPerspective3D(
if (!_renderer) {
_renderer = buildRenderer();
- _renderer.setPixelRatio(1);
+ _renderer.setPixelRatio(typeof window !== 'undefined' ? window.devicePixelRatio : 1);
}
if (_renderer.domElement.width !== w || _renderer.domElement.height !== h) {
_renderer.setSize(w, h, false);
@@ -127,6 +133,9 @@ export function applyPerspective3D(
_renderer.render(scene, _camera);
const ctx2d = canvas.getContext("2d", { alpha: true, willReadFrequently: false })!;
+ ctx2d.imageSmoothingEnabled = true;
+ ctx2d.imageSmoothingQuality = 'high';
+
ctx2d.clearRect(0, 0, w, h);
ctx2d.drawImage(_renderer.domElement, 0, 0);
}
diff --git a/types/zoom.types.ts b/types/zoom.types.ts
index 398a62e..a5aad06 100644
--- a/types/zoom.types.ts
+++ b/types/zoom.types.ts
@@ -71,7 +71,7 @@ export function calculateZoomPhaseState(
const transitionSeconds = speedToTransitionMs(fragment.speed) / 1000;
const entryEndTime = fragment.startTime + transitionSeconds;
- const exitStartTime = fragment.endTime - transitionSeconds;
+ const exitStartTime = fragment.endTime;
const holdDuration = Math.max(0, exitStartTime - entryEndTime);
let rotateX = 0;
@@ -155,10 +155,10 @@ export function calculateZoomPhaseState(
if (phase === 'entry') {
const entryProgress = (currentTime - fragment.startTime) / transitionSeconds;
effect3DOpacity = Math.min(1, entryProgress * 1.2);
- } else if (phase === 'exit') {
- const exitProgress = (currentTime - exitStartTime) / transitionSeconds;
- effect3DOpacity = Math.max(0, 1 - exitProgress * 1.8);
- } else {
+ } else if (phase === 'exit') {
+ const exitProgress = (currentTime - exitStartTime) / transitionSeconds;
+ effect3DOpacity = Math.max(0, 1 - exitProgress); // Reducción 1 a 1 perfecta
+}else {
effect3DOpacity = 1;
}