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,4 @@
export * from "./super-script";
export * from "./sub-script";
export * from "./sub-super-script";
export * from "./pre-sub-super-script";

View File

@ -0,0 +1,2 @@
export * from "./math-pre-sub-super-script-function";
export * from "./math-pre-sub-super-script-function-properties";

View File

@ -0,0 +1,17 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties";
describe("MathPreSubSuperScriptProperties", () => {
describe("#constructor()", () => {
it("should create a MathPreSubSuperScriptProperties with correct root key", () => {
const mathPreSubSuperScriptProperties = new MathPreSubSuperScriptProperties();
const tree = new Formatter().format(mathPreSubSuperScriptProperties);
expect(tree).to.deep.equal({
"m:sPrePr": {},
});
});
});
});

View File

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

View File

@ -0,0 +1,60 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../../math-run";
import { MathPreSubSuperScript } from "./math-pre-sub-super-script-function";
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"),
});
const tree = new Formatter().format(mathPreSubScript);
expect(tree).to.deep.equal({
"m:sPre": [
{
"m:sPrePr": {},
},
{
"m:e": [
{
"m:r": [
{
"m:t": ["e"],
},
],
},
],
},
{
"m:sub": [
{
"m:r": [
{
"m:t": ["2"],
},
],
},
],
},
{
"m:sup": [
{
"m:r": [
{
"m:t": ["5"],
},
],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,23 @@
// http://www.datypic.com/sc/ooxml/e-m_sPre-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../../math-component";
import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-ary";
import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties";
export interface IMathPreSubSuperScriptOptions {
readonly child: MathComponent;
readonly subScript: MathComponent;
readonly superScript: MathComponent;
}
export class MathPreSubSuperScript extends XmlComponent {
constructor(options: IMathPreSubSuperScriptOptions) {
super("m:sPre");
this.root.push(new MathPreSubSuperScriptProperties());
this.root.push(new MathBase(options.child));
this.root.push(new MathSubScriptElement(options.subScript));
this.root.push(new MathSuperScriptElement(options.superScript));
}
}

View File

@ -0,0 +1,2 @@
export * from "./math-sub-script-function";
export * from "./math-sub-script-function-properties";

View File

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

View File

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

View File

@ -0,0 +1,48 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../../math-run";
import { MathSubScript } from "./math-sub-script-function";
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"),
});
const tree = new Formatter().format(mathSubScript);
expect(tree).to.deep.equal({
"m:sSub": [
{
"m:sSubPr": {},
},
{
"m:e": [
{
"m:r": [
{
"m:t": ["e"],
},
],
},
],
},
{
"m:sub": [
{
"m:r": [
{
"m:t": ["2"],
},
],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,21 @@
// http://www.datypic.com/sc/ooxml/e-m_sSub-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../../math-component";
import { MathBase, MathSubScriptElement } from "../../n-ary";
import { MathSubScriptProperties } from "./math-sub-script-function-properties";
export interface IMathSubScriptOptions {
readonly child: MathComponent;
readonly subScript: MathComponent;
}
export class MathSubScript extends XmlComponent {
constructor(options: IMathSubScriptOptions) {
super("m:sSub");
this.root.push(new MathSubScriptProperties());
this.root.push(new MathBase(options.child));
this.root.push(new MathSubScriptElement(options.subScript));
}
}

View File

@ -0,0 +1,2 @@
export * from "./math-sub-super-script-function";
export * from "./math-sub-super-script-function-properties";

View File

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

View File

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

View File

@ -0,0 +1,60 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../../math-run";
import { MathSubSuperScript } from "./math-sub-super-script-function";
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"),
});
const tree = new Formatter().format(mathSubScript);
expect(tree).to.deep.equal({
"m:sSubSup": [
{
"m:sSubSupPr": {},
},
{
"m:e": [
{
"m:r": [
{
"m:t": ["e"],
},
],
},
],
},
{
"m:sub": [
{
"m:r": [
{
"m:t": ["2"],
},
],
},
],
},
{
"m:sup": [
{
"m:r": [
{
"m:t": ["5"],
},
],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,23 @@
// http://www.datypic.com/sc/ooxml/e-m_sSubSup-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../../math-component";
import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-ary";
import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties";
export interface IMathSubSuperScriptOptions {
readonly child: MathComponent;
readonly subScript: MathComponent;
readonly superScript: MathComponent;
}
export class MathSubSuperScript extends XmlComponent {
constructor(options: IMathSubSuperScriptOptions) {
super("m:sSubSup");
this.root.push(new MathSubSuperScriptProperties());
this.root.push(new MathBase(options.child));
this.root.push(new MathSubScriptElement(options.subScript));
this.root.push(new MathSuperScriptElement(options.superScript));
}
}

View File

@ -0,0 +1,2 @@
export * from "./math-super-script-function";
export * from "./math-super-script-function-properties";

View File

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

View File

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

View File

@ -0,0 +1,48 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { MathRun } from "../../math-run";
import { MathSuperScript } from "./math-super-script-function";
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"),
});
const tree = new Formatter().format(mathSuperScript);
expect(tree).to.deep.equal({
"m:sSup": [
{
"m:sSupPr": {},
},
{
"m:e": [
{
"m:r": [
{
"m:t": ["e"],
},
],
},
],
},
{
"m:sup": [
{
"m:r": [
{
"m:t": ["2"],
},
],
},
],
},
],
});
});
});
});

View File

@ -0,0 +1,21 @@
// http://www.datypic.com/sc/ooxml/e-m_sSup-1.html
import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../../math-component";
import { MathBase, MathSuperScriptElement } from "../../n-ary";
import { MathSuperScriptProperties } from "./math-super-script-function-properties";
export interface IMathSuperScriptOptions {
readonly child: MathComponent;
readonly superScript: MathComponent;
}
export class MathSuperScript extends XmlComponent {
constructor(options: IMathSuperScriptOptions) {
super("m:sSup");
this.root.push(new MathSuperScriptProperties());
this.root.push(new MathBase(options.child));
this.root.push(new MathSuperScriptElement(options.superScript));
}
}