More math components
This commit is contained in:
3
src/file/paragraph/math/function/index.ts
Normal file
3
src/file/paragraph/math/function/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from "./math-function";
|
||||
export * from "./math-function-name";
|
||||
export * from "./math-function-properties";
|
27
src/file/paragraph/math/function/math-function-name.spec.ts
Normal file
27
src/file/paragraph/math/function/math-function-name.spec.ts
Normal 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"],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
11
src/file/paragraph/math/function/math-function-name.ts
Normal file
11
src/file/paragraph/math/function/math-function-name.ts
Normal 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);
|
||||
}
|
||||
}
|
@ -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": {},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -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");
|
||||
}
|
||||
}
|
48
src/file/paragraph/math/function/math-function.spec.ts
Normal file
48
src/file/paragraph/math/function/math-function.spec.ts
Normal 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"],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
22
src/file/paragraph/math/function/math-function.ts
Normal file
22
src/file/paragraph/math/function/math-function.ts
Normal 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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user