More math components

This commit is contained in:
Dolan
2020-10-10 13:41:26 +01:00
parent 32a84a5ad0
commit 700a74fd4c
85 changed files with 1716 additions and 123 deletions

View File

@ -0,0 +1,3 @@
export * from "./math-function";
export * from "./math-function-name";
export * from "./math-function-properties";

View File

@ -0,0 +1,27 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../math-run";
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 tree = new Formatter().format(mathFunctionName);
expect(tree).to.deep.equal({
"m:fName": [
{
"m:r": [
{
"m:t": ["2"],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,11 @@
// http://www.datypic.com/sc/ooxml/e-m_fName-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
export class MathFunctionName extends XmlComponent {
constructor(child: MathComponent) {
super("m:fName");
this.root.push(child);
}
}

View File

@ -0,0 +1,18 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathFunctionProperties } from "./math-function-properties";
describe("MathFunctionProperties", () => {
describe("#constructor()", () => {
it("should create a MathFunctionProperties with correct root key", () => {
const mathFunctionProperties = new MathFunctionProperties();
const tree = new Formatter().format(mathFunctionProperties);
expect(tree).to.deep.equal({
"m:funcPr": {},
});
});
});
});

View File

@ -0,0 +1,8 @@
// http://www.datypic.com/sc/ooxml/e-m_radPr-1.html
import { XmlComponent } from "file/xml-components";
export class MathFunctionProperties extends XmlComponent {
constructor() {
super("m:funcPr");
}
}

View File

@ -0,0 +1,48 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../math-run";
import { MathFunction } from "./math-function";
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"),
});
const tree = new Formatter().format(mathFunction);
expect(tree).to.deep.equal({
"m:func": [
{
"m:funcPr": {},
},
{
"m:fName": [
{
"m:r": [
{
"m:t": ["sin"],
},
],
},
],
},
{
"m:e": [
{
"m:r": [
{
"m:t": ["60"],
},
],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,22 @@
// http://www.datypic.com/sc/ooxml/e-m_func-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
import { MathBase } from "../n-ary";
import { MathFunctionName } from "./math-function-name";
import { MathFunctionProperties } from "./math-function-properties";
export interface IMathFunctionOptions {
readonly child: MathComponent;
readonly name: MathComponent;
}
export class MathFunction extends XmlComponent {
constructor(options: IMathFunctionOptions) {
super("m:func");
this.root.push(new MathFunctionProperties());
this.root.push(new MathFunctionName(options.name));
this.root.push(new MathBase(options.child));
}
}