import { cn } from "./cn"; import { mergeFixedBoxStyle } from "./box"; import { useContext, type CSSProperties } from "react"; import { FrameContext } from "./FrameContext"; import type { BaseFigureProps, LineProps, MediaCaptionProps, MediaFigureProps, MediaObjectProps, MediaProps, ObjectEntityProps, TextProps, } from "./types"; import { createScopedObjectEntityId } from "../document-model/objectEntityModel"; export function ObjectEntity({ as: Element = "span", box, kind, label, parentId, pageId, blockId, frameKey, chainId, source, metadata, children, style, ...entityProps }: ObjectEntityProps) { const frame = useContext(FrameContext); const resolvedParentId = parentId ?? frame?.objectId; const resolvedPageId = pageId ?? frame?.pageId; const resolvedFrameKey = frameKey ?? frame?.frameKey; const sourceLocator = typeof (entityProps as Record)["data-op-id"] === "string" ? String((entityProps as Record)["data-op-id"]) : null; const localObjectId = label ?? sourceLocator ?? kind; const resolvedObjectLabel = label ?? localObjectId; const resolvedObjectId = createScopedObjectEntityId(kind, resolvedParentId, localObjectId); const mergedStyle = mergeFixedBoxStyle(box, style as CSSProperties | undefined); return ( {children} ); } export function Text(props: TextProps) { return ; } export function Line({ color, className, style, "aria-hidden": ariaHidden = true, ...lineProps }: LineProps) { const lineStyle = { display: "block", background: color, ...(style as CSSProperties | undefined), } as CSSProperties; return ( ); } export function BaseFigure({ caption, className, children, ...figureProps }: BaseFigureProps) { return (
{children}
{caption === undefined ? null :
{caption}
}
); } export function MediaObject({ className, children, ...mediaObjectProps }: MediaObjectProps) { return ( {children} ); } export function Media({ src, alt, ratio, fit = "cover", position = "50% 50%", loading = "eager", className, style, ...mediaProps }: MediaProps) { const mediaStyle = { "--openpress-media-ratio": ratio, "--openpress-media-fit": fit, "--openpress-media-position": position, ...(style as CSSProperties | undefined), } as CSSProperties; return ( {alt} ); } export function MediaCaption({ className, children, ...captionProps }: MediaCaptionProps) { return (
{children}
); } export function MediaFigure({ src, alt, caption, className, imgClassName, loading = "eager", ...figureProps }: MediaFigureProps) { return ( {caption} ); } export const ImageFigure = MediaFigure; function resolveMediaSrc(src: string) { const trimmed = String(src ?? "").trim(); if (!trimmed) return ""; if (/^(?:[a-z][a-z0-9+.-]*:|\/)/i.test(trimmed)) return trimmed; return `/openpress/media/${trimmed.replace(/^\.?\/*/, "")}`; }