import type { Bookmark } from "@/timeline"; import { EMPTY_PREVIEW_OVERLAY_SOURCE_RESULT, type PreviewOverlayDefinition, type PreviewOverlaySourceResult, } from "@/preview/overlays"; import { getBookmarksActiveAtTime } from "./utils"; import type { MediaTime } from "@/wasm"; export const bookmarkNotesPreviewOverlay: PreviewOverlayDefinition = { id: "bookmark-notes", label: "Show bookmark notes", defaultVisible: true, }; function BookmarkNotesOverlay({ bookmarks, }: { bookmarks: Array<{ time: MediaTime; note: string; color?: string }>; }) { return (
{bookmarks.map((bookmark) => (
{bookmark.note}
))}
); } export function getBookmarkPreviewOverlaySource({ bookmarks, time, isVisible, }: { bookmarks: Bookmark[]; time: MediaTime; isVisible: boolean; }): PreviewOverlaySourceResult { const bookmarksWithNotes = getBookmarksActiveAtTime({ bookmarks, time, }).flatMap((bookmark) => { if (bookmark.note == null || bookmark.note.trim() === "") { return []; } return [ { time: bookmark.time, note: bookmark.note, color: bookmark.color, }, ]; }); if (!isVisible || bookmarksWithNotes.length === 0) { return { ...EMPTY_PREVIEW_OVERLAY_SOURCE_RESULT, definitions: [bookmarkNotesPreviewOverlay], }; } return { definitions: [bookmarkNotesPreviewOverlay], instances: [ { id: bookmarkNotesPreviewOverlay.id, mount: { kind: "hud", anchor: "top-left", order: 0 }, plane: "over-interaction", pointerEvents: "none", render: () => , }, ], }; }