Skip to content

The open-source full-stack studio for Opus 5.5 motion video. Reverse engineering for any video. Code video with HTML: recreate, edit and render. BYOA + BYOK · Motion.md · Images, Video, Music & Voice.

4.4 KB
Raw Blame
// fallow-ignore-file dead-code
/**
 * Shared playhead visual used by TimelineCanvas (real playhead) and
 * TimelineEditorNotice (animated illustration).
 *
 * The vertical line + glow span the full track height; the grab-handle HEAD is
 * `position: sticky; top: 0` so it pins to the top of the (vertically) scrolling
 * track area — the ruler is sticky too, so the head stays visible and grabbable
 * no matter how far the tracks are scrolled. The head is OUTLINE-only at rest and
 * FILLED while the playhead is actively held/scrubbed (`scrubbing`).
 */
import { PLAYHEAD_HEAD_W } from "./timelineLayout";

/** Widest part of the playhead, centred on its line. */
export const PLAYHEAD_GLOW_W = 13;

interface PlayheadIndicatorProps {
  /** CSS color, defaults to the HF accent variable */
  color?: string;
  /** Glow shadow color, defaults to translucent accent */
  glowColor?: string;
  /** Whether the playhead is being actively scrubbed — fills the head. */
  scrubbing?: boolean;
  /**
   * When false, the head chip is absolutely positioned instead of using the
   * sticky pin — used by the static illustration where there is no scroll area.
   */
  stickyHead?: boolean;
}

export function PlayheadIndicator({
  color = "var(--timeline-accent)",
  glowColor = "var(--timeline-playhead-glow)",
  scrubbing = false,
  stickyHead = true,
}: PlayheadIndicatorProps) {
  // Head chip dimensions — used to compute the centering offset and the
  // point where the vertical line starts (so it begins at the head's bottom
  // edge rather than running through the hollow diamond center). The width is
  // the shared PLAYHEAD_HEAD_W constant: getTimelinePlayheadLeft shifts the
  // wrapper by -PLAYHEAD_HEAD_W/2 so the 1px line (centered at 50% of the
  // wrapper) lands exactly on GUTTER + time * pps — the ruler ticks' center x.
  const HEAD_W = PLAYHEAD_HEAD_W;
  const HEAD_H = 9;
  // Rotation expands the 9px square to ~13px. Reserve its full bounds so the
  // scroll viewport cannot clip the upper tip when the head becomes sticky.
  const HEAD_INSET = 3;
  const HEAD_TOTAL_H = Math.ceil(HEAD_INSET + HEAD_H / 2 + Math.hypot(HEAD_W, HEAD_H) / 2);

  return (
    <>
      {/* Glow — spans full height, centered on the line. */}
      <div
        aria-hidden="true"
        className="absolute top-0 bottom-0"
        style={{
          left: "50%",
          width: PLAYHEAD_GLOW_W,
          transform: "translateX(-50%)",
          background: `radial-gradient(closest-side, ${glowColor}, transparent)`,
        }}
      />
      {/* Vertical line — starts at the bottom edge of the head chip so nothing
          shows through the hollow diamond center. */}
      <div
        className="absolute bottom-0"
        style={{
          left: "50%",
          top: HEAD_TOTAL_H,
          width: 1,
          marginLeft: -0.5,
          background: color,
          boxShadow: `0 0 6px ${glowColor}`,
        }}
      />
      {/* Head chip — sticky so it pins to the ruler while tracks scroll.
          Centering logic: wrapper width = HEAD_W (chip forces it). The line sits
          at wrapper.left + HEAD_W/2 (left:"50%" of wrapper). The sticky element's
          natural flow position is wrapper.left; so placing it there with no
          horizontal translate puts its LEFT edge at wrapper.left and its CENTER
          at wrapper.left + HEAD_W/2 — exactly on the line. */}
      <div
        data-timeline-playhead-head=""
        className={stickyHead ? "sticky" : "absolute"}
        style={{
          left: 0,
          top: 0,
          width: HEAD_W,
          height: HEAD_TOTAL_H,
          // The line scrolls behind the pinned head. Mask it above the lower
          // tip too, rather than allowing it to cross the hollow diamond.
          background: stickyHead ? "var(--timeline-shell-bg)" : undefined,
        }}
      >
        <div
          style={{
            position: "absolute",
            top: HEAD_INSET,
            width: HEAD_W,
            height: HEAD_H,
            borderRadius: 2,
            // Outline-only at rest, filled while scrubbing.
            background: scrubbing ? color : stickyHead ? "var(--timeline-shell-bg)" : "transparent",
            border: `1.5px solid ${color}`,
            boxSizing: "border-box",
            boxShadow: `0 1px 3px var(--timeline-playhead-shadow), 0 0 5px ${glowColor}`,
            transform: "rotate(45deg)",
          }}
        />
      </div>
    </>
  );
}