More math components
This commit is contained in:
3
src/file/paragraph/math/radical/index.ts
Normal file
3
src/file/paragraph/math/radical/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from "./math-degree";
|
||||
export * from "./math-radical";
|
||||
export * from "./math-radical-properties";
|
22
src/file/paragraph/math/radical/math-degree-hide.spec.ts
Normal file
22
src/file/paragraph/math/radical/math-degree-hide.spec.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { MathDegreeHide } from "./math-degree-hide";
|
||||
|
||||
describe("MathDegreeHide", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathDegreeHide with correct root key", () => {
|
||||
const mathDegreeHide = new MathDegreeHide();
|
||||
|
||||
const tree = new Formatter().format(mathDegreeHide);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:degHide": {
|
||||
_attr: {
|
||||
"m:val": 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
14
src/file/paragraph/math/radical/math-degree-hide.ts
Normal file
14
src/file/paragraph/math/radical/math-degree-hide.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_degHide-1.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class MathDegreeHideAttributes extends XmlAttributeComponent<{ readonly hide: number }> {
|
||||
protected readonly xmlKeys = { hide: "m:val" };
|
||||
}
|
||||
|
||||
export class MathDegreeHide extends XmlComponent {
|
||||
constructor() {
|
||||
super("m:degHide");
|
||||
|
||||
this.root.push(new MathDegreeHideAttributes({ hide: 1 }));
|
||||
}
|
||||
}
|
36
src/file/paragraph/math/radical/math-degree.spec.ts
Normal file
36
src/file/paragraph/math/radical/math-degree.spec.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { MathRun } from "../math-run";
|
||||
import { MathDegree } from "./math-degree";
|
||||
|
||||
describe("MathDegree", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathDegree with correct root key", () => {
|
||||
const mathDegree = new MathDegree();
|
||||
|
||||
const tree = new Formatter().format(mathDegree);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:deg": {},
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a MathDegree with correct root key with child", () => {
|
||||
const mathDegree = new MathDegree(new MathRun("2"));
|
||||
|
||||
const tree = new Formatter().format(mathDegree);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:deg": [
|
||||
{
|
||||
"m:r": [
|
||||
{
|
||||
"m:t": ["2"],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
13
src/file/paragraph/math/radical/math-degree.ts
Normal file
13
src/file/paragraph/math/radical/math-degree.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_deg-1.html
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathDegree extends XmlComponent {
|
||||
constructor(child?: MathComponent) {
|
||||
super("m:deg");
|
||||
|
||||
if (!!child) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { MathRadicalProperties } from "./math-radical-properties";
|
||||
|
||||
describe("MathRadicalProperties", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathRadicalProperties with correct root key", () => {
|
||||
const mathRadicalProperties = new MathRadicalProperties(true);
|
||||
|
||||
const tree = new Formatter().format(mathRadicalProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:radPr": {},
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a MathRadicalProperties with correct root key with degree hide", () => {
|
||||
const mathRadicalProperties = new MathRadicalProperties(false);
|
||||
|
||||
const tree = new Formatter().format(mathRadicalProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:radPr": [
|
||||
{
|
||||
"m:degHide": {
|
||||
_attr: {
|
||||
"m:val": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
13
src/file/paragraph/math/radical/math-radical-properties.ts
Normal file
13
src/file/paragraph/math/radical/math-radical-properties.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_radPr-1.html
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { MathDegreeHide } from "./math-degree-hide";
|
||||
|
||||
export class MathRadicalProperties extends XmlComponent {
|
||||
constructor(hasDegree: boolean) {
|
||||
super("m:radPr");
|
||||
|
||||
if (!hasDegree) {
|
||||
this.root.push(new MathDegreeHide());
|
||||
}
|
||||
}
|
||||
}
|
48
src/file/paragraph/math/radical/math-radical.spec.ts
Normal file
48
src/file/paragraph/math/radical/math-radical.spec.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { MathRun } from "../math-run";
|
||||
import { MathRadical } from "./math-radical";
|
||||
|
||||
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"),
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathRadical);
|
||||
expect(tree).to.deep.equal({
|
||||
"m:rad": [
|
||||
{
|
||||
"m:radPr": {},
|
||||
},
|
||||
{
|
||||
"m:deg": [
|
||||
{
|
||||
"m:r": [
|
||||
{
|
||||
"m:t": ["2"],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"m:e": [
|
||||
{
|
||||
"m:r": [
|
||||
{
|
||||
"m:t": ["e"],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
22
src/file/paragraph/math/radical/math-radical.ts
Normal file
22
src/file/paragraph/math/radical/math-radical.ts
Normal file
@ -0,0 +1,22 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_rad-1.html
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { MathDegree } from "./math-degree";
|
||||
import { MathRadicalProperties } from "./math-radical-properties";
|
||||
|
||||
export interface IMathRadicalOptions {
|
||||
readonly child: MathComponent;
|
||||
readonly degree?: MathComponent;
|
||||
}
|
||||
|
||||
export class MathRadical extends XmlComponent {
|
||||
constructor(options: IMathRadicalOptions) {
|
||||
super("m:rad");
|
||||
|
||||
this.root.push(new MathRadicalProperties(!!options.degree));
|
||||
this.root.push(new MathDegree(options.degree));
|
||||
this.root.push(new MathBase(options.child));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user