Turn math component into array
This commit is contained in:
193
demo/55-math.ts
193
demo/55-math.ts
@ -33,8 +33,8 @@ doc.addSection({
|
||||
children: [
|
||||
new MathRun("2+2"),
|
||||
new MathFraction({
|
||||
numerator: new MathRun("hi"),
|
||||
denominator: new MathRun("2"),
|
||||
numerator: [new MathRun("hi")],
|
||||
denominator: [new MathRun("2")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -44,26 +44,43 @@ doc.addSection({
|
||||
}),
|
||||
],
|
||||
}),
|
||||
// new Paragraph({
|
||||
// children: [
|
||||
// new MathFraction({
|
||||
// numerator: [
|
||||
// new MathRun("1"),
|
||||
// new MathRadical({
|
||||
// children: [new MathRun("2")],
|
||||
// }),
|
||||
// ],
|
||||
// denominator: [new MathRun("2")],
|
||||
// }),
|
||||
// ],
|
||||
// }),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new Math({
|
||||
children: [
|
||||
new MathSum({
|
||||
child: new MathRun("test"),
|
||||
children: [new MathRun("test")],
|
||||
}),
|
||||
new MathSum({
|
||||
child: new MathSuperScript({
|
||||
child: new MathRun("e"),
|
||||
superScript: new MathRun("2"),
|
||||
}),
|
||||
subScript: new MathRun("i"),
|
||||
children: [
|
||||
new MathSuperScript({
|
||||
children: [new MathRun("e")],
|
||||
superScript: [new MathRun("2")],
|
||||
}),
|
||||
],
|
||||
subScript: [new MathRun("i")],
|
||||
}),
|
||||
new MathSum({
|
||||
child: new MathRadical({
|
||||
child: new MathRun("i"),
|
||||
}),
|
||||
subScript: new MathRun("i"),
|
||||
superScript: new MathRun("10"),
|
||||
children: [
|
||||
new MathRadical({
|
||||
children: [new MathRun("i")],
|
||||
}),
|
||||
],
|
||||
subScript: [new MathRun("i")],
|
||||
superScript: [new MathRun("10")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -74,8 +91,8 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathSuperScript({
|
||||
child: new MathRun("test"),
|
||||
superScript: new MathRun("hello"),
|
||||
children: [new MathRun("test")],
|
||||
superScript: [new MathRun("hello")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -86,8 +103,8 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathSubScript({
|
||||
child: new MathRun("test"),
|
||||
subScript: new MathRun("hello"),
|
||||
children: [new MathRun("test")],
|
||||
subScript: [new MathRun("hello")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -98,11 +115,13 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathSubScript({
|
||||
child: new MathRun("x"),
|
||||
subScript: new MathSuperScript({
|
||||
child: new MathRun("y"),
|
||||
superScript: new MathRun("2"),
|
||||
}),
|
||||
children: [new MathRun("x")],
|
||||
subScript: [
|
||||
new MathSuperScript({
|
||||
children: [new MathRun("y")],
|
||||
superScript: [new MathRun("2")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -113,9 +132,9 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathSubSuperScript({
|
||||
child: new MathRun("test"),
|
||||
superScript: new MathRun("hello"),
|
||||
subScript: new MathRun("world"),
|
||||
children: [new MathRun("test")],
|
||||
superScript: [new MathRun("hello")],
|
||||
subScript: [new MathRun("world")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -126,9 +145,9 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathPreSubSuperScript({
|
||||
child: new MathRun("test"),
|
||||
superScript: new MathRun("hello"),
|
||||
subScript: new MathRun("world"),
|
||||
children: [new MathRun("test")],
|
||||
superScript: [new MathRun("hello")],
|
||||
subScript: [new MathRun("world")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -139,29 +158,35 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathSubScript({
|
||||
child: new MathFraction({
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
subScript: new MathRun("4"),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new Math({
|
||||
children: [
|
||||
new MathSubScript({
|
||||
child: new MathRadical({
|
||||
child: new MathFraction({
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
children: [
|
||||
new MathFraction({
|
||||
numerator: [new MathRun("1")],
|
||||
denominator: [new MathRun("2")],
|
||||
}),
|
||||
degree: new MathRun("4"),
|
||||
}),
|
||||
subScript: new MathRun("x"),
|
||||
],
|
||||
subScript: [new MathRun("4")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
children: [
|
||||
new Math({
|
||||
children: [
|
||||
new MathSubScript({
|
||||
children: [
|
||||
new MathRadical({
|
||||
children: [
|
||||
new MathFraction({
|
||||
numerator: [new MathRun("1")],
|
||||
denominator: [new MathRun("2")],
|
||||
}),
|
||||
],
|
||||
degree: [new MathRun("4")],
|
||||
}),
|
||||
],
|
||||
subScript: [new MathRun("x")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -172,7 +197,7 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathRadical({
|
||||
child: new MathRun("4"),
|
||||
children: [new MathRun("4")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -183,16 +208,18 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathFunction({
|
||||
name: new MathSuperScript({
|
||||
child: new MathRun("cos"),
|
||||
superScript: new MathRun("-1"),
|
||||
}),
|
||||
child: new MathRun("100"),
|
||||
name: [
|
||||
new MathSuperScript({
|
||||
children: [new MathRun("cos")],
|
||||
superScript: [new MathRun("-1")],
|
||||
}),
|
||||
],
|
||||
children: [new MathRun("100")],
|
||||
}),
|
||||
new MathRun("×"),
|
||||
new MathFunction({
|
||||
name: new MathRun("sin"),
|
||||
child: new MathRun("360"),
|
||||
name: [new MathRun("sin")],
|
||||
children: [new MathRun("360")],
|
||||
}),
|
||||
new MathRun("= x"),
|
||||
],
|
||||
@ -204,28 +231,36 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathRoundBrackets({
|
||||
child: new MathFraction({
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
children: [
|
||||
new MathFraction({
|
||||
numerator: [new MathRun("1")],
|
||||
denominator: [new MathRun("2")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new MathSquareBrackets({
|
||||
child: new MathFraction({
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
children: [
|
||||
new MathFraction({
|
||||
numerator: [new MathRun("1")],
|
||||
denominator: [new MathRun("2")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new MathCurlyBrackets({
|
||||
child: new MathFraction({
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
children: [
|
||||
new MathFraction({
|
||||
numerator: [new MathRun("1")],
|
||||
denominator: [new MathRun("2")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new MathAngledBrackets({
|
||||
child: new MathFraction({
|
||||
numerator: new MathRun("1"),
|
||||
denominator: new MathRun("2"),
|
||||
}),
|
||||
children: [
|
||||
new MathFraction({
|
||||
numerator: [new MathRun("1")],
|
||||
denominator: [new MathRun("2")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -236,10 +271,12 @@ doc.addSection({
|
||||
new Math({
|
||||
children: [
|
||||
new MathFraction({
|
||||
numerator: new MathRadical({
|
||||
child: new MathRun("4"),
|
||||
}),
|
||||
denominator: new MathRun("2a"),
|
||||
numerator: [
|
||||
new MathRadical({
|
||||
children: [new MathRun("4")],
|
||||
}),
|
||||
],
|
||||
denominator: [new MathRun("2a")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
@ -9,7 +9,7 @@ describe("MathAngledBrackets", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathAngledBrackets with correct root key", () => {
|
||||
const mathAngledBrackets = new MathAngledBrackets({
|
||||
child: new MathRun("60"),
|
||||
children: [new MathRun("60")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathAngledBrackets);
|
||||
|
@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathAngledBrackets extends XmlComponent {
|
||||
constructor(options: { readonly child: MathComponent }) {
|
||||
constructor(options: { readonly children: MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
@ -15,6 +15,6 @@ export class MathAngledBrackets extends XmlComponent {
|
||||
endingCharacter: "〉",
|
||||
}),
|
||||
);
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ describe("MathCurlyBrackets", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathCurlyBrackets with correct root key", () => {
|
||||
const mathCurlyBrackets = new MathCurlyBrackets({
|
||||
child: new MathRun("60"),
|
||||
children: [new MathRun("60")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathCurlyBrackets);
|
||||
|
@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathCurlyBrackets extends XmlComponent {
|
||||
constructor(options: { readonly child: MathComponent }) {
|
||||
constructor(options: { readonly children: MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
@ -15,6 +15,6 @@ export class MathCurlyBrackets extends XmlComponent {
|
||||
endingCharacter: "}",
|
||||
}),
|
||||
);
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ describe("MathRoundBrackets", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathRoundBrackets with correct root key", () => {
|
||||
const mathRoundBrackets = new MathRoundBrackets({
|
||||
child: new MathRun("60"),
|
||||
children: [new MathRun("60")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathRoundBrackets);
|
||||
|
@ -6,10 +6,10 @@ import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathRoundBrackets extends XmlComponent {
|
||||
constructor(options: { readonly child: MathComponent }) {
|
||||
constructor(options: { readonly children: MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(new MathBracketProperties());
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ describe("MathSquareBrackets", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSquareBrackets with correct root key", () => {
|
||||
const mathSquareBrackets = new MathSquareBrackets({
|
||||
child: new MathRun("60"),
|
||||
children: [new MathRun("60")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathSquareBrackets);
|
||||
|
@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathSquareBrackets extends XmlComponent {
|
||||
constructor(options: { readonly child: MathComponent }) {
|
||||
constructor(options: { readonly children: MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
@ -15,6 +15,6 @@ export class MathSquareBrackets extends XmlComponent {
|
||||
endingCharacter: "]",
|
||||
}),
|
||||
);
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import { MathDenominator } from "./math-denominator";
|
||||
describe("MathDenominator", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathDenominator with correct root key", () => {
|
||||
const mathDenominator = new MathDenominator(new MathRun("2+2"));
|
||||
const mathDenominator = new MathDenominator([new MathRun("2+2")]);
|
||||
const tree = new Formatter().format(mathDenominator);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:den": [
|
||||
|
@ -3,9 +3,11 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathDenominator extends XmlComponent {
|
||||
constructor(child: MathComponent) {
|
||||
constructor(children: MathComponent[]) {
|
||||
super("m:den");
|
||||
|
||||
this.root.push(child);
|
||||
for (const child of children) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ describe("MathFraction", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathFraction with correct root key", () => {
|
||||
const mathFraction = new MathFraction({
|
||||
numerator: new MathRun("2"),
|
||||
denominator: new MathRun("2"),
|
||||
numerator: [new MathRun("2")],
|
||||
denominator: [new MathRun("2")],
|
||||
});
|
||||
const tree = new Formatter().format(mathFraction);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -5,8 +5,8 @@ import { MathDenominator } from "./math-denominator";
|
||||
import { MathNumerator } from "./math-numerator";
|
||||
|
||||
export interface IMathFractionOptions {
|
||||
readonly numerator: MathComponent;
|
||||
readonly denominator: MathComponent;
|
||||
readonly numerator: MathComponent[];
|
||||
readonly denominator: MathComponent[];
|
||||
}
|
||||
|
||||
export class MathFraction extends XmlComponent {
|
||||
|
@ -8,7 +8,7 @@ import { MathNumerator } from "./math-numerator";
|
||||
describe("MathNumerator", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathNumerator with correct root key", () => {
|
||||
const mathNumerator = new MathNumerator(new MathRun("2+2"));
|
||||
const mathNumerator = new MathNumerator([new MathRun("2+2")]);
|
||||
const tree = new Formatter().format(mathNumerator);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:num": [
|
||||
|
@ -3,9 +3,11 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathNumerator extends XmlComponent {
|
||||
constructor(child: MathComponent) {
|
||||
constructor(children: MathComponent[]) {
|
||||
super("m:num");
|
||||
|
||||
this.root.push(child);
|
||||
for (const child of children) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import { MathFunctionName } from "./math-function-name";
|
||||
describe("MathFunctionName", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathFunctionName with correct root key", () => {
|
||||
const mathFunctionName = new MathFunctionName(new MathRun("2"));
|
||||
const mathFunctionName = new MathFunctionName([new MathRun("2")]);
|
||||
|
||||
const tree = new Formatter().format(mathFunctionName);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -3,9 +3,11 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathFunctionName extends XmlComponent {
|
||||
constructor(child: MathComponent) {
|
||||
constructor(children: MathComponent[]) {
|
||||
super("m:fName");
|
||||
|
||||
this.root.push(child);
|
||||
for (const child of children) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ describe("MathFunction", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathFunction with correct root key", () => {
|
||||
const mathFunction = new MathFunction({
|
||||
name: new MathRun("sin"),
|
||||
child: new MathRun("60"),
|
||||
name: [new MathRun("sin")],
|
||||
children: [new MathRun("60")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathFunction);
|
||||
|
@ -7,8 +7,8 @@ import { MathFunctionName } from "./math-function-name";
|
||||
import { MathFunctionProperties } from "./math-function-properties";
|
||||
|
||||
export interface IMathFunctionOptions {
|
||||
readonly child: MathComponent;
|
||||
readonly name: MathComponent;
|
||||
readonly children: MathComponent[];
|
||||
readonly name: MathComponent[];
|
||||
}
|
||||
|
||||
export class MathFunction extends XmlComponent {
|
||||
@ -17,6 +17,6 @@ export class MathFunction extends XmlComponent {
|
||||
|
||||
this.root.push(new MathFunctionProperties());
|
||||
this.root.push(new MathFunctionName(options.name));
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import { MathBase } from "./math-base";
|
||||
describe("MathBase", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathBase with correct root key", () => {
|
||||
const mathBase = new MathBase(new MathRun("2+2"));
|
||||
const mathBase = new MathBase([new MathRun("2+2")]);
|
||||
|
||||
const tree = new Formatter().format(mathBase);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -4,9 +4,11 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathBase extends XmlComponent {
|
||||
constructor(run: MathComponent) {
|
||||
constructor(children: MathComponent[]) {
|
||||
super("m:e");
|
||||
|
||||
this.root.push(run);
|
||||
for (const child of children) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import { MathSubScriptElement } from "./math-sub-script";
|
||||
describe("MathSubScriptElement", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSubScriptElement with correct root key", () => {
|
||||
const mathSubScriptElement = new MathSubScriptElement(new MathRun("2+2"));
|
||||
const mathSubScriptElement = new MathSubScriptElement([new MathRun("2+2")]);
|
||||
|
||||
const tree = new Formatter().format(mathSubScriptElement);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -4,9 +4,11 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathSubScriptElement extends XmlComponent {
|
||||
constructor(child: MathComponent) {
|
||||
constructor(children: MathComponent[]) {
|
||||
super("m:sub");
|
||||
|
||||
this.root.push(child);
|
||||
for (const child of children) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ describe("MathSum", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSum with correct root key", () => {
|
||||
const mathSum = new MathSum({
|
||||
child: new MathRun("1"),
|
||||
subScript: new MathRun("2"),
|
||||
superScript: new MathRun("3"),
|
||||
children: [new MathRun("1")],
|
||||
subScript: [new MathRun("2")],
|
||||
superScript: [new MathRun("3")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathSum);
|
||||
|
@ -8,9 +8,9 @@ import { MathSubScriptElement } from "./math-sub-script";
|
||||
import { MathSuperScriptElement } from "./math-super-script";
|
||||
|
||||
export interface IMathSumOptions {
|
||||
readonly child: MathComponent;
|
||||
readonly subScript?: MathComponent;
|
||||
readonly superScript?: MathComponent;
|
||||
readonly children: MathComponent[];
|
||||
readonly subScript?: MathComponent[];
|
||||
readonly superScript?: MathComponent[];
|
||||
}
|
||||
|
||||
export class MathSum extends XmlComponent {
|
||||
@ -27,6 +27,6 @@ export class MathSum extends XmlComponent {
|
||||
this.root.push(new MathSuperScriptElement(options.superScript));
|
||||
}
|
||||
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import { MathSuperScriptElement } from "./math-super-script";
|
||||
describe("MathSuperScriptElement", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSuperScriptElement with correct root key", () => {
|
||||
const mathSuperScriptElement = new MathSuperScriptElement(new MathRun("2+2"));
|
||||
const mathSuperScriptElement = new MathSuperScriptElement([new MathRun("2+2")]);
|
||||
|
||||
const tree = new Formatter().format(mathSuperScriptElement);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -4,9 +4,11 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathSuperScriptElement extends XmlComponent {
|
||||
constructor(child: MathComponent) {
|
||||
constructor(children: MathComponent[]) {
|
||||
super("m:sup");
|
||||
|
||||
this.root.push(child);
|
||||
for (const child of children) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ describe("MathDegree", () => {
|
||||
});
|
||||
|
||||
it("should create a MathDegree with correct root key with child", () => {
|
||||
const mathDegree = new MathDegree(new MathRun("2"));
|
||||
const mathDegree = new MathDegree([new MathRun("2")]);
|
||||
|
||||
const tree = new Formatter().format(mathDegree);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -3,11 +3,13 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathDegree extends XmlComponent {
|
||||
constructor(child?: MathComponent) {
|
||||
constructor(children?: MathComponent[]) {
|
||||
super("m:deg");
|
||||
|
||||
if (!!child) {
|
||||
this.root.push(child);
|
||||
if (!!children) {
|
||||
for (const child of children) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ describe("MathRadical", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathRadical with correct root key", () => {
|
||||
const mathRadical = new MathRadical({
|
||||
child: new MathRun("e"),
|
||||
degree: new MathRun("2"),
|
||||
children: [new MathRun("e")],
|
||||
degree: [new MathRun("2")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathRadical);
|
||||
|
@ -7,8 +7,8 @@ import { MathDegree } from "./math-degree";
|
||||
import { MathRadicalProperties } from "./math-radical-properties";
|
||||
|
||||
export interface IMathRadicalOptions {
|
||||
readonly child: MathComponent;
|
||||
readonly degree?: MathComponent;
|
||||
readonly children: MathComponent[];
|
||||
readonly degree?: MathComponent[];
|
||||
}
|
||||
|
||||
export class MathRadical extends XmlComponent {
|
||||
@ -17,6 +17,6 @@ export class MathRadical extends XmlComponent {
|
||||
|
||||
this.root.push(new MathRadicalProperties(!!options.degree));
|
||||
this.root.push(new MathDegree(options.degree));
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ describe("MathPreSubScript", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathPreSubScript with correct root key", () => {
|
||||
const mathPreSubScript = new MathPreSubSuperScript({
|
||||
child: new MathRun("e"),
|
||||
subScript: new MathRun("2"),
|
||||
superScript: new MathRun("5"),
|
||||
children: [new MathRun("e")],
|
||||
subScript: [new MathRun("2")],
|
||||
superScript: [new MathRun("5")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathPreSubScript);
|
||||
|
@ -6,9 +6,9 @@ import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-
|
||||
import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties";
|
||||
|
||||
export interface IMathPreSubSuperScriptOptions {
|
||||
readonly child: MathComponent;
|
||||
readonly subScript: MathComponent;
|
||||
readonly superScript: MathComponent;
|
||||
readonly children: MathComponent[];
|
||||
readonly subScript: MathComponent[];
|
||||
readonly superScript: MathComponent[];
|
||||
}
|
||||
|
||||
export class MathPreSubSuperScript extends XmlComponent {
|
||||
@ -16,7 +16,7 @@ export class MathPreSubSuperScript extends XmlComponent {
|
||||
super("m:sPre");
|
||||
|
||||
this.root.push(new MathPreSubSuperScriptProperties());
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(new MathSubScriptElement(options.subScript));
|
||||
this.root.push(new MathSuperScriptElement(options.superScript));
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ describe("MathSubScript", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSubScript with correct root key", () => {
|
||||
const mathSubScript = new MathSubScript({
|
||||
child: new MathRun("e"),
|
||||
subScript: new MathRun("2"),
|
||||
children: [new MathRun("e")],
|
||||
subScript: [new MathRun("2")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathSubScript);
|
||||
|
@ -6,8 +6,8 @@ import { MathBase, MathSubScriptElement } from "../../n-ary";
|
||||
import { MathSubScriptProperties } from "./math-sub-script-function-properties";
|
||||
|
||||
export interface IMathSubScriptOptions {
|
||||
readonly child: MathComponent;
|
||||
readonly subScript: MathComponent;
|
||||
readonly children: MathComponent[];
|
||||
readonly subScript: MathComponent[];
|
||||
}
|
||||
|
||||
export class MathSubScript extends XmlComponent {
|
||||
@ -15,7 +15,7 @@ export class MathSubScript extends XmlComponent {
|
||||
super("m:sSub");
|
||||
|
||||
this.root.push(new MathSubScriptProperties());
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(new MathSubScriptElement(options.subScript));
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ describe("MathSubScript", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSubScript with correct root key", () => {
|
||||
const mathSubScript = new MathSubSuperScript({
|
||||
child: new MathRun("e"),
|
||||
subScript: new MathRun("2"),
|
||||
superScript: new MathRun("5"),
|
||||
children: [new MathRun("e")],
|
||||
subScript: [new MathRun("2")],
|
||||
superScript: [new MathRun("5")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathSubScript);
|
||||
|
@ -6,9 +6,9 @@ import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-
|
||||
import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties";
|
||||
|
||||
export interface IMathSubSuperScriptOptions {
|
||||
readonly child: MathComponent;
|
||||
readonly subScript: MathComponent;
|
||||
readonly superScript: MathComponent;
|
||||
readonly children: MathComponent[];
|
||||
readonly subScript: MathComponent[];
|
||||
readonly superScript: MathComponent[];
|
||||
}
|
||||
|
||||
export class MathSubSuperScript extends XmlComponent {
|
||||
@ -16,7 +16,7 @@ export class MathSubSuperScript extends XmlComponent {
|
||||
super("m:sSubSup");
|
||||
|
||||
this.root.push(new MathSubSuperScriptProperties());
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(new MathSubScriptElement(options.subScript));
|
||||
this.root.push(new MathSuperScriptElement(options.superScript));
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ describe("MathSuperScript", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSuperScript with correct root key", () => {
|
||||
const mathSuperScript = new MathSuperScript({
|
||||
child: new MathRun("e"),
|
||||
superScript: new MathRun("2"),
|
||||
children: [new MathRun("e")],
|
||||
superScript: [new MathRun("2")],
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathSuperScript);
|
||||
|
@ -6,8 +6,8 @@ import { MathBase, MathSuperScriptElement } from "../../n-ary";
|
||||
import { MathSuperScriptProperties } from "./math-super-script-function-properties";
|
||||
|
||||
export interface IMathSuperScriptOptions {
|
||||
readonly child: MathComponent;
|
||||
readonly superScript: MathComponent;
|
||||
readonly children: MathComponent[];
|
||||
readonly superScript: MathComponent[];
|
||||
}
|
||||
|
||||
export class MathSuperScript extends XmlComponent {
|
||||
@ -15,7 +15,7 @@ export class MathSuperScript extends XmlComponent {
|
||||
super("m:sSup");
|
||||
|
||||
this.root.push(new MathSuperScriptProperties());
|
||||
this.root.push(new MathBase(options.child));
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(new MathSuperScriptElement(options.superScript));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user