"use client"; import { useEffect, useRef, useState } from "react"; // HIDDEN REGIONS OVER A PLAYER (lane clip-kit, slice E; report-to-video clip-censor.mjs). Where a clip's raw window // plays -- Present (its public page too), the clip editor, the bench -- the boxes its recording and the clip hide are // drawn over the picture: the same boxes (fractions of the source picture), the same spans (source seconds), black // where the build fills black, a heavy backdrop blur where it blurs or pixelates. `mode`: // "cover" opaque, always (Present: a viewer, public or not, never sees the region) // "edit" an editing surface: the fill and a dashed outline, and a Peek toggle (OFF by default) that drops the fill // The picture's rect inside the player is measured (an element fitted with object-contain), so the boxes stand on // the picture, not on its letterbox. export type CensorRegion = { box: number[]; style: "blur" | "black" | "pixelate"; strength: number; from: number | null; to: number | null }; /** The regions over source second `at` (all, when `at` is unknown: a still frame shows them all). */ export const regionsAt = (regions: CensorRegion[], at: number | null) => regions.filter((g) => at === null || ((g.from === null || at >= g.from - 1e-6) && (g.to === null || at <= g.to + 1e-6))); export default function CensorOverlay({ regions, at, aspect, mode = "cover", testId = "censor-overlay" }: { regions: CensorRegion[]; at: number | null; /** The picture's width / height (its videoWidth / videoHeight); null until known (the whole box is used). */ aspect: number | null; mode?: "cover" | "edit"; testId?: string; }) { const box = useRef(null); const [size, setSize] = useState<{ w: number; h: number } | null>(null); const [peek, setPeek] = useState(false); useEffect(() => { const el = box.current; if (!el) return; const ro = new ResizeObserver(() => setSize({ w: el.clientWidth, h: el.clientHeight })); ro.observe(el); setSize({ w: el.clientWidth, h: el.clientHeight }); return () => ro.disconnect(); }, []); const now = regionsAt(regions, at); // The picture's rect in the player (object-contain). let pic = { x: 0, y: 0, w: size?.w ?? 0, h: size?.h ?? 0 }; if (size && aspect && size.w > 0 && size.h > 0) { const k = Math.min(size.w / aspect, size.h); pic = { x: (size.w - k * aspect) / 2, y: (size.h - k) / 2, w: k * aspect, h: k }; } return (
{size && now.map((g, i) => { const fill = mode === "edit" && peek ? {} : g.style === "black" ? { background: "#000" } : { backdropFilter: `blur(${Math.max(8, Math.round(pic.w * g.strength * 0.004 * (g.style === "pixelate" ? 2 : 1)))}px)`, WebkitBackdropFilter: `blur(${Math.max(8, Math.round(pic.w * g.strength * 0.004))}px)`, background: "rgba(0,0,0,0.25)" }; return (
); })} {mode === "edit" && regions.length > 0 && ( )}
); }