/** * "Comment the word" + reply / "כתבו בתגובות" עם התראה (student motion library, id "mac-composer") * Use: copy this file into your Remotion project and register it in your Root: * * Render transparent: npx remotion render src/index.ts LibMacComposer out.webm --codec=vp9 --pixel-format=yuva420p --image-format=png --props=props.json * Change the words / colours / side in props.json (same keys as macComposerDefaults). 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}) => ( ); // ---------------------------------------------------------------- Mac-style parts (all drawn in code) import {loadFont as loadInter} from '@remotion/google-fonts/Inter'; const inter = loadInter('normal', {weights: ['400', '500', '600', '700', '800'], subsets: ['latin']}); /** Latin text: Inter (closest free cousin of the system font), Hebrew falls through to Heebo. */ export const INTER = `${inter.fontFamily}, "Heebo", "Helvetica Neue", Arial, sans-serif`; export const macFont = (s: string, own?: string) => own ?? (isHe(s) ? '"Heebo", "Helvetica Neue", Arial, sans-serif' : INTER); /** Tight tracking for big Latin type, none for Hebrew. */ export const macTrack = (s: string, size: number) => (isHe(s) ? 0 : size >= 90 ? '-0.035em' : size >= 48 ? '-0.022em' : size >= 28 ? '-0.01em' : 0); /** The system blue (selection, links). */ export const MAC_BLUE = '#0A84FF'; /** A smooth "spring" like the system animations: response (s) and damping ratio, closed form, starts at t0. */ export const macSpring = (t: number, t0: number, response = 0.5, damping = 0.82) => { const x = t - t0; if (x <= 0) return 0; const w0 = (2 * Math.PI) / response; if (damping >= 1) return 1 - (1 + w0 * x) * Math.exp(-w0 * x); const wd = w0 * Math.sqrt(1 - damping * damping); return 1 - Math.exp(-damping * w0 * x) * (Math.cos(wd * x) + ((damping * w0) / wd) * Math.sin(wd * x)); }; // ------------------------------------------------------------------------------------------------ glass /** * A liquid-glass plate. On a transparent render there is nothing behind it to blur, so the look comes from a soft * milky fill, a bright rim and a sheen; inside Remotion, over your footage, `backdrop-filter` also blurs what's behind. * dark = smoked glass (for light footage). */ export const Glass: React.FC<{w: number; h: number; r?: number; dark?: boolean; frost?: boolean; opacity?: number; style?: React.CSSProperties; children?: React.ReactNode; shadow?: number}> = ({w, h, r = 32, dark = false, frost = false, opacity = 1, style, children, shadow = 1}) => (
{/* the sheen: light caught on the upper left of the glass */}
{/* the rim: bright on top, a thin line all round */}
{children}
); // ------------------------------------------------------------------------------------------------ icons /** A generic blue folder (our own drawing): back with its tab, a lighter front. */ export const FolderIcon: React.FC<{size: number; color?: string; dim?: number}> = ({size, color = '#3BA6F5', dim = 0}) => { const id = `fd${color.replace('#', '')}`; return ( ); }; /** A document with a folded corner and a coloured label for its type ("MP4", "PDF"...). */ export const FileIcon: React.FC<{size: number; ext?: string; color?: string; dim?: number}> = ({size, ext = 'MP4', color = '#7C5CFF', dim = 0}) => ( {ext} ); /** A glassy trash can with ribs (our own drawing). fill 0..1 = papers inside; lid lifts with `open`. */ export const TrashIcon: React.FC<{size: number; fill?: number; open?: number}> = ({size, fill = 0, open = 0}) => ( {fill > 0 && ( )} {[36, 44, 50, 56, 64].map((x, i) => ( ))} ); /** The kinds of generic app tiles (no real app's logo). */ export type TileKind = 'files' | 'photos' | 'video' | 'music' | 'chat' | 'mail' | 'notes' | 'calendar' | 'camera' | 'ai' | 'settings' | 'design' | 'browser' | 'maps'; const TILE_BG: Record = { files: 'linear-gradient(180deg, #5ac8fa, #1e7cf2)', photos: 'linear-gradient(160deg, #ffd25e, #ff7a59 55%, #ff4f8b)', video: 'linear-gradient(160deg, #8f6bff, #4b2fd6)', music: 'linear-gradient(160deg, #ff6a88, #ff2d55)', chat: 'linear-gradient(180deg, #67e37b, #22b845)', mail: 'linear-gradient(180deg, #4fc3ff, #1475f5)', notes: 'linear-gradient(180deg, #fff6c9 0%, #fff6c9 26%, #ffffff 26%)', calendar: '#ffffff', camera: 'linear-gradient(180deg, #e9ebef, #b9bec8)', ai: 'linear-gradient(150deg, #1b1b22, #2c2a3a)', settings: 'linear-gradient(180deg, #d7dae0, #9aa0ab)', design: 'linear-gradient(160deg, #ffb340, #ff6a2c)', browser: 'linear-gradient(180deg, #ffffff, #e6ecf5)', maps: 'linear-gradient(150deg, #8ee08a 0%, #8ee08a 45%, #f4e7c5 45%)', }; const glyph = (k: TileKind, day: string): React.ReactNode => { const w = {stroke: '#fff', strokeWidth: 5, fill: 'none', strokeLinecap: 'round' as const, strokeLinejoin: 'round' as const}; switch (k) { case 'files': return ; case 'photos': return ; case 'video': return ; case 'music': return ; case 'chat': return ; case 'mail': return ; case 'notes': return {[44, 56, 68].map((y) => )}; case 'calendar': return {'MON'}{day}; case 'camera': return ; case 'ai': return ; case 'settings': return ; case 'design': return ; case 'browser': return ; case 'maps': return ; } }; /** A rounded app tile in that squircle shape, with a simple glyph. */ export const Tile: React.FC<{kind: TileKind; size: number; day?: string; style?: React.CSSProperties}> = ({kind, size, day = '10', style}) => (
{glyph(kind, day)}
); /** A file / folder name under an icon; selected = white on blue, like a desktop selection. */ export const IconLabel: React.FC<{text: string; selected?: boolean; size?: number; font?: string; maxW?: number}> = ({text, selected = false, size = 22, font, maxW = 220}) => (
{text}
); /** * A dock: glass shelf, tiles left to right, a thin divider, the trash can last. `cx`/`cy` = centre of the shelf. * grow = how much the trash swells (1 = none), magnify = index of a tile under the cursor (-1 = none). */ export const dockWidth = (n: number, size: number) => (n + 1) * size + (n + 1) * size * 0.2 + size * 0.5; export const Dock: React.FC<{apps: TileKind[]; cx: number; cy: number; size?: number; grow?: number; trashFill?: number; dark?: boolean; lift?: number[]}> = ({apps, cx, cy, size = 84, grow = 1, trashFill = 0, dark = false, lift = []}) => { const gap = size * 0.2; const w = dockWidth(apps.length, size); const h = size + gap * 1.6; const x0 = cx - w / 2; return (
{apps.map((k, i) => (
))}
); }; /** Centre x of the trash can in a dock of n apps centred on cx. */ export const dockTrashX = (n: number, cx: number, size = 84) => { const gap = size * 0.2; const x0 = cx - dockWidth(n, size) / 2; return x0 + gap + n * (size + gap) + gap * 0.5 + size / 2; }; /** Centre x of app i. */ export const dockAppX = (i: number, n: number, cx: number, size = 84) => cx - dockWidth(n, size) / 2 + size * 0.2 + i * size * 1.2 + size / 2; // ------------------------------------------------------------------------------------------------ colour /** Lighten (k > 0) or darken (k < 0) a hex colour. */ export function shade(hex: string, k: number) { const m = rgba(hex, 1).match(/\d+/g)!.slice(0, 3).map(Number); const f = (c: number) => Math.round(k >= 0 ? c + (255 - c) * k : c * (1 + k)); return `rgb(${m.map(f).join(',')})`; } // ------------------------------------------------------------------------------------------------ frosted windows (the "Mac glass" edit style) /** Pop in (spring up out of a blur) and out (shrink into a blur): the way every frosted window arrives and leaves. */ export const pop = (t: number, total: number, t0 = 0.05, outDur = 0.38): React.CSSProperties & {k: number} => { const k = macSpring(t, t0, 0.5, 0.74); const o = Math.min(1, Math.max(0, (t - (total - outDur)) / outDur)); const oe = o * o; const blur = Math.max(0, (1 - k) * 14) + oe * 12; return {k, opacity: Math.min(1, Math.max(0, k * 1.8)) * (1 - oe), transform: `scale(${(0.82 + 0.18 * k) * (1 - 0.1 * oe)}) translateY(${(1 - k) * 24}px)`, filter: blur > 0.3 ? `blur(${blur}px)` : undefined}; }; /** The three window dots. */ export const Lights: React.FC<{size?: number}> = ({size = 15}) => (
{['#FF5F57', '#FEBC2E', '#28C840'].map((c) =>
)}
); /** A frosted window: dots on the left, a small grey title in the middle, then the content. dark = terminal glass. */ export const Win: React.FC<{w: number; h: number; title: string; dark?: boolean; font?: string; children?: React.ReactNode; style?: React.CSSProperties}> = ({w, h, title, dark = false, font, children, style}) => (
{title}
{children}
); /** A frosted pill with text (an emoji / icon before it is fine). */ export const Pill: React.FC<{text: React.ReactNode; size?: number; w?: number; font?: string; rtl?: boolean; style?: React.CSSProperties}> = ({text, size = 34, w, font, rtl = true, style}) => (
{text}
); /** Dark ink for text on frosted glass. */ export const INK = '#1f1f24'; export const INK2 = 'rgba(31,31,36,0.45)'; // ---------------------------------------------------------------- the scene /** * Mac style: "comment the word". A frosted message box types a word, the blue send button pops, a small line under it * says where to write it, then a notification card slides in with the reply. 4.8 s. Great for a call to action. * Design: a clean message box + notification, drawn in code. */ export type MacComposerProps = Base & { word: string; placeholder: string; hint: string; // under the box reply: string; // the notification ('' = none) replyFrom: string; }; export const macComposerDefaults: MacComposerProps = { duration: 4.8, side: 'center', y: 30, word: 'עריכה', placeholder: 'הודעה', hint: 'כתבו בתגובות 👇', reply: 'שלחתי לך את כל הפרטים ✨', replyFrom: 'הודעה חדשה', }; const W = 820; const BOX = 120; const H = BOX + 90 + 190; export const MacComposer: React.FC = (props) => { const p = {...macComposerDefaults, ...props}; const t = useT(); const total = p.duration!; const rtl = dirOf(p.word + p.hint + p.reply) === 'rtl'; const font = macFont(p.word + p.hint, p.font); const {k: _k, ...all} = pop(t, total); const typeA = 0.55; const typeB = typeA + Math.min(0.9, p.word.length * 0.11); const chars = Math.round(p.word.length * p01(t, typeA, typeB)); const send = macSpring(t, typeB + 0.1, 0.3, 0.45); const hint = macSpring(t, typeB + 0.25, 0.45, 0.75); const note = p.reply ? macSpring(t, typeB + 0.95, 0.5, 0.7) : 0; const caret = t < typeB + 0.1 && Math.floor(t * 2.4) % 2 === 0 ? 1 : 0; return (
{chars ? p.word.slice(0, chars) : p.placeholder}
{p.hint}
{p.reply ? (
{p.replyFrom}
{p.reply}
) : null}
); }; export const meta = {id: 'LibMacComposer', component: MacComposer, defaults: macComposerDefaults};