import React from "react";
import type { SentenceChildEL } from "../../node/cst/inline";
import * as std from "../../law/std";
import { assertNever } from "../../util";
import type { HTMLComponentProps } from "../common/html";
import { elProps, wrapHTMLComponent } from "../common/html";
import type { DOCXComponentProps } from "../common/docx/component";
import { wrapDOCXComponent } from "../common/docx/component";
import { w } from "../common/docx/tags";
import { DOCXArithFormulaRun, HTMLArithFormulaRun } from "./arithFormulaRun";
import { DOCXQuoteStructRun, HTMLQuoteStructRun } from "./quoteStructRun";
import { HTMLControlRun } from "./controlRun";
import { withKey } from "../common";
interface SentenceChildrenRunProps {
els: (string | SentenceChildEL)[];
}
export const HTMLSentenceChildrenRunCSS = /*css*/`
`;
export const HTMLSentenceChildrenRun = wrapHTMLComponent("HTMLSentenceChildrenRun", ((props: HTMLComponentProps & SentenceChildrenRunProps) => {
const { els, htmlOptions } = props;
const { renderControlEL } = htmlOptions;
const runs: (React.JSX.Element | string)[] = [];
for (const el of els) {
if (typeof el === "string") {
runs.push(el);
} else if (el.isControl) {
if (renderControlEL) {
runs.push();
} else {
runs.push(el.text());
}
} else {
if (el.tag === "Ruby") {
const rb = el.children
.map(c =>
(typeof c === "string")
? c
: !std.isRt(c)
? c.text()
: "",
).join("");
const rt = (el.children
.filter(c => !(typeof c === "string") && std.isRt(c)) as std.Rt[])
.map(c => c.text())
.join("");
runs.push({rb});
} else if (el.tag === "Sub") {
runs.push({el.text()});
} else if (el.tag === "Sup") {
runs.push({el.text()});
} else if (el.tag === "QuoteStruct") {
runs.push();
} else if (el.tag === "ArithFormula") {
runs.push();
} else if (el.tag === "Line") {
return ((
));
}
else { assertNever(el); }
}
}
return <>
{withKey(runs)}
>;
}));
export const DOCXSentenceChildrenRun = wrapDOCXComponent("DOCXSentenceChildrenRun", ((props: DOCXComponentProps & SentenceChildrenRunProps & {emphasis?: boolean}) => {
const { els, emphasis, docxOptions } = props;
const runs: React.JSX.Element[] = [];
for (const el of els) {
if (typeof el === "string" || el instanceof String) {
runs.push(
{emphasis ? : null}
{el}
);
} else if (el.isControl) {
runs.push(
{emphasis ? : null}
{el.text()}
);
} else {
if (el.tag === "Ruby") {
const rb = el.children
.map(c =>
(typeof c === "string")
? c
: !std.isRt(c)
? c.text()
: "",
).join("");
const rt = (el.children
.filter(c => !(typeof c === "string") && std.isRt(c)) as std.Rt[])
.map(c => c.text())
.join("");
runs.push(
{emphasis ? : null}
{rt}
{rb}
);
} else if (el.tag === "Sub") {
runs.push(
{el.text()}
);
} else if (el.tag === "Sup") {
runs.push(
{el.text()}
);
} else if (el.tag === "QuoteStruct") {
runs.push();
} else if (el.tag === "ArithFormula") {
runs.push();
} else if (el.tag === "Line") {
runs.push();
}
else { assertNever(el); }
}
}
return <>
{withKey(runs)}
>;
}));