A world-class math input for the web
at main 28 lines 787 B view raw
1import { CaretNode, h, VNode } from "@caret-js/core"; 2import { MathExpressionTag } from "../tags/mathExpression"; 3import { SubscriptNode } from "./subscript"; 4 5export class ExponentNode extends CaretNode { 6 constructor(public base: CaretNode, public power: CaretNode) { 7 super(); 8 this.addTag(new MathExpressionTag()); 9 } 10 11 static from(base: CaretNode, power: CaretNode): ExponentNode { 12 return new ExponentNode(base, power); 13 } 14 15 toDebugMathML(): VNode { 16 if (this.base instanceof SubscriptNode) { 17 return h( 18 "msubsup", 19 {}, 20 this.base.child.toDebugMathML(), 21 this.base.subscript.toDebugMathML(), 22 this.power.toDebugMathML() 23 ); 24 } 25 26 return h("msup", {}, this.base.toDebugMathML(), this.power.toDebugMathML()); 27 } 28}