import { CaretNode, h, t, VNode } from "@caret-js/core"; import { MathExpressionTag } from "../tags/mathExpression"; import { MultiplicationStyleTag } from "../parselets/adjacentMultiplication"; export class MultiplyNode extends CaretNode { constructor(public factors: CaretNode[]) { super(); this.addTag(new MathExpressionTag()); } static from(factors: CaretNode[]): MultiplyNode { return new MultiplyNode( factors.flatMap((node) => node instanceof MultiplyNode ? node.factors : [node] ) ).mergeTagsFromNodes( factors.filter((node) => node instanceof MultiplyNode) ); } toDebugMathML(): VNode { const separator = () => { const tag = this.getTag(MultiplicationStyleTag); if (tag?.style === "dot") { return h("mo", {}, t("·")); } else if (tag?.style === "cross") { return h("mo", {}, t("×")); } else if (tag?.style === "implicit") { return null; } return null; }; return h( "mrow", {}, ...this.factors.flatMap((factor, index) => [ factor.toDebugMathML(), index < this.factors.length - 1 ? separator() : null, ]) ); } }