import React, { useMemo } from "react"; import { VideoEmbedProps } from "./types"; import { cx } from "@shared/utils"; const extractVimeoIdandHash = (href: string) => { // Strip query parameters and fragments const cleanHref = href.split(/[?#]/)[0].replace(/\/+$/, ""); const match = cleanHref.match(/vimeo\.com\/(?:.*\/)?(\d{6,})/) || cleanHref.match(/player\.vimeo\.com\/video\/(\d{6,})/); const parts = cleanHref.split("/"); const hash = parts[parts.length - 1]; if (!match?.[1]) return ""; if (match[1] === hash) return match[1]; return `${match[1]}/${hash}`; }; export const VimeoEmbed: React.FC = props => { const { link, containerClassName, autoplay = false, debug = false } = props; const { href, embedId } = useMemo(() => { if (!link) return { href: "", embedId: "" }; const resolved = link.toString(); const id = extractVimeoIdandHash(resolved); return { href: resolved, embedId: id }; }, [link]); if (debug) { // eslint-disable-next-line no-console console.log("[VimeoEmbed] href:", href, "id:", embedId); } if (!embedId) { return null; } const params = new URLSearchParams({ autoplay: autoplay ? "1" : "0", muted: "0", playsinline: "1", dnt: "1", title: "0", byline: "0", portrait: "0", autopause: "1", }); const o_src = `https://player.vimeo.com/video/${embedId}?${params.toString()}`; const src = normalizeVimeoPlayerSrc(o_src); return (