Create professional demos and 3D mockups in seconds, directly in your browser
feat: add types motion menu
CristianOlivera1e368ebcd3006
diff --git a/hooks/useImageProjects.ts b/hooks/useImageProjects.tsindex 44b0a66..a025e41 100644--- a/hooks/useImageProjects.ts+++ b/hooks/useImageProjects.ts@@ -41,6 +41,19 @@ interface ImageProjectState {imagePreview3D: Preview3DConfig;apply3DToBackground: boolean;imageMaskConfig: ImageMaskConfig;+ // ── Motion / 3D device mockup state (image mode) ──────────────────────+ imagePhoneActive: boolean;+ imagePhoneX: number;+ imagePhoneY: number;+ imagePhoneScale: number;+ imagePhoneRotX: number;+ imagePhoneRotY: number;+ imagePhoneRotZ: number;+ imagePhonePerspective: number;+ imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'samsung' | 'laptop';+ imagePhoneOpening: number;+ imagePhoneShadow: number;+ imagePhoneShadowColor: string;}const DEFAULT_PROJECT_STATE: ImageProjectState = {@@ -66,6 +79,19 @@ const DEFAULT_PROJECT_STATE: ImageProjectState = {imagePreview3D: PREVIEW_CONFIGS[0],apply3DToBackground: false,imageMaskConfig: DEFAULT_MASK_CONFIG,+ // ── Motion / 3D device mockup state defaults (match MotionContext) ───+ imagePhoneActive: false,+ imagePhoneX: 0,+ imagePhoneY: 0,+ imagePhoneScale: 1,+ imagePhoneRotX: 0,+ imagePhoneRotY: 0,+ imagePhoneRotZ: 0,+ imagePhonePerspective: 600,+ imagePhoneDevice: 'phone',+ imagePhoneOpening: 1,+ imagePhoneShadow: 0.6,+ imagePhoneShadowColor: "#000000",};export function useImageProjects() {diff --git a/lib/motion.utils.ts b/lib/motion.utils.tsnew file mode 100644index 0000000..be6495d--- /dev/null+++ b/lib/motion.utils.ts@@ -0,0 +1,369 @@+import { ScriptFn, CameraVariant, MotionStyle } from "@/types/motion.types";+import { STYLE_CFG, NRX, NRY } from "./animation-core";+import gsap from "gsap";++export const sweepScript: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000;+ const { amp, e1, e2, e3 } = STYLE_CFG[style];+ const a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX + 18 * a, ry: -58 * a, tx: 36 * a, ty: -14 * a, sc: 0.95, duration: c * 0.12, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: 0, sc: 1.04, duration: c * 0.22, ease: e2, onUpdate })+ .to(av, { rx: NRX + 14 * a, ry: NRY - 50 * a, tx: 36 * a, ty: -18 * a, sc: 0.98, duration: c * 0.20, ease: e3, onUpdate })+ .to(av, { rx: NRX + 6 * a, ry: NRY + 32 * a, tx: -24 * a, ty: 10 * a, sc: 1.02, duration: c * 0.20, ease: e3, onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.26, ease: "power3.in", onUpdate });+};++// 1. HERO REVEAL (Respeta tu pose personalizada: ry: 50*a)+export const heroRevealScript: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000;+ const { amp, e1, e2 } = STYLE_CFG[style];+ const a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: 50 * a, tx: 33 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX + 18 * a, ry: -58 * a, tx: 36 * a, ty: -14 * a, sc: 0.90, duration: c * 0.10, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX + 10 * a, ry: -28 * a, tx: 14 * a, ty: 6 * a, sc: 0.94, duration: c * 0.16, ease: "power3.out", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: 0, sc: 1.00, duration: c * 0.18, ease: e1, onUpdate })+ .to(av, { rx: NRX - 4 * a, ry: NRY + 8 * a, tx: -3 * a, ty: -5 * a, sc: 1.00, duration: c * 0.18, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX + 6 * a, ry: NRY - 30 * a, tx: 18 * a, ty: -10 * a, sc: 0.97, duration: c * 0.16, ease: e2, onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: 50 * a, tx: 33 * a, ty: 4 * a, sc: 1.00, duration: c * 0.22, ease: "power3.in", onUpdate });+};++// 2. ORBIT (Ajustado para no achicarse tanto)+export const orbitScript: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000;+ const { amp, e1, e2 } = STYLE_CFG[style];+ const a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX - 4 * a, ry: NRY + 10 * a, tx: -5 * a, ty: -4 * a, sc: 1.00, duration: c * 0.16, ease: e1, onUpdate })+ .to(av, { rx: NRX + 8 * a, ry: 62 * a, tx: -12 * a, ty: 6 * a, sc: 0.95, duration: c * 0.20, ease: e2, onUpdate })+ .to(av, { rx: NRX + 10 * a, ry: 66 * a, tx: -14 * a, ty: 8 * a, sc: 0.94, duration: c * 0.08, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: 0, sc: 1.00, duration: c * 0.12, ease: e1, onUpdate })+ .to(av, { rx: NRX + 8 * a, ry: -62 * a, tx: 12 * a, ty: 6 * a, sc: 0.95, duration: c * 0.20, ease: e2, onUpdate })+ .to(av, { rx: NRX + 10 * a, ry: -66 * a, tx: 14 * a, ty: 8 * a, sc: 0.94, duration: c * 0.08, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.16, ease: "expo.out", onUpdate });+};++// 3. SHOWCASE+export const showcaseScript: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000;+ const { amp, e1, e2 } = STYLE_CFG[style];+ const a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX + 18 * a, ry: -55 * a, tx: 35 * a, ty: -14 * a, sc: 0.90, duration: c * 0.12, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX, ry: 0, tx: 0, ty: 0, sc: 1.08, duration: c * 0.22, ease: e2, onUpdate })+ .to(av, { rx: NRX - 6 * a, ry: 6 * a, tx: -4 * a, ty: -8 * a, sc: 1.00, duration: c * 0.18, ease: "expo.out", onUpdate })+ .to(av, { rx: NRX - 4 * a, ry: 10 * a, tx: -6 * a, ty: -4 * a, sc: 1.00, duration: c * 0.15, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX - 20 * a, ry: 58 * a, tx: -38 * a, ty: 12 * a, sc: 0.88, duration: c * 0.18, ease: e1, onUpdate })+ .to(av, { rx: NRX - 22 * a, ry: 62 * a, tx: -40 * a, ty: 14 * a, sc: 0.87, duration: c * 0.08, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.07, ease: "power3.inOut", onUpdate });+};++// 4. STAGE ENTRY (Corregido zoom-out excesivo al entrar/rebotar)+export const stageEntryScript: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000;+ const { amp } = STYLE_CFG[style];+ const a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX + 18 * a, ry: -58 * a, tx: 36 * a, ty: -14 * a, sc: 0.90, duration: c * 0.08, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX + 6 * a, ry: NRY - 18 * a, tx: 0, ty: 50 * a, sc: 0.90, duration: c * 0.10, ease: "power2.in", onUpdate })+ .to(av, { rx: NRX + 3 * a, ry: NRY - 6 * a, tx: 0, ty: 16 * a, sc: 0.95, duration: c * 0.20, ease: "expo.out", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: -8 * a, sc: 1.05, duration: c * 0.12, ease: "back.out(1.8)", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: 0, sc: 1.00, duration: c * 0.08, ease: "power2.out", onUpdate })+ .to(av, { rx: NRX - 5 * a, ry: NRY - 16 * a, tx: 8 * a, ty: -5 * a, sc: 1.00, duration: c * 0.18, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX + 4 * a, ry: NRY + 12 * a, tx: -6 * a, ty: 4 * a, sc: 1.00, duration: c * 0.14, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.10, ease: "power4.in", onUpdate });+};++// 5. TILT SHIFT+export const tiltShiftScript: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000;+ const { amp, e1, e3 } = STYLE_CFG[style];+ const a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX + 20 * a, ry: -66 * a, tx: 40 * a, ty: -14 * a, sc: 0.93, duration: c * 0.16, ease: e3, onUpdate })+ .to(av, { rx: NRX, ry: 0, tx: 0, ty: 0, sc: 1.06, duration: c * 0.18, ease: e1, onUpdate })+ .to(av, { rx: NRX - 3 * a, ry: 5 * a, tx: 0, ty: -4 * a, sc: 1.00, duration: c * 0.10, ease: "expo.out", onUpdate })+ .to(av, { rx: NRX - 18 * a, ry: 62 * a, tx: -36 * a, ty: 10 * a, sc: 0.91, duration: c * 0.20, ease: e3, onUpdate })+ .to(av, { rx: NRX - 20 * a, ry: 66 * a, tx: -38 * a, ty: 12 * a, sc: 0.91, duration: c * 0.08, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: 0, sc: 1.00, duration: c * 0.12, ease: e1, onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.16, ease: "power2.in", onUpdate });+};++// 6. GRAVITY DROP (Minimizado el salto hacia atrás)+export const gravityDropScript: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000;+ const { amp } = STYLE_CFG[style];+ const a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX - 4 * a, ry: NRY - 20 * a, tx: 0, ty: -100 * a, sc: 0.88, duration: c * 0.08, ease: "power2.in", onUpdate })+ .to(av, { rx: NRX + 4 * a, ry: NRY, tx: 0, ty: 16 * a, sc: 1.05, duration: c * 0.20, ease: "power3.in", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: -14 * a, sc: 1.00, duration: c * 0.10, ease: "power2.out", onUpdate })+ .to(av, { rx: NRX + 2 * a, ry: NRY, tx: 0, ty: 4 * a, sc: 1.00, duration: c * 0.06, ease: "power2.in", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: -2 * a, sc: 1.00, duration: c * 0.04, ease: "power2.out", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: 0, sc: 1.00, duration: c * 0.06, ease: "power2.inOut", onUpdate })+ .to(av, { rx: NRX - 5 * a, ry: NRY - 16 * a, tx: 10 * a, ty: -6 * a, sc: 1.00, duration: c * 0.20, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX + 4 * a, ry: NRY + 12 * a, tx: -7 * a, ty: 5 * a, sc: 1.00, duration: c * 0.16, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.10, ease: "power4.in", onUpdate });+};++// 7. SIGNATURE (Respeta tu pose personalizada: ry: -45*a)+export const signatureScript: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000;+ const { amp, e1, e2 } = STYLE_CFG[style];+ const a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -45 * a, tx: 12 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX - 4 * a, ry: NRY - 10 * a, tx: 5 * a, ty: -5 * a, sc: 1.00, duration: c * 0.16, ease: e1, onUpdate })+ .to(av, { rx: NRX - 4 * a, ry: NRY - 12 * a, tx: 6 * a, ty: -5 * a, sc: 1.00, duration: c * 0.16, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX + 4 * a, ry: NRY + 10 * a, tx: -5 * a, ty: 4 * a, sc: 1.00, duration: c * 0.16, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX + 10 * a, ry: 58 * a, tx: -14 * a, ty: 6 * a, sc: 0.88, duration: c * 0.16, ease: e2, onUpdate })+ .to(av, { rx: NRX + 12 * a, ry: 62 * a, tx: -16 * a, ty: 8 * a, sc: 0.87, duration: c * 0.10, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX + 4 * a, ry: 18 * a, tx: -4 * a, ty: 2 * a, sc: 0.96, duration: c * 0.12, ease: e1, onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -45 * a, tx: 12 * a, ty: 4 * a, sc: 1.00, duration: c * 0.14, ease: "expo.out", onUpdate });+};++// 8. CINEMATIC IN (Corregido achicamiento masivo sc:0.78 -> 0.92)+export const cinematicInScript: ScriptFn = (av, intensity, durMs, _style, onUpdate) => {+ const c = Math.min(durMs / 1000, 4.0);+ const a = intensity;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX + 8 * a, ry: -28 * a, tx: -18 * a, ty: -20 * a, sc: 0.92, duration: c * 0.40, ease: "power4.out", onUpdate })+ .to(av, { rx: NRX + 2 * a, ry: 0, tx: 0, ty: 0, sc: 1.06, duration: c * 0.30, ease: "expo.out", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: -3 * a, sc: 1.00, duration: c * 0.18, ease: "back.out(1.3)", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.12, ease: "sine.inOut", onUpdate });+};++// 9. CINEMATIC OUT (Corregido achicamiento masivo sc:0.58 -> 0.85)+export const cinematicOutScript: ScriptFn = (av, intensity, durMs, _style, onUpdate) => {+ const c = Math.min(durMs / 1000, 3.5);+ const a = intensity;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: 0, sc: 1.00, duration: c * 0.18, ease: "power2.out", onUpdate })+ .to(av, { rx: NRX - 3 * a, ry: NRY - 6 * a, tx: 3 * a, ty: -4 * a, sc: 1.02, duration: c * 0.14, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX + 14 * a, ry: -52 * a, tx: -26 * a, ty: -72 * a, sc: 0.85, duration: c * 0.68, ease: "power3.in", onUpdate });+};++// ─── ENTRY / EXIT scripts ─────────────────────────────────────────────────────++export const heroRevealEntry: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000, { amp, e1 } = STYLE_CFG[style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -58 * a, tx: 36 * a, ty: 12 * a, sc: 1.00 })+ .to(av, { rx: NRX - 35 * a, ry: -28 * a, tx: 14 * a, ty: 6 * a, sc: 1.00, duration: c * 0.35, ease: "power3.out", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: 0, sc: 1.00, duration: c * 0.35, ease: e1, onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: 50 * a, tx: 33 * a, ty: 4 * a, sc: 1.00, duration: c * 0.30, ease: "sine.out", onUpdate });+};++export const heroRevealExit: ScriptFn = (av, intensity, durMs, _style, onUpdate) => {+ const c = durMs / 1000, { amp, e2 } = STYLE_CFG[_style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: 50 * a, tx: 33 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX - 30 * a, ry: -30 * a, tx: 18 * a, ty: -10 * a, sc: 1.00, duration: c * 0.45, ease: e2, onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -58 * a, tx: 36 * a, ty: 12 * a, sc: 1.00, duration: c * 0.55, ease: "power3.in", onUpdate });+};+export const orbitEntry: ScriptFn = (av, intensity, durMs, _style, onUpdate) => {+ const c = durMs / 1000, { amp } = STYLE_CFG[_style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 30 * a, ry: -64 * a, tx: 14 * a, ty: 6 * a, sc: 1.00 })+ .to(av, { rx: NRX - 30 * a, ry: -28 * a, tx: 6 * a, ty: -4 * a, sc: 1.00, duration: c * 0.50, ease: "power2.out", onUpdate })+ .to(av, { rx: NRX, ry: -35 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.50, ease: "expo.out", onUpdate });+};++export const orbitExit: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000, { amp } = STYLE_CFG[style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX, ry: -35 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX - 30 * a, ry: -40 * a, tx: -12 * a, ty: 5 * a, sc: 1.00, duration: c * 0.50, ease: "power2.in", onUpdate })+ .to(av, { rx: NRX - 30 * a, ry: 40 * a, tx: -18 * a, ty: 9 * a, sc: 0.95, duration: c * 0.50, ease: "power4.in", onUpdate });+};+++export const showcaseEntry: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000, { amp, e2 } = STYLE_CFG[style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 55 * a, ry: -55 * a, tx: 35 * a, ty: 12 * a, sc: 1.00 })+ .to(av, { rx: NRX, ry: 0, tx: 0, ty: 0, sc: 1.00, duration: c * 0.55, ease: e2, onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.45, ease: "expo.out", onUpdate });+};++export const showcaseExit: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000, { amp, e1 } = STYLE_CFG[style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX - 30 * a, ry: -20 * a, tx: -36 * a, ty: 6 * a, sc: 1.00, duration: c * 0.55, ease: e1, onUpdate })+ .to(av, { rx: NRX - 20 * a, ry: 40 * a, tx: -44 * a, ty: 15 * a, sc: 0.95, duration: c * 0.45, ease: "power4.in", onUpdate });+};+export const stageEntryEntry: ScriptFn = (av, intensity, durMs, _style, onUpdate) => {+ const c = durMs / 1000, { amp } = STYLE_CFG[_style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 55 * a, ry: -55 * a, tx: 35 * a, ty: 12 * a, sc: 1.00 })+ .to(av, { rx: NRX, ry: 0, tx: 0, ty: 0, sc: 1.00, duration: c * 0.55, ease: "power2.out", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.45, ease: "expo.out", onUpdate });+};++export const stageEntryExit: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000, { amp } = STYLE_CFG[style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX - 30 * a, ry: -20 * a, tx: -36 * a, ty: 6 * a, sc: 1.00, duration: c * 0.55, ease: "power3.in", onUpdate })+ .to(av, { rx: NRX - 20 * a, ry: 40 * a, tx: -44 * a, ty: 15 * a, sc: 0.95, duration: c * 0.45, ease: "power4.in", onUpdate });+};++export const tiltShiftEntry: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000;+ const { amp, e1 } = STYLE_CFG[style];+ const a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX + 20 * a, ry: -66 * a, tx: 40 * a, ty: -14 * a, sc: 0.93 })+ .to(av, { rx: NRX, ry: 0, tx: 0, ty: 0, sc: 1.06, duration: c * 0.55, ease: e1, onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.45, ease: "expo.out", onUpdate });+};++export const tiltShiftExit: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000;+ const { amp, e3 } = STYLE_CFG[style];+ const a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX - 18 * a, ry: 62 * a, tx: -36 * a, ty: 10 * a, sc: 0.91, duration: c * 0.55, ease: e3, onUpdate })+ .to(av, { rx: NRX - 20 * a, ry: 76 * a, tx: -46 * a, ty: 14 * a, sc: 0.88, duration: c * 0.45, ease: "power4.in", onUpdate });+};++export const gravityDropEntry: ScriptFn = (av, intensity, durMs, _style, onUpdate) => {+ const c = durMs / 1000, { amp } = STYLE_CFG[_style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 45 * a, ry: NRY - 20 * a, tx: 0, ty: -100 * a, sc: 1.00 })+ .to(av, { rx: NRX - 30 * a, ry: NRY, tx: 0, ty: 16 * a, sc: 1.00, duration: c * 0.45, ease: "power3.in", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: -35 * a, sc: 1.00, duration: c * 0.55, ease: "expo.out", onUpdate });+};++export const gravityDropExit: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000, { amp } = STYLE_CFG[style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: -35 * a, sc: 1.00 })+ .to(av, { rx: NRX - 30 * a, ry: NRY - 12 * a, tx: 0, ty: -36 * a, sc: 0.92, duration: c * 0.40, ease: "power2.in", onUpdate })+ .to(av, { rx: NRX - 45 * a, ry: NRY - 20 * a, tx: 0, ty: -100 * a, sc: 0.85, duration: c * 0.60, ease: "power4.in", onUpdate });+};++export const signatureEntry: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000, { amp, e1 } = STYLE_CFG[style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 55 * a, ry: -60 * a, tx: 16 * a, ty: 12 * a, sc: 1.00 })+ .to(av, { rx: NRX - 40 * a, ry: -35 * a, tx: 8 * a, ty: 6 * a, sc: 1.00, duration: c * 0.45, ease: "power2.out", onUpdate })+ .to(av, { rx: NRX, ry: NRY, tx: 0, ty: 0, sc: 1.00, duration: c * 0.35, ease: "back.out(1.2)", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -45 * a, tx: 12 * a, ty: 4 * a, sc: 1.00, duration: c * 0.20, ease: "power3.out", onUpdate });+};++export const signatureExit: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ const c = durMs / 1000, { amp, e2 } = STYLE_CFG[style], a = intensity * amp;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -45 * a, tx: 12 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX - 30 * a, ry: -20 * a, tx: -14 * a, ty: 6 * a, sc: 1.00, duration: c * 0.50, ease: e2, onUpdate })+ .to(av, { rx: NRX - 20 * a, ry: 40 * a, tx: -30 * a, ty: 15 * a, sc: 0.95, duration: c * 0.50, ease: "power4.in", onUpdate });+};+export const cinematicInEntry: ScriptFn = (av, intensity, durMs, _style, onUpdate) => {+ const c = Math.min(durMs / 1000, 4.0), a = intensity;+ return gsap.timeline()+ .set(av, { rx: NRX - 55 * a, ry: -55 * a, tx: 35 * a, ty: 12 * a, sc: 1.00 })+ .to(av, { rx: NRX - 35 * a, ry: -28 * a, tx: 14 * a, ty: 6 * a, sc: 1.00, duration: c * 0.40, ease: "power4.out", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: 0, tx: 0, ty: 0, sc: 1.06, duration: c * 0.30, ease: "expo.out", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: NRY, tx: 0, ty: -3 * a, sc: 1.00, duration: c * 0.18, ease: "back.out(1.3)", onUpdate })+ .to(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00, duration: c * 0.12, ease: "sine.inOut", onUpdate });+};++export const cinematicOutExit: ScriptFn = (av, intensity, durMs, _style, onUpdate) => {+ const c = Math.min(durMs / 1000, 3.5), a = intensity;+ return gsap.timeline()+ .set(av, { rx: NRX - 38 * a, ry: -50 * a, tx: 30 * a, ty: 4 * a, sc: 1.00 })+ .to(av, { rx: NRX - 35 * a, ry: NRY - 6 * a, tx: 3 * a, ty: -4 * a, sc: 1.02, duration: c * 0.18, ease: "sine.inOut", onUpdate })+ .to(av, { rx: NRX - 20 * a, ry: 40 * a, tx: -44 * a, ty: 15 * a, sc: 0.95, duration: c * 0.82, ease: "power3.in", onUpdate });+};++// ─── Variant registry ─────────────────────────────────────────────────────────++export const DEFAULT_VARIANT_ID = "heroReveal";++export const CAMERA_VARIANTS: CameraVariant[] = [+ {+ id: "heroReveal", label: "Hero Reveal", description: "Entrada lateral, pausa al frente, loop suave",+ icon: "ph:sparkle-bold", defaultAnimMode: "entry+exit",+ entryDuration: 2800, exitDuration: 1800,+ entryScript: heroRevealEntry, exitScript: heroRevealExit, script: heroRevealScript,+ },+ {+ id: "orbit", label: "Orbit", description: "Gira de cara a cara por ambos laterales",+ icon: "ph:arrows-clockwise-bold", defaultAnimMode: "entry+exit",+ entryDuration: 2400, exitDuration: 1600,+ entryScript: orbitEntry, exitScript: orbitExit, script: orbitScript,+ },+ {+ id: "showcase", label: "Showcase", description: "Dos poses con giro entre ellas — look Stripe",+ icon: "ph:intersect-bold", defaultAnimMode: "entry+exit",+ entryDuration: 2200, exitDuration: 1800,+ entryScript: showcaseEntry, exitScript: showcaseExit, script: showcaseScript,+ },+ {+ id: "stageEntry", label: "Stage Entry", description: "Aparece desde abajo con bounce, de cara siempre",+ icon: "ph:rocket-launch-bold", defaultAnimMode: "entry",+ entryDuration: 2500, exitDuration: 1500,+ entryScript: stageEntryEntry, exitScript: stageEntryExit, script: stageEntryScript,+ },+ {+ id: "tiltShift", label: "Tilt Shift", description: "Inclinaciones profundas — muestra los laterales",+ icon: "ph:arrows-left-right-bold", defaultAnimMode: "entry+exit",+ entryDuration: 2000, exitDuration: 1600,+ entryScript: tiltShiftEntry, exitScript: tiltShiftExit, script: tiltShiftScript,+ },+ {+ id: "gravityDrop", label: "Gravity Drop", description: "Caída física con rebote natural",+ icon: "ph:arrow-fat-down-bold", defaultAnimMode: "entry",+ entryDuration: 2200, exitDuration: 1400,+ entryScript: gravityDropEntry, exitScript: gravityDropExit, script: gravityDropScript,+ },+ {+ id: "signature", label: "Signature", description: "Drift suave + lateral lento, look brand",+ icon: "ph:seal-bold", defaultAnimMode: "entry+exit",+ entryDuration: 3200, exitDuration: 2200,+ entryScript: signatureEntry, exitScript: signatureExit, script: signatureScript,+ },+ {+ id: "cinematicIn", label: "Cinematic In", description: "Entrada cinematográfica desde arriba lateral",+ icon: "ph:film-slate-bold", defaultAnimMode: "entry",+ entryDuration: 3500, exitDuration: 1800,+ entryScript: cinematicInEntry, exitScript: cinematicOutExit, script: cinematicInScript,+ },+ {+ id: "cinematicOut", label: "Cinematic Out", description: "Pausa al frente y sale hacia arriba lateral",+ icon: "ph:arrow-fat-line-right-bold", defaultAnimMode: "exit",+ entryDuration: 2500, exitDuration: 2800,+ entryScript: cinematicInEntry, exitScript: cinematicOutExit, script: cinematicOutScript,+ },+];++// ─── Resolve the active script from a variant ID ──────────────────────────────+export function resolvePhoneScript(variantId: string): ScriptFn {+ return CAMERA_VARIANTS.find((v) => v.id === variantId)?.script ?? sweepScript;+}++// The exported ScriptFn used by Phone3DViewer — reads variant from context+// via a closure: the context value is passed in at call-site in PhoneTemplate.+export const phoneScript: ScriptFn = (av, intensity, durMs, style, onUpdate) => {+ // Default — Phone3DViewer calls this; the variant-aware version is built below.+ return sweepScript(av, intensity, durMs, style, onUpdate);+};++// ─── Easing picker ────────────────────────────────────────────────────────────+export const EASING_OPTIONS: { id: MotionStyle; label: string; path: string }[] = [+ { id: "smooth", label: "Suave", path: "M 0 48 C 16 44 32 4 48 0" },+ { id: "normal", label: "Normal", path: "M 0 48 C 12 36 36 12 48 0" },+ { id: "cinematic", label: "Cine", path: "M 0 48 C 2 46 6 2 48 0" },+];\ No newline at end of filediff --git a/lib/phone3d.utils.ts b/lib/phone3d.utils.tsnew file mode 100644index 0000000..7c7641c--- /dev/null+++ b/lib/phone3d.utils.ts@@ -0,0 +1,210 @@+/**+ * Phone3DViewer — pure helpers and constants+ *+ * Extracted from Phone3DViewer.tsx to keep the main component file focused+ * on React state, refs, and the render loop. Everything here is a pure+ * function or a module-level constant that doesn't depend on React.+ */+import * as THREE from "three";+import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";++// ─── Canvas dimensions ────────────────────────────────────────────────────────+// Based on phone-gltf.glb model dimensions:+// Model aspect ratio (width/height): 0.479+// Screen aspect ratio (width/height): 0.459+export const PHONE_H = 704;+export const PHONE_W = Math.round(PHONE_H * 0.479); // matches model aspect ratio++// Render at 4x resolution for better quality (antialiasing) AND to provide+// enough buffer space for rotations and scaling without clipping.+export const RENDER_MULTIPLIER = 4; // Important: quality+export const RENDER_W = PHONE_W * RENDER_MULTIPLIER;+export const RENDER_H = PHONE_H * RENDER_MULTIPLIER;++// Camera settings (based on appscreen-main reference: fov=20, position=[-3,-1,4])+export const CAM_FOV = 20;+export const CAM_Z = 6; // Closer to model (reference uses position.z = 4)++// ─── Device configs ───────────────────────────────────────────────────────────+// For iPhone/Samsung the GLB doesn't expose a usable screen UV, so we add a+// custom PlaneGeometry on top of the glass with the correct aspect ratio.+export type DeviceKey = "iphone" | "samsung" | "phone";++export interface DeviceConfig {+ modelUrl: string | null;+ aspectRatio: number;+ screenHeightFactor: number;+ screenOffset: { x: number; y: number; z: number };+ cornerRadiusFactor: number;+}++export const deviceConfigs: Record<DeviceKey, DeviceConfig> = {+ iphone: {+ modelUrl: "/models/iphone-15-pro-max.glb",+ aspectRatio: 1290 / 2796,+ screenHeightFactor: 0.826,+ screenOffset: { x: 0.027, y: 0.745, z: 0.098 },+ cornerRadiusFactor: 0.16,+ },+ samsung: {+ modelUrl: "/models/samsung-galaxy-s25-ultra.glb",+ aspectRatio: 1440 / 3120,+ screenHeightFactor: 0.66,+ screenOffset: { x: 0, y: 0.0, z: 0.08 },+ cornerRadiusFactor: 0.04,+ },+ phone: {+ modelUrl: "/models/phone-gltf.glb", // previously loaded from JSON, now a real GLB+ aspectRatio: 0, // uses model's built-in screen mesh UV+ screenHeightFactor: 0,+ screenOffset: { x: 0, y: 0, z: 0 },+ cornerRadiusFactor: 0,+ },+};++export function getDeviceFromModelUrl(modelUrl: string | undefined): DeviceKey {+ if (!modelUrl) return "phone";+ if (modelUrl.includes("iphone")) return "iphone";+ if (modelUrl.includes("samsung")) return "samsung";+ return "phone";+}++// ─── Screen canvas helper ────────────────────────────────────────────────────+export interface ImageMaskConfigLike {+ enabled?: boolean;+ top?: { from: number; to?: number };+ right?: { from: number; to?: number };+ bottom?: { from: number; to?: number };+ left?: { from: number; to?: number };+ angle?: number;+ angleFrom?: number;+ angleTo?: number;+}++export function createCoverScreenCanvas(+ source: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement,+ targetW: number,+ targetH: number,+ cornerRadius: number,+ maskConfig?: ImageMaskConfigLike | null+): HTMLCanvasElement {+ let srcW: number, srcH: number;+ if (source instanceof HTMLImageElement) {+ srcW = source.naturalWidth || source.width || 1;+ srcH = source.naturalHeight || source.height || 1;+ } else if (source instanceof HTMLVideoElement) {+ srcW = source.videoWidth || 1;+ srcH = source.videoHeight || 1;+ } else {+ srcW = source.width || 1;+ srcH = source.height || 1;+ }++ const scale = Math.max(targetW / srcW, targetH / srcH);+ const drawW = srcW * scale;+ const drawH = srcH * scale;+ const offsetX = (targetW - drawW) / 2;+ const offsetY = (targetH - drawH) / 2;++ const canvas = document.createElement("canvas");+ canvas.width = targetW;+ canvas.height = targetH;+ const ctx = canvas.getContext("2d")!;+ ctx.imageSmoothingEnabled = true;+ ctx.imageSmoothingQuality = "high";++ const r = Math.min(cornerRadius, Math.min(targetW, targetH) / 2);+ ctx.beginPath();+ ctx.moveTo(r, 0);+ ctx.lineTo(targetW - r, 0);+ ctx.quadraticCurveTo(targetW, 0, targetW, r);+ ctx.lineTo(targetW, targetH - r);+ ctx.quadraticCurveTo(targetW, targetH, targetW - r, targetH);+ ctx.lineTo(r, targetH);+ ctx.quadraticCurveTo(0, targetH, 0, targetH - r);+ ctx.lineTo(0, r);+ ctx.quadraticCurveTo(0, 0, r, 0);+ ctx.closePath();+ ctx.clip();++ ctx.drawImage(source, offsetX, offsetY, drawW, drawH);++ if (maskConfig?.enabled) {+ const drawGradient = (cssAngleDeg: number, from: number, to: number) => {+ const a = (cssAngleDeg * Math.PI) / 180;+ const cx = targetW / 2;+ const cy = targetH / 2;+ const diag = Math.sqrt(targetW * targetW + targetH * targetH);+ const dx = Math.sin(a) * diag;+ const dy = -Math.cos(a) * diag;+ const g = ctx.createLinearGradient(cx - dx / 2, cy - dy / 2, cx + dx / 2, cy + dy / 2);+ g.addColorStop(0, "rgba(0,0,0,1)");+ g.addColorStop(Math.max(0, Math.min(1, from / 100)), "rgba(0,0,0,1)");+ g.addColorStop(Math.max(0, Math.min(1, (to ?? 100) / 100)), "rgba(0,0,0,0)");+ ctx.globalCompositeOperation = "destination-out";+ ctx.fillStyle = g;+ ctx.fillRect(0, 0, targetW, targetH);+ ctx.globalCompositeOperation = "source-over";+ };+ if (maskConfig.top) drawGradient(180, maskConfig.top.from, maskConfig.top.to ?? 100);+ if (maskConfig.bottom) drawGradient(0, maskConfig.bottom.from, maskConfig.bottom.to ?? 100);+ if (maskConfig.left) drawGradient(90, maskConfig.left.from, maskConfig.left.to ?? 100);+ if (maskConfig.right) drawGradient(270, maskConfig.right.from, maskConfig.right.to ?? 100);+ if (maskConfig.angle !== undefined) {+ drawGradient(maskConfig.angle, maskConfig.angleFrom ?? 0, maskConfig.angleTo ?? 100);+ }+ }+ return canvas;+}++// ─── GLTF URL cache ───────────────────────────────────────────────────────────+// All models (including the default phone) are now loaded as GLB files via URL.+// The old loadGltfGroup() / GLTFLoader.parse() path is gone; everything goes+// through loadGltfFromUrl() which caches by URL so each file is fetched once.+const gltfUrlCache = new Map<string, Promise<THREE.Group>>();++export function loadGltfFromUrl(url: string): Promise<THREE.Group> {+ if (!gltfUrlCache.has(url)) {+ gltfUrlCache.set(+ url,+ new Promise<THREE.Group>((resolve, reject) =>+ new GLTFLoader().load(+ url,+ (gltf) => resolve(gltf.scene as THREE.Group),+ undefined,+ reject+ )+ )+ );+ }+ return gltfUrlCache.get(url)!;+}++/**+ * Convenience alias kept for callers that previously used loadGltfGroup().+ * Now simply delegates to loadGltfFromUrl with the default phone GLB path.+ */+export function loadGltfGroup(): Promise<THREE.Group> {+ return loadGltfFromUrl("/models/phone-gltf.glb");+}++export function cloneGroup(src: THREE.Group): THREE.Group {+ const cloned = src.clone(true);+ cloned.traverse((obj) => {+ if (obj instanceof THREE.Mesh) {+ const orig = obj.material as THREE.Material | THREE.Material[];+ if (Array.isArray(orig)) {+ obj.material = orig.map((m) => m.clone());+ } else {+ obj.material = orig.clone();+ }+ }+ });+ return cloned;+}++// ─── Math helpers ────────────────────────────────────────────────────────────+/** Shortest arc in degrees from curRy to targetRy, result in [-180, 180] */+export function shortArc(curRy: number, targetRy: number): number {+ return ((targetRy - curRy) % 360 + 540) % 360 - 180;+}\ No newline at end of filediff --git a/types/image-project.types.ts b/types/image-project.types.tsindex b0e400f..e13a863 100644--- a/types/image-project.types.ts+++ b/types/image-project.types.ts@@ -41,6 +41,20 @@ export interface ImageProject {apply3DToBackground: boolean;imageMaskConfig: ImageMaskConfig;+ // ── Motion / 3D device mockup state (image mode) ──────────────────────+ imagePhoneActive: boolean;+ imagePhoneX: number;+ imagePhoneY: number;+ imagePhoneScale: number;+ imagePhoneRotX: number;+ imagePhoneRotY: number;+ imagePhoneRotZ: number;+ imagePhonePerspective: number;+ imagePhoneDevice: 'phone' | 'iphone' | 'iphone-13-pro-max' | 'samsung' | 'laptop';+ imagePhoneOpening: number;+ imagePhoneShadow: number;+ imagePhoneShadowColor: string;+createdAt: number;}diff --git a/types/motion.types.ts b/types/motion.types.tsindex 8b32ec5..6a75732 100644--- a/types/motion.types.ts+++ b/types/motion.types.ts@@ -43,4 +43,23 @@ export interface MotionTemplate {/** Props every EditorPanel receives */export interface EditorPanelProps {template: MotionTemplate;+}++export interface CameraVariant {+ id: string;+ label: string;+ description: string;+ icon: string;+ /** Suggested default animMode for this variant */+ defaultAnimMode: AnimMode;+ /** Duration in ms for the entry animation */+ entryDuration: number;+ /** Duration in ms for the exit animation */+ exitDuration: number;+ /** Entry: dramatic pose → REST (NRX/NRY). Must end at REST. */+ entryScript: ScriptFn;+ /** Exit: REST (NRX/NRY) → dramatic pose. */+ exitScript: ScriptFn;+ /** Kept for backwards compat with one-shot preview */+ script: ScriptFn;}\ No newline at end of filediff --git a/types/photo.types.ts b/types/photo.types.tsindex 12e9584..47aa8fa 100644--- a/types/photo.types.ts+++ b/types/photo.types.ts@@ -18,11 +18,11 @@ export interface PhoneRotationOffset {export const PREVIEW_TO_PHONE_OFFSET: Record<string, PhoneRotationOffset> = {"front": { rx: 0, ry: 0 },- "top-left-angle": { rx: 15, ry: -25 },- "top-right-angle": { rx: 15, ry: 22 },- "bottom-left-angle": { rx: -15, ry: -25 },- "bottom-right-angle": { rx: -15, ry: 22 },- "isometric": { rx: 25, ry: 45 },+ "top-left-angle": { rx: 15, ry: 25 },+ "top-right-angle": { rx: 15, ry: -22 },+ "bottom-left-angle": { rx: -15, ry: 25 },+ "bottom-right-angle": { rx: -15, ry: -22 },+ "isometric": { rx: 25, ry: -45 },"tilt-up": { rx: 15, ry: 0 },"tilt-down": { rx: -15, ry: 0 },};