import { html } from "lit"; import { msg } from "@lit/localize"; import type { BuilderComponent } from "../../types/BuilderComponent"; /** * Small default placeholder video (MDN demo, can be replaced later) */ const PLACEHOLDER_VIDEO = "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"; export const VideoComponent: BuilderComponent = { type: "video", label: () => msg("Video"), group: "media", defaultData: { src: PLACEHOLDER_VIDEO, }, render(data) { const src = data?.src || PLACEHOLDER_VIDEO; const alt = data?.alt ?? ""; const width = data?.width ?? "auto"; const height = data?.height ?? "auto"; const objectFit = data?.["object-fit"] ?? "contain"; const opacity = data?.opacity ?? 1; const borderRadius = data?.["border-radius"] ?? "0"; return html`
`; }, bindings: () => [ { key: "src", label: msg("Video URL"), kind: "attr", target: "video", name: "src", placeholder: `https://… ${msg("or")} data:video/…`, }, { key: "alt", label: msg("Alt Text"), kind: "attr", target: "video", name: "alt", placeholder: msg("Describe the video (accessibility)"), }, { key: "width", label: msg("Width"), kind: "style", target: "video", name: "width", placeholder: `${msg("e.g.")} 300px`, }, { key: "height", label: msg("Height"), kind: "style", target: "video", name: "height", placeholder: `${msg("e.g.")} 200px`, }, { key: "object-fit", label: msg("Object Fit"), kind: "style", target: "video", name: "object-fit", placeholder: `${msg("e.g.")} contain, cover, fill`, }, { key: "opacity", label: msg("Opacity"), kind: "style", target: "video", name: "opacity", placeholder: `${msg("e.g.")} 0.5`, }, { key: "border-radius", label: msg("Border Radius"), kind: "style", target: "video", name: "border-radius", placeholder: `${msg("e.g.")} 8px`, }, ], // Upload and reset belong into custom settings settings: ({ setData }) => { const onFileChange = (e: Event) => { const input = e.currentTarget as HTMLInputElement; const file = input.files?.[0]; if (!file) return; if (!file.type.startsWith("video/")) return; const reader = new FileReader(); reader.onload = () => setData({ src: String(reader.result ?? PLACEHOLDER_VIDEO) }); reader.readAsDataURL(file); input.value = ""; }; const resetToPlaceholder = () => setData({ src: PLACEHOLDER_VIDEO }); return html`

${msg("Video")}

${msg("Reset to placeholder")}
`; }, };