/** * Like burst + counter / לייק עם פיצוץ לבבות (student motion library, id "ui-like-burst") * Use: copy this file into your Remotion project and register it in your Root: * * Render transparent: npx remotion render src/index.ts LibUiLike out.webm --codec=vp9 --pixel-format=yuva420p --image-format=png --props=props.json * Change the words / colours / side in props.json (same keys as likeDefaults). A vertical video: width 1080, height 1920. */ // ---------------------------------------------------------------- helpers (shared by every library scene) // Conventions: 1920x1080, 30 fps, transparent background. Sizes follow the frame's short side, so 1080x1920 works too. // Common props: duration (s), side 'right' | 'left' | 'center', x / y (centre in % of the frame, override side), // scale, font (a CSS font-family; default Heebo). Time is in seconds; the first and last frames are empty. import React from 'react'; import {AbsoluteFill, Easing, useCurrentFrame, useVideoConfig} from 'remotion'; import {loadFont as loadHeebo} from '@remotion/google-fonts/Heebo'; const heebo = loadHeebo('normal', {weights: ['400', '500', '700', '800', '900'], subsets: ['hebrew', 'latin']}); /** Hebrew + Latin font (Google "Heebo"). props.font overrides it per scene. */ export const HEEBO = `${heebo.fontFamily}, "Helvetica Neue", Arial, sans-serif`; export const MONO = 'ui-monospace, "SF Mono", Menlo, Consolas, monospace'; export type Side = 'right' | 'left' | 'center'; export type Base = {duration?: number; side?: Side; x?: number; y?: number; scale?: number; font?: string}; export const clamp01 = (x: number) => Math.min(1, Math.max(0, x)); /** 0..1 progress of t between a and b (seconds) */ export const p01 = (t: number, a: number, b: number) => clamp01((t - a) / (b - a)); export const lerp = (a: number, b: number, k: number) => a + (b - a) * k; export const outE = Easing.bezier(0.16, 1, 0.3, 1); // fast out, long settle export const inOut = Easing.bezier(0.65, 0, 0.35, 1); export const inE = Easing.bezier(0.55, 0, 0.9, 0.45); export const backOut = (x: number, s = 1.7) => (x <= 0 ? 0 : x >= 1 ? 1 : 1 + (s + 1) * Math.pow(x - 1, 3) + s * Math.pow(x - 1, 2)); /** Damped spring 0 -> 1 starting at t0 (closed form, so any frame computes on its own). */ export const spr = (t: number, t0: number, freq = 16, damp = 9) => { const x = t - t0; return x <= 0 ? 0 : 1 - Math.exp(-damp * x) * Math.cos(freq * x); }; /** Deterministic pseudo random 0..1 */ export const rnd = (i: number, seed = 1) => { const v = Math.sin(i * 127.1 + seed * 311.7) * 43758.5453; return v - Math.floor(v); }; export const isHe = (s: string) => /[֐-׿]/.test(s); export const dirOf = (s: string): 'rtl' | 'ltr' => (isHe(s) ? 'rtl' : 'ltr'); /** "#a1b2c3" / "#abc" + alpha -> rgba() */ export const rgba = (hex: string, a = 1) => { let h = hex.replace('#', ''); if (h.length === 3) h = h.split('').map((ch) => ch + ch).join(''); const n = parseInt(h.slice(0, 6), 16); return `rgba(${(n >> 16) & 255},${(n >> 8) & 255},${n & 255},${a})`; }; export const useT = () => { const f = useCurrentFrame(); const {fps} = useVideoConfig(); return f / fps; }; /** 12345 -> "12,345" */ export const fmt = (n: number, sep = ',') => Math.round(n).toString().replace(/\B(?=(\d{3})+(?!\d))/g, sep); /** Arrive (scale up out of a blur) and leave (shrink into a blur) for a whole group. */ export const life = (t: number, total: number, inDur = 0.45, outDur = 0.35) => { const a = p01(t, 0, inDur); const z = inOut(p01(t, total - outDur, total)); return { opacity: clamp01(a * 2.2) * (1 - z), scale: lerp(0.82, 1, backOut(a, 1.4)) * (1 - 0.08 * z), blur: (1 - outE(a)) * 12 + z * 10, style: {} as React.CSSProperties, }; }; export const lifeStyle = (t: number, total: number, inDur = 0.45, outDur = 0.35): React.CSSProperties => { const l = life(t, total, inDur, outDur); return {opacity: l.opacity, transform: `scale(${l.scale})`, filter: l.blur > 0.2 ? `blur(${l.blur}px)` : undefined}; }; /** * Places a w x h box (design pixels of a 1080-high frame) on its side of the frame and scales it with the frame's * short side and props.scale. Children are positioned inside the box. */ export const Stage: React.FC<{p: Base; w: number; h: number; children: React.ReactNode; style?: React.CSSProperties; defSide?: Side}> = ({p, w, h, children, style, defSide = 'center'}) => { const {width: W, height: H} = useVideoConfig(); const u = (Math.min(W, H) / 1080) * (p.scale ?? 1); const side = p.side ?? defSide; const cx = ((p.x ?? (side === 'right' ? 73 : side === 'left' ? 27 : 50)) / 100) * W; const cy = ((p.y ?? 50) / 100) * H; return (
{children}
); }; /** Soft two-layer drop shadow for cards on any footage */ export const SHADOW = '0 22px 48px rgba(12,12,20,0.22), 0 4px 12px rgba(12,12,20,0.14)'; /** The classic arrow cursor; (x, y) = its tip; press 0..1 = mouse down. */ export const Cursor: React.FC<{x: number; y: number; press?: number; size?: number; fill?: string; stroke?: string}> = ({x, y, press = 0, size = 1.6, fill = '#111', stroke = '#fff'}) => { const s = size * (1 - 0.12 * press); return ( ); }; /** A four-point sparkle centred on (0,0) in a -50..50 box. */ export const SPARK_PATH = 'M0 -50 C 6 -14 14 -6 50 0 C 14 6 6 14 0 50 C -6 14 -14 6 -50 0 C -14 -6 -6 -14 0 -50 Z'; export const Spark: React.FC<{x: number; y: number; size: number; color: string; rotate?: number; opacity?: number; glow?: boolean}> = ({x, y, size, color, rotate = 0, opacity = 1, glow = false}) => ( ); // ---------------------------------------------------------------- the scene /** * Like chip: a finger taps the heart, it squashes and pops full, a ring and a burst of dots + mini hearts fly out, the * counter rolls up by one, then a few hearts float up like live reactions. 3.6 s. * Inspired by "like" button bursts (LottieFiles / Dribbble), redesigned: a reaction chip with an odometer + live hearts. */ export type LikeProps = Base & { count: number; heart: string; // the full heart colour burst: string[]; // particle colours chip: string; // chip background ink: string; // number colour }; export const likeDefaults: LikeProps = { duration: 3.6, side: 'right', count: 2481, heart: '#FF3B6B', burst: ['#FFB020', '#7C5CFF', '#22C3A6', '#FF3B6B'], chip: '#ffffff', ink: '#16151a', }; const HEART = 'M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'; const Heart: React.FC<{size: number; fill: string; stroke?: string; sw?: number}> = ({size, fill, stroke = 'none', sw = 0}) => ( ); /** digits of a number; changed digits roll up from the old to the new one */ const Roll: React.FC<{from: number; to: number; k: number; size: number; color: string; font: string}> = ({from, to, k, size, color, font}) => { const a = from.toLocaleString('en-US'); const b = to.toLocaleString('en-US').padStart(a.length, ' '); const A = a.padStart(b.length, ' '); const h = size * 1.15; return (
{b.split('').map((ch, i) => { const same = ch === A[i]; return (
{same ? (
{ch}
) : (
{A[i]}
{ch}
)}
); })}
); }; export const UiLike: React.FC = (props) => { const p = {...likeDefaults, ...props}; const t = useT(); const font = p.font ?? HEEBO; const TAP = 1.0; const W = 420; const H = 150; const hx = 95; // heart centre in the chip const hy = H / 2; const liked = t >= TAP; const squash = t < TAP ? 1 - 0.22 * p01(t, TAP - 0.18, TAP) : lerp(0.78, 1, spr(t, TAP, 18, 7)); const ring = p01(t, TAP, TAP + 0.45); const roll = outE(p01(t, TAP + 0.05, TAP + 0.5)); const touch = p01(t, TAP - 0.3, TAP - 0.12) * (1 - p01(t, TAP + 0.05, TAP + 0.3)); return (
{/* live hearts floating up */} {Array.from({length: 7}, (_, i) => { const t0 = TAP + 0.45 + i * 0.17; const k = p01(t, t0, t0 + 1.3); if (k <= 0 || k >= 1) return null; const sz = 34 + rnd(i, 2) * 26; const x = hx + Math.sin(k * 5 + i) * (18 + rnd(i, 4) * 20) + (rnd(i, 6) - 0.5) * 40; const y = 360 + hy - k * 330; const c = i % 3 === 1 ? p.burst[1 % p.burst.length] : p.heart; return (
); })} {/* the chip */}
{/* ring */} {liked && ring < 1 && (
)} {/* particles */} {liked && Array.from({length: 12}, (_, i) => { const a = (i / 12) * Math.PI * 2 + 0.2; const k = outE(p01(t, TAP + 0.04, TAP + 0.75)); const r = lerp(40, 118 + rnd(i, 3) * 26, k); const s = (i % 2 ? 16 : 24) * (1 - p01(t, TAP + 0.35, TAP + 0.8)); const col = p.burst[i % p.burst.length]; return i % 3 === 0 ? (
) : (
); })} {/* the heart */}
{liked ? : }
{/* the finger */} {touch > 0 && (
)}
); }; export const meta = {id: 'LibUiLike', component: UiLike, defaults: likeDefaults};