Documentation and Refactoring (#3028)
* Documentation and Refactoring * Documentation and Refactoring * Fix lint issues * Convert components to Builder style --------- Co-authored-by: Dolan Miu <dmiu@bloomberg.net>
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
// https://www.datypic.com/sc/ooxml/e-m_pos-1.html
|
||||
import { Attributes, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
export class MathBarPos extends XmlComponent {
|
||||
// TODO: Use correct types rather than any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
public constructor(attributes: any) {
|
||||
super("m:pos");
|
||||
this.root.push(new Attributes(attributes));
|
||||
}
|
||||
}
|
||||
type MathBarPosOptions = { readonly val: string };
|
||||
|
||||
export const createMathBarPos = ({ val }: MathBarPosOptions): XmlComponent =>
|
||||
new BuilderElement<MathBarPosOptions>({
|
||||
name: "m:pos",
|
||||
attributes: {
|
||||
val: { key: "w:val", value: val },
|
||||
},
|
||||
});
|
||||
|
@ -2,11 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathBarProperties } from "./math-bar-properties";
|
||||
import { createMathBarProperties } from "./math-bar-properties";
|
||||
|
||||
describe("MathBarProperties", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathBarProperties with top key", () => {
|
||||
const mathBarProperties = new MathBarProperties("top");
|
||||
const mathBarProperties = createMathBarProperties({ type: "top" });
|
||||
|
||||
const tree = new Formatter().format(mathBarProperties);
|
||||
|
||||
@ -23,7 +24,7 @@ describe("MathBarProperties", () => {
|
||||
});
|
||||
});
|
||||
it("should create a MathBarProperties with bottom key", () => {
|
||||
const mathBarProperties = new MathBarProperties("bot");
|
||||
const mathBarProperties = createMathBarProperties({ type: "bot" });
|
||||
|
||||
const tree = new Formatter().format(mathBarProperties);
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
// https://www.datypic.com/sc/ooxml/e-m_barPr-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathBarPos } from "./math-bar-pos";
|
||||
import { createMathBarPos } from "./math-bar-pos";
|
||||
|
||||
export class MathBarProperties extends XmlComponent {
|
||||
public constructor(type: string) {
|
||||
super("m:barPr");
|
||||
this.root.push(new MathBarPos({ val: type }));
|
||||
}
|
||||
}
|
||||
export const createMathBarProperties = ({ type }: { readonly type: string }): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:barPr",
|
||||
children: [createMathBarPos({ val: type })],
|
||||
});
|
||||
|
@ -2,13 +2,13 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathBar } from "./math-bar";
|
||||
import { MathRun } from "../math-run";
|
||||
import { createMathBar } from "./math-bar";
|
||||
|
||||
describe("MathBar", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathBar with correct root key", () => {
|
||||
const mathBar = new MathBar({ type: "top", children: [new MathRun("text")] });
|
||||
const mathBar = createMathBar({ type: "top", children: [new MathRun("text")] });
|
||||
const tree = new Formatter().format(mathBar);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,18 +1,17 @@
|
||||
// https://www.datypic.com/sc/ooxml/e-m_bar-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathBarProperties } from "./math-bar-properties";
|
||||
import type { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { createMathBarProperties } from "./math-bar-properties";
|
||||
|
||||
type MathBarOption = {
|
||||
type MathBarOptions = {
|
||||
readonly type: "top" | "bot";
|
||||
readonly children: readonly MathComponent[];
|
||||
};
|
||||
export class MathBar extends XmlComponent {
|
||||
public constructor(options: MathBarOption) {
|
||||
super("m:bar");
|
||||
this.root.push(new MathBarProperties(options.type));
|
||||
this.root.push(new MathBase(options.children));
|
||||
}
|
||||
}
|
||||
|
||||
export const createMathBar = ({ type, children }: MathBarOptions): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:bar",
|
||||
children: [createMathBarProperties({ type }), createMathBase({ children })],
|
||||
});
|
||||
|
@ -2,19 +2,23 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { createMathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
type MathAngledBracketsOptions = { readonly children: readonly MathComponent[] };
|
||||
|
||||
export class MathAngledBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
public constructor(options: MathAngledBracketsOptions) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
new MathBracketProperties({
|
||||
beginningCharacter: "〈",
|
||||
endingCharacter: "〉",
|
||||
createMathBracketProperties({
|
||||
characters: {
|
||||
beginningCharacter: "〈",
|
||||
endingCharacter: "〉",
|
||||
},
|
||||
}),
|
||||
);
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathBeginningCharacter } from "./math-beginning-character";
|
||||
import { createMathBeginningCharacter } from "./math-beginning-character";
|
||||
|
||||
describe("MathBeginningCharacter", () => {
|
||||
describe("createMathBeginningCharacter", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathBeginningCharacter with correct root key", () => {
|
||||
const mathBeginningCharacter = new MathBeginningCharacter("[");
|
||||
const mathBeginningCharacter = createMathBeginningCharacter({ character: "[" });
|
||||
|
||||
const tree = new Formatter().format(mathBeginningCharacter);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,14 +1,12 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_begChr-1.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
class MathBeginningCharacterAttributes extends XmlAttributeComponent<{ readonly character: string }> {
|
||||
protected readonly xmlKeys = { character: "m:val" };
|
||||
}
|
||||
type MathBeginningCharacterOptions = { readonly character: string };
|
||||
|
||||
export class MathBeginningCharacter extends XmlComponent {
|
||||
public constructor(character: string) {
|
||||
super("m:begChr");
|
||||
|
||||
this.root.push(new MathBeginningCharacterAttributes({ character }));
|
||||
}
|
||||
}
|
||||
export const createMathBeginningCharacter = ({ character }: MathBeginningCharacterOptions): XmlComponent =>
|
||||
new BuilderElement<MathBeginningCharacterOptions>({
|
||||
name: "m:begChr",
|
||||
attributes: {
|
||||
character: { key: "m:val", value: character },
|
||||
},
|
||||
});
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
import { createMathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
describe("MathBracketProperties", () => {
|
||||
describe("createMathBracketProperties", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathBracketProperties with correct root key", () => {
|
||||
const mathBracketProperties = new MathBracketProperties();
|
||||
const mathBracketProperties = createMathBracketProperties({});
|
||||
|
||||
const tree = new Formatter().format(mathBracketProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
@ -16,9 +16,11 @@ describe("MathBracketProperties", () => {
|
||||
});
|
||||
|
||||
it("should create a MathBracketProperties with correct root key and add brackets", () => {
|
||||
const mathBracketProperties = new MathBracketProperties({
|
||||
beginningCharacter: "[",
|
||||
endingCharacter: "]",
|
||||
const mathBracketProperties = createMathBracketProperties({
|
||||
characters: {
|
||||
beginningCharacter: "[",
|
||||
endingCharacter: "]",
|
||||
},
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathBracketProperties);
|
||||
|
@ -1,16 +1,18 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_dPr-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathBeginningCharacter } from "./math-beginning-character";
|
||||
import { MathEndingCharacter } from "./math-ending-char";
|
||||
import { createMathBeginningCharacter } from "./math-beginning-character";
|
||||
import { createMathEndingCharacter } from "./math-ending-char";
|
||||
|
||||
export class MathBracketProperties extends XmlComponent {
|
||||
public constructor(options?: { readonly beginningCharacter: string; readonly endingCharacter: string }) {
|
||||
super("m:dPr");
|
||||
type MathBracketPropertiesOptions = { readonly characters?: { readonly beginningCharacter: string; readonly endingCharacter: string } };
|
||||
|
||||
if (!!options) {
|
||||
this.root.push(new MathBeginningCharacter(options.beginningCharacter));
|
||||
this.root.push(new MathEndingCharacter(options.endingCharacter));
|
||||
}
|
||||
}
|
||||
}
|
||||
export const createMathBracketProperties = ({ characters }: MathBracketPropertiesOptions): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:dPr",
|
||||
children: !!characters
|
||||
? [
|
||||
createMathBeginningCharacter({ character: characters.beginningCharacter }),
|
||||
createMathEndingCharacter({ character: characters.endingCharacter }),
|
||||
]
|
||||
: [],
|
||||
});
|
||||
|
@ -2,19 +2,21 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { createMathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathCurlyBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
new MathBracketProperties({
|
||||
beginningCharacter: "{",
|
||||
endingCharacter: "}",
|
||||
createMathBracketProperties({
|
||||
characters: {
|
||||
beginningCharacter: "{",
|
||||
endingCharacter: "}",
|
||||
},
|
||||
}),
|
||||
);
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_endChr-1.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
class MathEndingCharacterAttributes extends XmlAttributeComponent<{ readonly character: string }> {
|
||||
protected readonly xmlKeys = { character: "m:val" };
|
||||
}
|
||||
type MathEndingCharacterOptions = { readonly character: string };
|
||||
|
||||
export class MathEndingCharacter extends XmlComponent {
|
||||
public constructor(character: string) {
|
||||
super("m:endChr");
|
||||
|
||||
this.root.push(new MathEndingCharacterAttributes({ character }));
|
||||
}
|
||||
}
|
||||
export const createMathEndingCharacter = ({ character }: MathEndingCharacterOptions): XmlComponent =>
|
||||
new BuilderElement<MathEndingCharacterOptions>({
|
||||
name: "m:endChr",
|
||||
attributes: {
|
||||
character: { key: "m:val", value: character },
|
||||
},
|
||||
});
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathEndingCharacter } from "./math-ending-char";
|
||||
import { createMathEndingCharacter } from "./math-ending-char";
|
||||
|
||||
describe("MathEndingCharacter", () => {
|
||||
describe("createMathEndingCharacter", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathEndingCharacter with correct root key", () => {
|
||||
const mathEndingCharacter = new MathEndingCharacter("]");
|
||||
const mathEndingCharacter = createMathEndingCharacter({ character: "]" });
|
||||
|
||||
const tree = new Formatter().format(mathEndingCharacter);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -2,14 +2,14 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { createMathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathRoundBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(new MathBracketProperties());
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBracketProperties({}));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,21 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { createMathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathSquareBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
new MathBracketProperties({
|
||||
beginningCharacter: "[",
|
||||
endingCharacter: "]",
|
||||
createMathBracketProperties({
|
||||
characters: {
|
||||
beginningCharacter: "[",
|
||||
endingCharacter: "]",
|
||||
},
|
||||
}),
|
||||
);
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { MathFunctionName } from "./math-function-name";
|
||||
import { MathFunctionProperties } from "./math-function-properties";
|
||||
|
||||
@ -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.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathAccentCharacter } from "./math-accent-character";
|
||||
import { createMathAccentCharacter } from "./math-accent-character";
|
||||
|
||||
describe("MathAccentCharacter", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathAccentCharacter with correct root key", () => {
|
||||
const mathAccentCharacter = new MathAccentCharacter("∑");
|
||||
const mathAccentCharacter = createMathAccentCharacter({ accent: "∑" });
|
||||
|
||||
const tree = new Formatter().format(mathAccentCharacter);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,14 +1,12 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_chr-1.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
class MathAccentCharacterAttributes extends XmlAttributeComponent<{ readonly accent: string }> {
|
||||
protected readonly xmlKeys = { accent: "m:val" };
|
||||
}
|
||||
type MathAccentCharacterOptions = { readonly accent: string };
|
||||
|
||||
export class MathAccentCharacter extends XmlComponent {
|
||||
public constructor(accent: string) {
|
||||
super("m:chr");
|
||||
|
||||
this.root.push(new MathAccentCharacterAttributes({ accent }));
|
||||
}
|
||||
}
|
||||
export const createMathAccentCharacter = ({ accent }: MathAccentCharacterOptions): XmlComponent =>
|
||||
new BuilderElement<MathAccentCharacterOptions>({
|
||||
name: "m:chr",
|
||||
attributes: {
|
||||
accent: { key: "m:val", value: accent },
|
||||
},
|
||||
});
|
||||
|
@ -3,12 +3,12 @@ import { describe, expect, it } from "vitest";
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathRun } from "../math-run";
|
||||
import { MathBase } from "./math-base";
|
||||
import { createMathBase } from "./math-base";
|
||||
|
||||
describe("MathBase", () => {
|
||||
describe("createMathBase", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathBase with correct root key", () => {
|
||||
const mathBase = new MathBase([new MathRun("2+2")]);
|
||||
const mathBase = createMathBase({ children: [new MathRun("2+2")] });
|
||||
|
||||
const tree = new Formatter().format(mathBase);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,14 +1,14 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_e-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathBase extends XmlComponent {
|
||||
public constructor(children: readonly MathComponent[]) {
|
||||
super("m:e");
|
||||
type MathBaseOptions = {
|
||||
readonly children: readonly MathComponent[];
|
||||
};
|
||||
|
||||
for (const child of children) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
export const createMathBase = ({ children }: MathBaseOptions): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:e",
|
||||
children,
|
||||
});
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "./math-base";
|
||||
import { MathNAryProperties } from "./math-n-ary-properties";
|
||||
import { MathSubScriptElement } from "./math-sub-script";
|
||||
import { MathSuperScriptElement } from "./math-super-script";
|
||||
import { createMathBase } from "./math-base";
|
||||
import { createMathNAryProperties } from "./math-n-ary-properties";
|
||||
import { createMathSubScriptElement } from "./math-sub-script";
|
||||
import { createMathSuperScriptElement } from "./math-super-script";
|
||||
|
||||
export type IMathIntegralOptions = {
|
||||
readonly children: readonly MathComponent[];
|
||||
@ -16,16 +16,23 @@ export class MathIntegral extends XmlComponent {
|
||||
public constructor(options: IMathIntegralOptions) {
|
||||
super("m:nary");
|
||||
|
||||
this.root.push(new MathNAryProperties("", !!options.superScript, !!options.subScript, "subSup"));
|
||||
this.root.push(
|
||||
createMathNAryProperties({
|
||||
accent: "",
|
||||
hasSuperScript: !!options.superScript,
|
||||
hasSubScript: !!options.subScript,
|
||||
limitLocationVal: "subSup",
|
||||
}),
|
||||
);
|
||||
|
||||
if (!!options.subScript) {
|
||||
this.root.push(new MathSubScriptElement(options.subScript));
|
||||
this.root.push(createMathSubScriptElement({ children: options.subScript }));
|
||||
}
|
||||
|
||||
if (!!options.superScript) {
|
||||
this.root.push(new MathSuperScriptElement(options.superScript));
|
||||
this.root.push(createMathSuperScriptElement({ children: options.superScript }));
|
||||
}
|
||||
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathLimitLocation } from "./math-limit-location";
|
||||
import { createMathLimitLocation } from "./math-limit-location";
|
||||
|
||||
describe("MathLimitLocation", () => {
|
||||
describe("createMathLimitLocation", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathLimitLocation with correct root key", () => {
|
||||
const mathLimitLocation = new MathLimitLocation();
|
||||
const mathLimitLocation = createMathLimitLocation({});
|
||||
|
||||
const tree = new Formatter().format(mathLimitLocation);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,14 +1,12 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_limLoc-1.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
class MathLimitLocationAttributes extends XmlAttributeComponent<{ readonly value: string }> {
|
||||
protected readonly xmlKeys = { value: "m:val" };
|
||||
}
|
||||
type MathLimitLocationOptions = { readonly value?: string };
|
||||
|
||||
export class MathLimitLocation extends XmlComponent {
|
||||
public constructor(value?: string) {
|
||||
super("m:limLoc");
|
||||
|
||||
this.root.push(new MathLimitLocationAttributes({ value: value || "undOvr" }));
|
||||
}
|
||||
}
|
||||
export const createMathLimitLocation = ({ value }: MathLimitLocationOptions): XmlComponent =>
|
||||
new BuilderElement<Required<MathLimitLocationOptions>>({
|
||||
name: "m:limLoc",
|
||||
attributes: {
|
||||
value: { key: "m:val", value: value || "undOvr" },
|
||||
},
|
||||
});
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "./math-base";
|
||||
import { createMathBase } from "./math-base";
|
||||
import { MathLimit } from "./math-limit";
|
||||
|
||||
export type IMathLimitLowerOptions = {
|
||||
@ -14,7 +14,7 @@ export class MathLimitLower extends XmlComponent {
|
||||
public constructor(options: IMathLimitLowerOptions) {
|
||||
super("m:limLow");
|
||||
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
this.root.push(new MathLimit(options.limit));
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "./math-base";
|
||||
import { createMathBase } from "./math-base";
|
||||
import { MathLimit } from "./math-limit";
|
||||
|
||||
export type IMathLimitUpperOptions = {
|
||||
@ -14,7 +14,7 @@ export class MathLimitUpper extends XmlComponent {
|
||||
public constructor(options: IMathLimitUpperOptions) {
|
||||
super("m:limUpp");
|
||||
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
this.root.push(new MathLimit(options.limit));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,16 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathNAryProperties } from "./math-n-ary-properties";
|
||||
import { createMathNAryProperties } from "./math-n-ary-properties";
|
||||
|
||||
describe("MathNAryProperties", () => {
|
||||
describe("createMathNAryProperties", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathNAryProperties with correct root key", () => {
|
||||
const mathNAryProperties = new MathNAryProperties("∑", true, true);
|
||||
const mathNAryProperties = createMathNAryProperties({
|
||||
accent: "∑",
|
||||
hasSuperScript: true,
|
||||
hasSubScript: true,
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathNAryProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
@ -31,7 +35,11 @@ describe("MathNAryProperties", () => {
|
||||
});
|
||||
|
||||
it("should add super-script hide attributes", () => {
|
||||
const mathNAryProperties = new MathNAryProperties("∑", false, true);
|
||||
const mathNAryProperties = createMathNAryProperties({
|
||||
accent: "∑",
|
||||
hasSuperScript: false,
|
||||
hasSubScript: true,
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathNAryProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
@ -62,7 +70,11 @@ describe("MathNAryProperties", () => {
|
||||
});
|
||||
|
||||
it("should add sub-script hide attributes", () => {
|
||||
const mathNAryProperties = new MathNAryProperties("∑", true, false);
|
||||
const mathNAryProperties = createMathNAryProperties({
|
||||
accent: "∑",
|
||||
hasSuperScript: true,
|
||||
hasSubScript: false,
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathNAryProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
@ -93,7 +105,11 @@ describe("MathNAryProperties", () => {
|
||||
});
|
||||
|
||||
it("should add both super-script and sub-script hide attributes", () => {
|
||||
const mathNAryProperties = new MathNAryProperties("∑", false, false);
|
||||
const mathNAryProperties = createMathNAryProperties({
|
||||
accent: "∑",
|
||||
hasSuperScript: false,
|
||||
hasSubScript: false,
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(mathNAryProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,26 +1,30 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_naryPr-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathAccentCharacter } from "./math-accent-character";
|
||||
import { MathLimitLocation } from "./math-limit-location";
|
||||
import { MathSubScriptHide } from "./math-sub-script-hide";
|
||||
import { MathSuperScriptHide } from "./math-super-script-hide";
|
||||
import { createMathAccentCharacter } from "./math-accent-character";
|
||||
import { createMathLimitLocation } from "./math-limit-location";
|
||||
import { createMathSubScriptHide } from "./math-sub-script-hide";
|
||||
import { createMathSuperScriptHide } from "./math-super-script-hide";
|
||||
|
||||
export class MathNAryProperties extends XmlComponent {
|
||||
public constructor(accent: string, hasSuperScript: boolean, hasSubScript: boolean, limitLocationVal?: string) {
|
||||
super("m:naryPr");
|
||||
type MathNAryPropertiesOptions = {
|
||||
readonly accent: string;
|
||||
readonly hasSuperScript: boolean;
|
||||
readonly hasSubScript: boolean;
|
||||
readonly limitLocationVal?: string;
|
||||
};
|
||||
|
||||
if (!!accent) {
|
||||
this.root.push(new MathAccentCharacter(accent));
|
||||
}
|
||||
this.root.push(new MathLimitLocation(limitLocationVal));
|
||||
|
||||
if (!hasSuperScript) {
|
||||
this.root.push(new MathSuperScriptHide());
|
||||
}
|
||||
|
||||
if (!hasSubScript) {
|
||||
this.root.push(new MathSubScriptHide());
|
||||
}
|
||||
}
|
||||
}
|
||||
export const createMathNAryProperties = ({
|
||||
accent,
|
||||
hasSuperScript,
|
||||
hasSubScript,
|
||||
limitLocationVal,
|
||||
}: MathNAryPropertiesOptions): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:naryPr",
|
||||
children: [
|
||||
...(!!accent ? [createMathAccentCharacter({ accent })] : []),
|
||||
createMathLimitLocation({ value: limitLocationVal }),
|
||||
...(!hasSuperScript ? [createMathSuperScriptHide()] : []),
|
||||
...(!hasSubScript ? [createMathSubScriptHide()] : []),
|
||||
],
|
||||
});
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathSubScriptHide } from "./math-sub-script-hide";
|
||||
import { createMathSubScriptHide } from "./math-sub-script-hide";
|
||||
|
||||
describe("MathSubScriptHide", () => {
|
||||
describe("createMathSubScriptHide", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSubScriptHide with correct root key", () => {
|
||||
const mathSubScriptHide = new MathSubScriptHide();
|
||||
const mathSubScriptHide = createMathSubScriptHide();
|
||||
|
||||
const tree = new Formatter().format(mathSubScriptHide);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,14 +1,10 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_subHide-1.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
class MathSubScriptHideAttributes extends XmlAttributeComponent<{ readonly hide: number }> {
|
||||
protected readonly xmlKeys = { hide: "m:val" };
|
||||
}
|
||||
|
||||
export class MathSubScriptHide extends XmlComponent {
|
||||
public constructor() {
|
||||
super("m:subHide");
|
||||
|
||||
this.root.push(new MathSubScriptHideAttributes({ hide: 1 }));
|
||||
}
|
||||
}
|
||||
export const createMathSubScriptHide = (): XmlComponent =>
|
||||
new BuilderElement<{ readonly hide: number }>({
|
||||
name: "m:subHide",
|
||||
attributes: {
|
||||
hide: { key: "m:val", value: 1 },
|
||||
},
|
||||
});
|
||||
|
@ -3,12 +3,12 @@ import { describe, expect, it } from "vitest";
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathRun } from "../math-run";
|
||||
import { MathSubScriptElement } from "./math-sub-script";
|
||||
import { createMathSubScriptElement } from "./math-sub-script";
|
||||
|
||||
describe("MathSubScriptElement", () => {
|
||||
describe("createMathSubScriptElement", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSubScriptElement with correct root key", () => {
|
||||
const mathSubScriptElement = new MathSubScriptElement([new MathRun("2+2")]);
|
||||
const mathSubScriptElement = createMathSubScriptElement({ children: [new MathRun("2+2")] });
|
||||
|
||||
const tree = new Formatter().format(mathSubScriptElement);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,14 +1,14 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_sub-3.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathSubScriptElement extends XmlComponent {
|
||||
public constructor(children: readonly MathComponent[]) {
|
||||
super("m:sub");
|
||||
type MathSubScriptElementOptions = {
|
||||
readonly children: readonly MathComponent[];
|
||||
};
|
||||
|
||||
for (const child of children) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
export const createMathSubScriptElement = ({ children }: MathSubScriptElementOptions): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:sub",
|
||||
children,
|
||||
});
|
||||
|
@ -2,10 +2,10 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "./math-base";
|
||||
import { MathNAryProperties } from "./math-n-ary-properties";
|
||||
import { MathSubScriptElement } from "./math-sub-script";
|
||||
import { MathSuperScriptElement } from "./math-super-script";
|
||||
import { createMathBase } from "./math-base";
|
||||
import { createMathNAryProperties } from "./math-n-ary-properties";
|
||||
import { createMathSubScriptElement } from "./math-sub-script";
|
||||
import { createMathSuperScriptElement } from "./math-super-script";
|
||||
|
||||
export type IMathSumOptions = {
|
||||
readonly children: readonly MathComponent[];
|
||||
@ -17,16 +17,22 @@ export class MathSum extends XmlComponent {
|
||||
public constructor(options: IMathSumOptions) {
|
||||
super("m:nary");
|
||||
|
||||
this.root.push(new MathNAryProperties("∑", !!options.superScript, !!options.subScript));
|
||||
this.root.push(
|
||||
createMathNAryProperties({
|
||||
accent: "∑",
|
||||
hasSuperScript: !!options.superScript,
|
||||
hasSubScript: !!options.subScript,
|
||||
}),
|
||||
);
|
||||
|
||||
if (!!options.subScript) {
|
||||
this.root.push(new MathSubScriptElement(options.subScript));
|
||||
this.root.push(createMathSubScriptElement({ children: options.subScript }));
|
||||
}
|
||||
|
||||
if (!!options.superScript) {
|
||||
this.root.push(new MathSuperScriptElement(options.superScript));
|
||||
this.root.push(createMathSuperScriptElement({ children: options.superScript }));
|
||||
}
|
||||
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathSuperScriptHide } from "./math-super-script-hide";
|
||||
import { createMathSuperScriptHide } from "./math-super-script-hide";
|
||||
|
||||
describe("MathSuperScriptHide", () => {
|
||||
describe("createMathSuperScriptHide", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSuperScriptHide with correct root key", () => {
|
||||
const mathSuperScriptHide = new MathSuperScriptHide();
|
||||
const mathSuperScriptHide = createMathSuperScriptHide();
|
||||
|
||||
const tree = new Formatter().format(mathSuperScriptHide);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,14 +1,10 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_subHide-1.html
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
class MathSuperScriptHideAttributes extends XmlAttributeComponent<{ readonly hide: number }> {
|
||||
protected readonly xmlKeys = { hide: "m:val" };
|
||||
}
|
||||
|
||||
export class MathSuperScriptHide extends XmlComponent {
|
||||
public constructor() {
|
||||
super("m:supHide");
|
||||
|
||||
this.root.push(new MathSuperScriptHideAttributes({ hide: 1 }));
|
||||
}
|
||||
}
|
||||
export const createMathSuperScriptHide = (): XmlComponent =>
|
||||
new BuilderElement<{ readonly hide: number }>({
|
||||
name: "m:supHide",
|
||||
attributes: {
|
||||
hide: { key: "m:val", value: 1 },
|
||||
},
|
||||
});
|
||||
|
@ -3,12 +3,12 @@ import { describe, expect, it } from "vitest";
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathRun } from "../math-run";
|
||||
import { MathSuperScriptElement } from "./math-super-script";
|
||||
import { createMathSuperScriptElement } from "./math-super-script";
|
||||
|
||||
describe("MathSuperScriptElement", () => {
|
||||
describe("createMathSuperScriptElement", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSuperScriptElement with correct root key", () => {
|
||||
const mathSuperScriptElement = new MathSuperScriptElement([new MathRun("2+2")]);
|
||||
const mathSuperScriptElement = createMathSuperScriptElement({ children: [new MathRun("2+2")] });
|
||||
|
||||
const tree = new Formatter().format(mathSuperScriptElement);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,14 +1,14 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_sup-3.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathSuperScriptElement extends XmlComponent {
|
||||
public constructor(children: readonly MathComponent[]) {
|
||||
super("m:sup");
|
||||
type MathSuperScriptElementOptions = {
|
||||
readonly children: readonly MathComponent[];
|
||||
};
|
||||
|
||||
for (const child of children) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
export const createMathSuperScriptElement = ({ children }: MathSuperScriptElementOptions): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:sup",
|
||||
children,
|
||||
});
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathComponent } from "../math-component";
|
||||
import { MathBase } from "../n-ary";
|
||||
import { createMathBase } from "../n-ary";
|
||||
import { MathDegree } from "./math-degree";
|
||||
import { MathRadicalProperties } from "./math-radical-properties";
|
||||
|
||||
@ -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.children));
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties";
|
||||
import { createMathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties";
|
||||
|
||||
describe("MathPreSubSuperScriptProperties", () => {
|
||||
describe("createMathPreSubSuperScriptProperties", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathPreSubSuperScriptProperties with correct root key", () => {
|
||||
const mathPreSubSuperScriptProperties = new MathPreSubSuperScriptProperties();
|
||||
const mathPreSubSuperScriptProperties = createMathPreSubSuperScriptProperties();
|
||||
|
||||
const tree = new Formatter().format(mathPreSubSuperScriptProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,8 +1,7 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_sPrePr-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
export class MathPreSubSuperScriptProperties extends XmlComponent {
|
||||
public constructor() {
|
||||
super("m:sPrePr");
|
||||
}
|
||||
}
|
||||
export const createMathPreSubSuperScriptProperties = (): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:sPrePr",
|
||||
});
|
||||
|
@ -1,9 +1,9 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_sPre-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement } from "@file/xml-components";
|
||||
|
||||
import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties";
|
||||
import { createMathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties";
|
||||
import type { MathComponent } from "../../math-component";
|
||||
import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-ary";
|
||||
import { createMathBase, createMathSubScriptElement, createMathSuperScriptElement } from "../../n-ary";
|
||||
|
||||
export type IMathPreSubSuperScriptOptions = {
|
||||
readonly children: readonly MathComponent[];
|
||||
@ -11,13 +11,16 @@ export type IMathPreSubSuperScriptOptions = {
|
||||
readonly superScript: readonly MathComponent[];
|
||||
};
|
||||
|
||||
export class MathPreSubSuperScript extends XmlComponent {
|
||||
public constructor(options: IMathPreSubSuperScriptOptions) {
|
||||
super("m:sPre");
|
||||
|
||||
this.root.push(new MathPreSubSuperScriptProperties());
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(new MathSubScriptElement(options.subScript));
|
||||
this.root.push(new MathSuperScriptElement(options.superScript));
|
||||
export class MathPreSubSuperScript extends BuilderElement {
|
||||
public constructor({ children, subScript, superScript }: IMathPreSubSuperScriptOptions) {
|
||||
super({
|
||||
name: "m:sPre",
|
||||
children: [
|
||||
createMathPreSubSuperScriptProperties(),
|
||||
createMathBase({ children: children }),
|
||||
createMathSubScriptElement({ children: subScript }),
|
||||
createMathSuperScriptElement({ children: superScript }),
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathSubScriptProperties } from "./math-sub-script-function-properties";
|
||||
import { createMathSubScriptProperties } from "./math-sub-script-function-properties";
|
||||
|
||||
describe("MathSubScriptProperties", () => {
|
||||
describe("createMathSubScriptProperties", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSubScriptProperties with correct root key", () => {
|
||||
const mathSubScriptProperties = new MathSubScriptProperties();
|
||||
const mathSubScriptProperties = createMathSubScriptProperties();
|
||||
|
||||
const tree = new Formatter().format(mathSubScriptProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,8 +1,7 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_sSubPr-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
export class MathSubScriptProperties extends XmlComponent {
|
||||
public constructor() {
|
||||
super("m:sSubPr");
|
||||
}
|
||||
}
|
||||
export const createMathSubScriptProperties = (): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:sSubPr",
|
||||
});
|
||||
|
@ -1,9 +1,9 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_sSub-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathSubScriptProperties } from "./math-sub-script-function-properties";
|
||||
import { createMathSubScriptProperties } from "./math-sub-script-function-properties";
|
||||
import { MathComponent } from "../../math-component";
|
||||
import { MathBase, MathSubScriptElement } from "../../n-ary";
|
||||
import { createMathBase, createMathSubScriptElement } from "../../n-ary";
|
||||
|
||||
export type IMathSubScriptOptions = {
|
||||
readonly children: readonly MathComponent[];
|
||||
@ -14,8 +14,8 @@ export class MathSubScript extends XmlComponent {
|
||||
public constructor(options: IMathSubScriptOptions) {
|
||||
super("m:sSub");
|
||||
|
||||
this.root.push(new MathSubScriptProperties());
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(new MathSubScriptElement(options.subScript));
|
||||
this.root.push(createMathSubScriptProperties());
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
this.root.push(createMathSubScriptElement({ children: options.subScript }));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties";
|
||||
import { createMathSubSuperScriptProperties } from "./math-sub-super-script-function-properties";
|
||||
|
||||
describe("MathSubSuperScriptProperties", () => {
|
||||
describe("createMathSuperScriptProperties", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSubSuperScriptProperties with correct root key", () => {
|
||||
const mathSubSuperScriptProperties = new MathSubSuperScriptProperties();
|
||||
const mathSubSuperScriptProperties = createMathSubSuperScriptProperties();
|
||||
|
||||
const tree = new Formatter().format(mathSubSuperScriptProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,8 +1,7 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_sSubSupPr-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
export class MathSubSuperScriptProperties extends XmlComponent {
|
||||
public constructor() {
|
||||
super("m:sSubSupPr");
|
||||
}
|
||||
}
|
||||
export const createMathSubSuperScriptProperties = (): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:sSubSupPr",
|
||||
});
|
||||
|
@ -1,9 +1,9 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_sSubSup-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties";
|
||||
import { createMathSubSuperScriptProperties } from "./math-sub-super-script-function-properties";
|
||||
import { MathComponent } from "../../math-component";
|
||||
import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-ary";
|
||||
import { createMathBase, createMathSubScriptElement, createMathSuperScriptElement } from "../../n-ary";
|
||||
|
||||
export type IMathSubSuperScriptOptions = {
|
||||
readonly children: readonly MathComponent[];
|
||||
@ -15,9 +15,9 @@ export class MathSubSuperScript extends XmlComponent {
|
||||
public constructor(options: IMathSubSuperScriptOptions) {
|
||||
super("m:sSubSup");
|
||||
|
||||
this.root.push(new MathSubSuperScriptProperties());
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(new MathSubScriptElement(options.subScript));
|
||||
this.root.push(new MathSuperScriptElement(options.superScript));
|
||||
this.root.push(createMathSubSuperScriptProperties());
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
this.root.push(createMathSubScriptElement({ children: options.subScript }));
|
||||
this.root.push(createMathSuperScriptElement({ children: options.superScript }));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { MathSuperScriptProperties } from "./math-super-script-function-properties";
|
||||
import { createMathSuperScriptProperties } from "./math-super-script-function-properties";
|
||||
|
||||
describe("MathSuperScriptProperties", () => {
|
||||
describe("createMathSuperScriptProperties", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create a MathSuperScriptProperties with correct root key", () => {
|
||||
const mathSuperScriptProperties = new MathSuperScriptProperties();
|
||||
const mathSuperScriptProperties = createMathSuperScriptProperties();
|
||||
|
||||
const tree = new Formatter().format(mathSuperScriptProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,8 +1,7 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_sSupPr-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
export class MathSuperScriptProperties extends XmlComponent {
|
||||
public constructor() {
|
||||
super("m:sSupPr");
|
||||
}
|
||||
}
|
||||
export const createMathSuperScriptProperties = (): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "m:sSupPr",
|
||||
});
|
||||
|
@ -1,9 +1,9 @@
|
||||
// http://www.datypic.com/sc/ooxml/e-m_sSup-1.html
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { MathSuperScriptProperties } from "./math-super-script-function-properties";
|
||||
import { createMathSuperScriptProperties } from "./math-super-script-function-properties";
|
||||
import { MathComponent } from "../../math-component";
|
||||
import { MathBase, MathSuperScriptElement } from "../../n-ary";
|
||||
import { createMathBase, createMathSuperScriptElement } from "../../n-ary";
|
||||
|
||||
export type IMathSuperScriptOptions = {
|
||||
readonly children: readonly MathComponent[];
|
||||
@ -14,8 +14,8 @@ export class MathSuperScript extends XmlComponent {
|
||||
public constructor(options: IMathSuperScriptOptions) {
|
||||
super("m:sSup");
|
||||
|
||||
this.root.push(new MathSuperScriptProperties());
|
||||
this.root.push(new MathBase(options.children));
|
||||
this.root.push(new MathSuperScriptElement(options.superScript));
|
||||
this.root.push(createMathSuperScriptProperties());
|
||||
this.root.push(createMathBase({ children: options.children }));
|
||||
this.root.push(createMathSuperScriptElement({ children: options.superScript }));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user