A world-class math input for the web
at main 30 lines 604 B view raw
1import { CaretNode, h, VNode } from "@caret-js/core"; 2 3export class RadicalNode extends CaretNode { 4 constructor( 5 public radicand: CaretNode, 6 public index: CaretNode | null = null 7 ) { 8 super(); 9 } 10 11 static from( 12 radicand: CaretNode, 13 index: CaretNode | null = null 14 ): RadicalNode { 15 return new RadicalNode(radicand, index); 16 } 17 18 toDebugMathML(): VNode { 19 if (this.index === null) { 20 return h("msqrt", {}, this.radicand.toDebugMathML()); 21 } 22 23 return h( 24 "mroot", 25 {}, 26 this.radicand.toDebugMathML(), 27 this.index.toDebugMathML() 28 ); 29 } 30}