A world-class math input for the web
at main 28 lines 753 B view raw
1import { CaretNode, h, t, VNode } from "@caret-js/core"; 2import { MathExpressionTag } from "../tags/mathExpression"; 3 4export class AddNode extends CaretNode { 5 constructor(public addends: CaretNode[]) { 6 super(); 7 this.addTag(new MathExpressionTag()); 8 } 9 10 static from(addends: CaretNode[]): AddNode { 11 return new AddNode( 12 addends.flatMap((node) => 13 node instanceof AddNode ? node.addends : [node] 14 ) 15 ).mergeTagsFromNodes(addends.filter((node) => node instanceof AddNode)); 16 } 17 18 toDebugMathML(): VNode { 19 return h( 20 "mrow", 21 {}, 22 ...this.addends.flatMap((addend, index) => [ 23 addend.toDebugMathML(), 24 index < this.addends.length - 1 ? h("mo", {}, t("+")) : null, 25 ]) 26 ); 27 } 28}