Search Reveal
Expanding construction circles snap into a search pill, type editable text, and reveal an abstract graphic panel.
Source
components/kuchi/search-reveal.tsx
1"use client";23import {4 AbsoluteFill,5 Easing,6 interpolate,7 useCurrentFrame,8 useVideoConfig,9} from "remotion";1011export type SearchRevealProps = {12 text?: string;13 fieldWidth?: number;14 fontSize?: number;15 framesPerCharacter?: number;16 showPanel?: boolean;17 showGuides?: boolean;18 color?: string;19 fieldColor?: string;20 ringColor?: string;21 panelColor?: string;22 accentColor?: string;23 backgroundColor?: string;24 speed?: number;25 reducedMotion?: boolean;26 className?: string;27};2829export const searchRevealLength = 90;30const finite = (value: number | undefined, fallback: number) =>31 typeof value === "number" && Number.isFinite(value) ? value : fallback;32const clamp = (value: number, min: number, max: number) =>33 Math.min(max, Math.max(min, value));34const letters = (text: string) =>35 Array.from(36 new Intl.Segmenter("en", { granularity: "grapheme" }).segment(text),37 (part) => part.segment,38 );39const curve = Easing.bezier(0.22, 1, 0.36, 1);40const tween = (frame: number, start: number, end: number, from = 0, to = 1) =>41 interpolate(frame, [start, end], [from, to], {42 extrapolateLeft: "clamp",43 extrapolateRight: "clamp",44 easing: curve,45 });4647function timing(props: SearchRevealProps) {48 const characters = letters(props.text ?? "acme");49 const step = clamp(finite(props.framesPerCharacter, 4), 1, 12);50 const end = Math.max(searchRevealLength, 54 + characters.length * step + 10);51 return { characters, step, end, speed: Math.max(0, finite(props.speed, 1)) };52}5354/** Demo duration at 30 fps, including an 18-frame final hold. */55export function getSearchRevealDuration(props: SearchRevealProps = {}) {56 const { end, speed } = timing(props);57 return speed === 0 ? 1 : Math.ceil((end + 18) / speed);58}5960/** Frame is expressed at 30 fps; playback speed is applied here. */61export function getSearchRevealState(62 frame: number,63 props: SearchRevealProps = {},64) {65 const { characters, step, end, speed } = timing(props);66 const t = props.reducedMotion ? end : Math.max(0, finite(frame, 0)) * speed;67 const typedCount = clamp(Math.floor((t - 54) / step), 0, characters.length);68 const width = clamp(finite(props.fieldWidth, 464), 320, 640);69 const reveal = props.showPanel === false ? 0 : tween(t, 56, 90);70 const fieldWidth = tween(t, 26, 48, 130, width);71 const fieldHeight = tween(t, 26, 46, 24, 80);72 const panelWidth =73 fieldWidth + (Math.max(774, width + 170) - fieldWidth) * reveal;74 const panelHeight = fieldHeight + (374 - fieldHeight) * reveal;75 return {76 t,77 end,78 typedCount,79 text: characters.slice(0, typedCount).join(""),80 circleRadius: tween(t, 0, 26, 250, 410),81 circleOffset: tween(t, 0, 26, 62, 185),82 circlesVisible: t < 26,83 fieldVisible: t >= 26,84 fieldWidth,85 fieldHeight,86 tilt: tween(t, 26, 47, -4, 0),87 iconOpacity: tween(t, 34, 46),88 panelWidth,89 panelHeight,90 panelRadius: 40 * (1 - reveal),91 panelOpacity: tween(t, 56, 60),92 reveal,93 caretVisible:94 t >= 52 &&95 t < end &&96 (typedCount < characters.length || Math.floor((t - 52) / 12) % 2 === 0),97 };98}99100function Cross({ x, y, size = 9 }: { x: number; y: number; size?: number }) {101 return (102 <path103 d={`M ${x - size} ${y} H ${x + size} M ${x} ${y - size} V ${y + size}`}104 />105 );106}107108/** A video scene: expanding construction circles, a search pill, and typed copy. */109export function SearchReveal({110 text = "acme",111 fieldWidth = 464,112 fontSize = 34,113 framesPerCharacter = 4,114 showPanel = true,115 showGuides = true,116 color = "#26232b",117 fieldColor = "#ffffff",118 ringColor = "#cbc5cf",119 panelColor = "#a800b7",120 accentColor = "#e8f99a",121 backgroundColor = "#f5f1f5",122 speed = 1,123 reducedMotion = false,124 className,125}: SearchRevealProps) {126 const frame = useCurrentFrame();127 const { width, height, fps } = useVideoConfig();128 const state = getSearchRevealState((frame * 30) / fps, {129 text,130 fieldWidth,131 framesPerCharacter,132 showPanel,133 speed,134 reducedMotion,135 });136 const scale = Math.min(width / 1280, height / 720);137 const fittedFont = Math.min(138 clamp(finite(fontSize, 34), 18, 54),139 (state.fieldWidth - 120) / Math.max(1, letters(text).length * 0.65),140 );141 const markerWidth = showPanel ? state.panelWidth : state.fieldWidth;142 const markerHeight = showPanel ? state.panelHeight : state.fieldHeight;143144 return (145 <AbsoluteFill146 className={className}147 style={{148 backgroundColor,149 overflow: "hidden",150 alignItems: "center",151 justifyContent: "center",152 }}153 >154 <div155 style={{156 width: 1280,157 height: 720,158 flexShrink: 0,159 position: "relative",160 transform: `scale(${scale})`,161 }}162 >163 {state.circlesVisible && (164 <svg165 aria-hidden="true"166 width="1280"167 height="720"168 viewBox="-640 -360 1280 720"169 style={{ position: "absolute", inset: 0, overflow: "visible" }}170 >171 <g fill="none" stroke={ringColor} strokeWidth="1">172 {[-1, 1].map((side) => (173 <g key={side}>174 <circle175 cx={side * state.circleOffset}176 r={state.circleRadius}177 />178 {showGuides &&179 [-1, 1].map((edge) => (180 <Cross181 key={edge}182 x={183 side * state.circleOffset + edge * state.circleRadius184 }185 y={0}186 size={6}187 />188 ))}189 </g>190 ))}191 </g>192 </svg>193 )}194 {state.fieldVisible && (195 <div196 style={{197 position: "absolute",198 left: "50%",199 top: "50%",200 width: 0,201 height: 0,202 transform: `rotate(${state.tilt}deg)`,203 }}204 >205 {showPanel && (206 <div207 style={{208 position: "absolute",209 left: -state.panelWidth / 2,210 top: -state.panelHeight / 2,211 width: state.panelWidth,212 height: state.panelHeight,213 borderRadius: state.panelRadius,214 overflow: "hidden",215 opacity: state.panelOpacity,216 backgroundColor: panelColor,217 }}218 >219 <svg220 aria-hidden="true"221 width="844"222 height="374"223 viewBox="0 0 844 374"224 style={{225 position: "absolute",226 left: "50%",227 top: "50%",228 transform: `translate(-50%, -50%) scale(${1.07 - state.reveal * 0.07})`,229 }}230 >231 <g232 transform={`translate(310 -45) rotate(${-24 + 10 * state.reveal})`}233 fill="none"234 stroke={fieldColor}235 >236 {Array.from({ length: 30 }, (_, i) => (237 <ellipse238 key={i}239 rx={82 + i * 3}240 ry={118}241 transform={`rotate(${i * 6})`}242 strokeWidth="1.4"243 opacity={0.35 + i / 70}244 />245 ))}246 </g>247 <g248 transform={`translate(65 233) rotate(${state.reveal * 25})`}249 fill={accentColor}250 >251 {Array.from({ length: 10 }, (_, i) => (252 <ellipse253 key={i}254 cy="-41"255 rx="19"256 ry="48"257 transform={`rotate(${i * 36})`}258 />259 ))}260 </g>261 <g262 transform={`translate(720 357) rotate(${-18 * state.reveal})`}263 fill="none"264 stroke={accentColor}265 strokeWidth="22"266 >267 <path d="M -68 -115 V 80 M -122 -60 L -14 26 M -125 18 L -12 -61" />268 <circle cx="103" cy="-35" r="54" />269 </g>270 </svg>271 </div>272 )}273 {showGuides && (274 <svg275 aria-hidden="true"276 width="1280"277 height="720"278 viewBox="-640 -360 1280 720"279 style={{280 position: "absolute",281 left: -640,282 top: -360,283 overflow: "visible",284 }}285 >286 <g287 fill="none"288 stroke={ringColor}289 strokeWidth="1"290 opacity={0.5 * state.iconOpacity}291 >292 <path293 d={`M ${markerWidth / 2} ${-markerHeight / 2 - 14} V -360 M ${-markerWidth / 2} ${markerHeight / 2 + 14} V 360`}294 />295 </g>296 <g fill="none" stroke={color} strokeWidth="1.5">297 <Cross x={-markerWidth / 2} y={markerHeight / 2} />298 <Cross x={markerWidth / 2} y={-markerHeight / 2} />299 </g>300 </svg>301 )}302 <div303 style={{304 position: "absolute",305 left: -state.fieldWidth / 2,306 top: -state.fieldHeight / 2,307 width: state.fieldWidth,308 height: state.fieldHeight,309 borderRadius: 999,310 backgroundColor: fieldColor,311 boxShadow: "0 3px 12px #26232b08, inset 0 0 0 1px #26232b0a",312 display: "flex",313 alignItems: "center",314 justifyContent: "center",315 overflow: "hidden",316 color,317 fontFamily: "Arial, Helvetica, sans-serif",318 fontSize: fittedFont,319 fontWeight: 400,320 }}321 >322 <div323 style={{324 display: "flex",325 alignItems: "center",326 justifyContent: "center",327 maxWidth: state.fieldWidth - 116,328 overflow: "hidden",329 whiteSpace: "pre",330 }}331 >332 <span>{state.text}</span>333 <span334 aria-hidden="true"335 style={{336 width: 1.5,337 height: fittedFont * 1.12,338 marginLeft: 2,339 flexShrink: 0,340 backgroundColor: color,341 opacity: state.caretVisible ? 1 : 0,342 }}343 />344 </div>345 <svg346 aria-hidden="true"347 width="28"348 height="28"349 viewBox="0 0 28 28"350 fill="none"351 stroke={ringColor}352 strokeWidth="1.5"353 strokeLinecap="round"354 style={{355 position: "absolute",356 right: 24,357 opacity: state.iconOpacity,358 }}359 >360 <circle cx="11.5" cy="11.5" r="7.5" />361 <path d="m17 17 7 7" />362 </svg>363 </div>364 </div>365 )}366 </div>367 </AbsoluteFill>368 );369}









