import React from "react";
import type * as std from "../../law/std";
import type { HTMLFigData, HTMLComponentProps } from "../common/html";
import { elProps, wrapHTMLComponent } from "../common/html";
import type { DOCXComponentProps, DOCXFigData, DOCXFigDataManager } from "../common/docx/component";
import { wrapDOCXComponent } from "../common/docx/component";
import { w, wp, a, pic, o, v } from "../common/docx/tags";
import { NotImplementedError } from "../../util";
export interface FigRunProps {
el: std.Fig,
}
export const HTMLFigRunCSS = /*css*/`
.fig-iframe {
width: 100%;
height: 80vh;
border: 1px solid gray;
}
.fig-img {
max-width: 100%;
}
`;
export const HTMLFigRun = wrapHTMLComponent("HTMLFigRun", ((props: HTMLComponentProps & FigRunProps) => {
const { el, htmlOptions } = props;
const { getFigData } = htmlOptions;
if (el.children.length > 0) {
throw new NotImplementedError(el.outerXML());
}
if (getFigData) {
const figData = getFigData(el.attr.src);
return figData === null ? (
<>[{el.attr.src}]>
) : (
);
} else {
return (
{el.attr.src}
);
}
}));
export const HTMLFigRunWithFigData = (props: HTMLComponentProps & FigRunProps & { figData: HTMLFigData, fig: std.Fig }) => {
const { el, figData, htmlOptions, fig } = props;
const { renderPDFAsLink } = htmlOptions;
return (
figData.type.startsWith("image/")
? (
)
: ((!renderPDFAsLink) && figData.type.includes("pdf"))
? (
)
: (
{el.attr.src}
)
);
};
export const DOCXFigRun = wrapDOCXComponent("DOCXFigRun", ((props: DOCXComponentProps & FigRunProps) => {
const { el, docxOptions } = props;
const { figDataManager } = docxOptions;
if (el.children.length > 0) {
throw new NotImplementedError(el.outerXML());
}
if (figDataManager) {
const figData = figDataManager.getFigData(el.attr.src);
return figData === null ? (
{el.attr.src}
) : (
);
} else {
return (
{el.attr.src}
);
}
}));
export const DOCXFigRunWithFigData = (props: DOCXComponentProps & FigRunProps & { figData: DOCXFigData, fig: std.Fig, figDataManager: DOCXFigDataManager }) => {
const { figData, figDataManager } = props;
return (<>
{("image" in figData) && (
)}
{("file" in figData) && (
)}
{("pages" in figData) && figData.pages.map((page, key) => (
))}
>);
};