Check List
A handwritten checklist that writes itself out in full, then ticks and strikes through every done item, one at a time.
Source
components/kuchi/check-list.tsx
1"use client";23import { useCurrentFrame } from "remotion";4import { Handwrite, handwriteDuration } from "@/components/kuchi/handwrite";5import { DEFAULT_STEP, hashRange, steppedRamp } from "@/lib/kuchi/stop-motion";67const easeOutCubic = (t: number) => 1 - (1 - t) ** 3;89const DEFAULT_PER_STEP = 1.6;1011export type CheckListItem = {12 text: string;13 checked?: boolean;14};1516export type CheckListEntry = {17 text: string;18 checked: boolean;19};2021export type CheckListGeometry = {22 boxSize: number;23 boxGap: number;24 rowHeight: number;25 labelWidth: number;26};2728export type CheckListBeat = {29 boxFrom: number;30 boxTo: number;31 labelAt: number;32 labelEnd: number;33 tickFrom?: number;34 tickTo?: number;35 strikeFrom?: number;36 strikeTo?: number;37};3839export type CheckListTiming = {40 delay?: number;41 itemGap?: number;42 perStep?: number;43 step?: number;44 closeGap?: number;45};4647export function normalizeCheckListItems(48 items: (string | CheckListItem)[],49): CheckListEntry[] {50 return items.map((item) =>51 typeof item === "string"52 ? { text: item, checked: true }53 : { text: item.text, checked: item.checked ?? true },54 );55}5657export function checkListGeometry(58 width: number,59 fontSize: number,60): CheckListGeometry {61 const boxSize = Math.round(fontSize * 0.62);62 const boxGap = Math.round(fontSize * 0.4);63 return {64 boxSize,65 boxGap,66 rowHeight: Math.round(fontSize * 1.15),67 labelWidth: Math.max(fontSize * 2, width - boxSize - boxGap),68 };69}7071export function checkListRowWidth(width: number, fontSize: number): number {72 const { boxSize, boxGap, labelWidth } = checkListGeometry(width, fontSize);73 return boxSize + boxGap + labelWidth;74}7576export function checkListEnterEnd(77 items: (string | CheckListItem)[],78 options?: CheckListTiming,79): number {80 const step = options?.step ?? DEFAULT_STEP;81 const delay = options?.delay ?? 0;82 const itemGap = options?.itemGap ?? step * 6;83 const perStep = options?.perStep ?? DEFAULT_PER_STEP;8485 return normalizeCheckListItems(items).reduce(86 (end, item, i) =>87 Math.max(88 end,89 delay +90 i * itemGap +91 step * 2 +92 handwriteDuration(item.text, { perStep, step }),93 ),94 delay,95 );96}9798export function checkListSchedule(99 items: (string | CheckListItem)[],100 options?: CheckListTiming,101): CheckListBeat[] {102 const step = options?.step ?? DEFAULT_STEP;103 const delay = options?.delay ?? 0;104 const itemGap = options?.itemGap ?? step * 6;105 const perStep = options?.perStep ?? DEFAULT_PER_STEP;106 const closeGap = options?.closeGap ?? step * 3;107 const entries = normalizeCheckListItems(items);108 const enterEnd = checkListEnterEnd(entries, options);109110 const closeOrder = new Map<number, number>();111 entries.forEach((item, i) => {112 if (item.checked) {113 closeOrder.set(i, closeOrder.size);114 }115 });116117 return entries.map((item, i) => {118 const boxFrom = delay + i * itemGap;119 const boxTo = boxFrom + step * 2;120 const labelEnd = boxTo + handwriteDuration(item.text, { perStep, step });121 const slot = closeOrder.get(i);122 if (slot === undefined) {123 return { boxFrom, boxTo, labelAt: boxTo, labelEnd };124 }125 const tickFrom = enterEnd + slot * closeGap;126 const tickTo = tickFrom + step * 2;127 return {128 boxFrom,129 boxTo,130 labelAt: boxTo,131 labelEnd,132 tickFrom,133 tickTo,134 strikeFrom: tickTo,135 strikeTo: tickTo + step * 2,136 };137 });138}139140export function checkListDuration(141 items: (string | CheckListItem)[],142 options?: CheckListTiming,143): number {144 return checkListSchedule(items, options).reduce(145 (end, beat) => Math.max(end, beat.strikeTo ?? beat.labelEnd),146 0,147 );148}149150const boxPath = (size: number, seed: string, index: number): string => {151 const nudge = (n: number) => hashRange(`${seed}:${index}:c${n}`, -1.5, 1.5);152 const lo = size * 0.08;153 const hi = size - lo;154 const corners: [number, number][] = [155 [lo + nudge(0), lo + nudge(1)],156 [hi + nudge(2), lo + nudge(3)],157 [hi + nudge(4), hi + nudge(5)],158 [lo + nudge(6), hi + nudge(7)],159 ];160 const [start, ...rest] = corners;161 return `M ${start[0]} ${start[1]} ${rest162 .map(([x, y]) => `L ${x} ${y}`)163 .join(" ")} Z`;164};165166const tickPath = (size: number): string =>167 `M ${size * 0.2} ${size * 0.52} L ${size * 0.42} ${size * 0.78} L ${size * 0.88} ${size * 0.14}`;168169const CAVEAT_ADVANCE = 0.36;170171export function checkListStrikeWidth(172 text: string,173 fontSize: number,174 labelWidth: number,175): number {176 return Math.min(177 labelWidth,178 Array.from(text).length * fontSize * CAVEAT_ADVANCE,179 );180}181182const strikePath = (183 reach: number,184 fontSize: number,185 rowHeight: number,186 seed: string,187 index: number,188): string => {189 const lift = (n: number) => hashRange(`${seed}:${index}:s${n}`, -1.6, 1.6);190 const overshoot = fontSize * 0.07;191 const mid = rowHeight / 2;192 return `M ${-overshoot} ${mid + lift(0)} C ${reach * 0.35} ${mid + lift(1)}, ${reach * 0.7} ${mid + lift(2)}, ${reach + overshoot} ${mid + lift(3)}`;193};194195export interface CheckListProps {196 items?: (string | CheckListItem)[];197 width?: number;198 fontSize?: number;199 color?: string;200 boxColor?: string;201 tickColor?: string;202 delay?: number;203 itemGap?: number;204 closeGap?: number;205 rowGap?: number;206 strokeWidth?: number;207 perStep?: number;208 weight?: 400 | 500 | 600 | 700;209 seed?: string;210 step?: number;211}212213export function CheckList({214 items = ["Write the launch post", "Record the demo", { text: "Ship it", checked: false }],215 width = 720,216 fontSize = 40,217 color = "#26242c",218 boxColor = "#26242c",219 tickColor = "#6f7f35",220 delay = 0,221 itemGap,222 closeGap,223 rowGap,224 strokeWidth = 3,225 perStep = DEFAULT_PER_STEP,226 weight = 600,227 seed = "checklist",228 step = DEFAULT_STEP,229}: CheckListProps) {230 const frame = useCurrentFrame();231 const entries = normalizeCheckListItems(items);232 const schedule = checkListSchedule(entries, {233 delay,234 itemGap,235 closeGap,236 perStep,237 step,238 });239 const { boxSize, boxGap, rowHeight, labelWidth } = checkListGeometry(240 width,241 fontSize,242 );243244 return (245 <div246 style={{247 width: checkListRowWidth(width, fontSize),248 display: "flex",249 flexDirection: "column",250 gap: rowGap ?? fontSize * 0.55,251 }}252 >253 {entries.map((item, i) => {254 const beat = schedule[i];255 const boxProgress = steppedRamp(frame, beat.boxFrom, beat.boxTo, {256 ease: easeOutCubic,257 step,258 });259 const tickProgress =260 beat.tickFrom === undefined || beat.tickTo === undefined261 ? 0262 : steppedRamp(frame, beat.tickFrom, beat.tickTo, {263 ease: easeOutCubic,264 step,265 });266 const strikeProgress =267 beat.strikeFrom === undefined || beat.strikeTo === undefined268 ? 0269 : steppedRamp(frame, beat.strikeFrom, beat.strikeTo, {270 ease: easeOutCubic,271 step,272 });273274 return (275 <div276 key={`${item.text}:${i}`}277 style={{278 display: "flex",279 alignItems: "center",280 gap: boxGap,281 height: rowHeight,282 }}283 >284 <svg285 width={boxSize}286 height={boxSize}287 viewBox={`0 0 ${boxSize} ${boxSize}`}288 style={{ display: "block", overflow: "visible", flexShrink: 0 }}289 >290 <path291 d={boxPath(boxSize, seed, i)}292 stroke={boxColor}293 strokeWidth={strokeWidth}294 strokeLinecap="round"295 strokeLinejoin="round"296 fill="none"297 pathLength={1}298 strokeDasharray={1}299 strokeDashoffset={1 - boxProgress}300 opacity={boxProgress > 0 ? 0.9 : 0}301 />302 {item.checked ? (303 <path304 d={tickPath(boxSize)}305 stroke={tickColor}306 strokeWidth={strokeWidth + 1}307 strokeLinecap="round"308 strokeLinejoin="round"309 fill="none"310 pathLength={1}311 strokeDasharray={1}312 strokeDashoffset={1 - tickProgress}313 opacity={tickProgress > 0 ? 1 : 0}314 />315 ) : null}316 </svg>317 <div318 style={{319 position: "relative",320 flexShrink: 0,321 width: labelWidth,322 height: rowHeight,323 }}324 >325 <Handwrite326 text={item.text}327 fontSize={fontSize}328 color={color}329 delay={beat.labelAt}330 perStep={perStep}331 weight={weight}332 align="left"333 step={step}334 />335 {item.checked ? (336 <svg337 width={labelWidth}338 height={rowHeight}339 viewBox={`0 0 ${labelWidth} ${rowHeight}`}340 style={{341 position: "absolute",342 inset: 0,343 display: "block",344 overflow: "visible",345 }}346 >347 <path348 d={strikePath(349 checkListStrikeWidth(item.text, fontSize, labelWidth),350 fontSize,351 rowHeight,352 seed,353 i,354 )}355 stroke={tickColor}356 strokeWidth={strokeWidth}357 strokeLinecap="round"358 fill="none"359 pathLength={1}360 strokeDasharray={1}361 strokeDashoffset={1 - strikeProgress}362 opacity={strikeProgress > 0 ? 0.85 : 0}363 />364 </svg>365 ) : null}366 </div>367 </div>368 );369 })}370 </div>371 );372}









