/** * Toolbar hover tooltips / סרגל כלים עם טולטיפים (student motion library, id "cur-hover-tooltip") * Use: copy this file into your Remotion project and register it in your Root: * * Render transparent: npx remotion render src/index.ts LibCurHoverTooltip out.webm --codec=vp9 --pixel-format=yuva420p --image-format=png --props=props.json * Change the words / colours / side in props.json (same keys as hoverTooltipDefaults). 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 /** * Hover tooltips: a floating toolbar slides up, the cursor hops from tool to tool and each one lights up with a * tooltip that springs out above it; the last tool gets clicked, turns on and its tooltip changes. 4.8 s. * Inspired by animated CSS tooltips (CodePen: bouncing tool-tip, scale-in tooltip), redesigned: a toolbar tour with * a cursor and an "on" state. */ export type HoverTooltipProps = Base & { tools: {icon: 'cut' | 'text' | 'music' | 'export' | 'zoom' | 'magic'; label: string}[]; clickedLabel: string; accent: string; bar: string; tip: string; }; export const hoverTooltipDefaults: HoverTooltipProps = { duration: 4.8, side: 'right', tools: [ {icon: 'cut', label: 'חיתוך'}, {icon: 'text', label: 'כתוביות'}, {icon: 'music', label: 'מוזיקה'}, {icon: 'magic', label: 'עריכה אוטומטית'}, ], clickedLabel: 'עובד על זה...', accent: '#7C5CFF', bar: '#ffffff', tip: '#16151a', }; const ICONS: Record = { cut: 'M6 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM20 4L8.1 15.9M14.5 14.5L20 20M8.1 8.1L12 12', text: 'M4 6V4h16v2M12 4v16M9 20h6', music: 'M9 18V5l11-2v13M9 18a3 3 0 1 1-6 0 3 3 0 0 1 6 0zM20 16a3 3 0 1 1-6 0 3 3 0 0 1 6 0z', export: 'M12 15V3M7 8l5-5 5 5M5 14v5a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-5', zoom: 'M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM20 20l-4-4M11 8v6M8 11h6', magic: 'M15 4V2M15 16v-2M8 9h2M20 9h2M17.8 11.8L19 13M17.8 6.2L19 5M3 21l9-9M12.2 6.2L11 5', }; const BTN = 104; const GAP = 14; export const CurHoverTooltip: React.FC = (props) => { const p = {...hoverTooltipDefaults, ...props}; const t = useT(); const font = p.font ?? HEEBO; const rtl = dirOf(p.tools.map((x) => x.label).join('')) === 'rtl'; const n = p.tools.length; const BW = n * BTN + (n - 1) * GAP + 28; const W = Math.max(BW + 200, 760); const H = 400; const bx = (W - BW) / 2; const by = 220; const centre = (i: number) => { const k = rtl ? n - 1 - i : i; // tour in reading order return [bx + 14 + k * (BTN + GAP) + BTN / 2, by + 14 + BTN / 2]; }; const T0 = 0.75; const STEP = 0.72; const arrive = (i: number) => T0 + i * STEP; const CLICK = arrive(n - 1) + 0.35; // cursor: hops between the tools let cx = rtl ? -60 : W + 60; let cy = H + 60; for (let i = 0; i < n; i++) { const [x, y] = centre(i); const k = inOut(p01(t, arrive(i) - 0.32, arrive(i))); if (k > 0) { cx = lerp(cx, x + 8, k); cy = lerp(cy, y + 10, k) + Math.sin(k * Math.PI) * 26; } } const leave = inOut(p01(t, CLICK + 0.6, CLICK + 1.1)); cx = lerp(cx, cx + (rtl ? -50 : 50), leave); cy = lerp(cy, H + 70, leave); const hoverOf = (i: number) => (t >= arrive(i) - 0.05 && (i === n - 1 ? t < CLICK + 0.75 : t < arrive(i + 1) - 0.2) ? 1 : 0); const press = p01(t, CLICK - 0.08, CLICK) * (1 - p01(t, CLICK + 0.05, CLICK + 0.2)); const on = t > CLICK; const barIn = spr(t, 0.1, 14, 9); return (
{p.tools.map((tool, i) => { const [x, y] = centre(i); const hov = hoverOf(i); const isOn = on && i === n - 1; const tipK = hov ? spr(t, arrive(i) - 0.02, 18, 9) : 0; return (
{tipK > 0.01 && (
{isOn ? p.clickedLabel : tool.label}
)} ); })} {t > arrive(0) - 0.5 && leave < 1 && }
); }; export const meta = {id: 'LibCurHoverTooltip', component: CurHoverTooltip, defaults: hoverTooltipDefaults};