|
| 1 | +import { quintIn, quintOut, quintInOut } from "svelte/easing"; |
| 2 | +import type { TransitionConfig } from "svelte/transition"; |
| 3 | + |
| 4 | +export function crtShutdown( |
| 5 | + _: Element, |
| 6 | + { delay = 0, duration = 550 } = {}, |
| 7 | +): TransitionConfig { |
| 8 | + return { |
| 9 | + delay, |
| 10 | + duration, |
| 11 | + easing: quintOut, |
| 12 | + css: (t: number) => { |
| 13 | + // Invert t since this is outro (t:0->1 intro, want progress 1->0) |
| 14 | + const progress = 1 - t; |
| 15 | + |
| 16 | + // Vertical jitter for old CRT wobble effect |
| 17 | + const jitter = 2 * Math.sin(progress * 50); |
| 18 | + |
| 19 | + let scaleX: number, scaleY: number; |
| 20 | + let brightness: number, contrast: number, saturate: number; |
| 21 | + let glowOpacity: number; |
| 22 | + let opacity = 1; |
| 23 | + |
| 24 | + if (progress <= 0.6) { |
| 25 | + // First 60% of the animation |
| 26 | + const localT = progress / 0.6; |
| 27 | + |
| 28 | + // Eased scaling |
| 29 | + scaleX = 1 + 0.3 * quintInOut(localT); |
| 30 | + scaleY = 1.3 - 1.299 * quintInOut(localT); |
| 31 | + |
| 32 | + // Filters for bright white flash glow |
| 33 | + brightness = 1 + 9 * localT; |
| 34 | + contrast = 1 + 10 * localT; |
| 35 | + saturate = 1 + 30 * localT; |
| 36 | + |
| 37 | + // Pulsing glow opacity (2 full pulses) |
| 38 | + glowOpacity = 0.8 * Math.sin(progress * Math.PI * 4) ** 2; |
| 39 | + } else { |
| 40 | + // Last 40% of animation with easing |
| 41 | + const localT = (progress - 0.6) / 0.4; |
| 42 | + const easedT = quintIn(localT); |
| 43 | + |
| 44 | + scaleX = 1.3 - 1.3 * easedT; |
| 45 | + scaleY = 0.001 - 0.0009 * easedT; |
| 46 | + |
| 47 | + brightness = 10 + 40 * easedT; |
| 48 | + contrast = 11 + 39 * easedT; |
| 49 | + saturate = 31 + 69 * easedT; |
| 50 | + |
| 51 | + glowOpacity = 0.8 * Math.sin(progress * Math.PI * 4) ** 2; |
| 52 | + } |
| 53 | + |
| 54 | + // Flickering opacity in last 10% of shutdown, smoothed out to avoid flicker at very end |
| 55 | + if (progress < 0.1) { |
| 56 | + opacity = 0.7 + 0.3 * Math.random(); |
| 57 | + } |
| 58 | + |
| 59 | + // Chromatic aberration effect with subtle colored drop shadows, softer with blur |
| 60 | + const chroma = ` |
| 61 | + drop-shadow(1.5px 0 rgba(255, 0, 0, 0.5)) |
| 62 | + drop-shadow(-1.5px 0 rgba(0, 255, 255, 0.5)) |
| 63 | + drop-shadow(0 1.5px rgba(0, 0, 255, 0.3)) |
| 64 | + `; |
| 65 | + |
| 66 | + // Soften the white glow box-shadow: less spread, more blur, less opacity |
| 67 | + const softGlow = `inset 0 0 50px 30px rgba(255,255,255,${glowOpacity.toFixed(2)})`; |
| 68 | + |
| 69 | + return ` |
| 70 | + transform: scale(${scaleX.toFixed(3)}, ${scaleY.toFixed(3)}) translate3d(0, ${jitter.toFixed(2)}px, 0); |
| 71 | + filter: brightness(${brightness.toFixed(2)}) contrast(${contrast.toFixed(2)}) saturate(${saturate.toFixed(2)}) ${chroma}; |
| 72 | + box-shadow: ${softGlow}; |
| 73 | + opacity: ${opacity.toFixed(2)}; |
| 74 | + `; |
| 75 | + }, |
| 76 | + }; |
| 77 | +} |
0 commit comments