diff --git a/src/file/paragraph/math/bar/index.ts b/src/file/paragraph/math/bar/index.ts new file mode 100644 index 0000000000..c524bfc3cf --- /dev/null +++ b/src/file/paragraph/math/bar/index.ts @@ -0,0 +1,2 @@ +export * from "./math-bar"; +export * from "./math-bar-properties"; diff --git a/src/file/paragraph/math/bar/math-bar-pos.ts b/src/file/paragraph/math/bar/math-bar-pos.ts new file mode 100644 index 0000000000..d5051d1f2d --- /dev/null +++ b/src/file/paragraph/math/bar/math-bar-pos.ts @@ -0,0 +1,11 @@ +// https://www.datypic.com/sc/ooxml/e-m_pos-1.html +import { Attributes, 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)); + } +} diff --git a/src/file/paragraph/math/bar/math-bar-properties.spec.ts b/src/file/paragraph/math/bar/math-bar-properties.spec.ts new file mode 100644 index 0000000000..1e5a369d84 --- /dev/null +++ b/src/file/paragraph/math/bar/math-bar-properties.spec.ts @@ -0,0 +1,43 @@ +import { describe, expect, it } from "vitest"; + +import { Formatter } from "@export/formatter"; + +import { MathBarProperties } from "./math-bar-properties"; +describe("MathBarProperties", () => { + describe("#constructor()", () => { + it("should create a MathBarProperties with top key", () => { + const mathBarProperties = new MathBarProperties("top"); + + const tree = new Formatter().format(mathBarProperties); + + expect(tree).to.deep.equal({ + "m:barPr": [ + { + "m:pos": { + _attr: { + "w:val": "top", + }, + }, + }, + ], + }); + }); + it("should create a MathBarProperties with bottom key", () => { + const mathBarProperties = new MathBarProperties("bot"); + + const tree = new Formatter().format(mathBarProperties); + + expect(tree).to.deep.equal({ + "m:barPr": [ + { + "m:pos": { + _attr: { + "w:val": "bot", + }, + }, + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/bar/math-bar-properties.ts b/src/file/paragraph/math/bar/math-bar-properties.ts new file mode 100644 index 0000000000..71201d85be --- /dev/null +++ b/src/file/paragraph/math/bar/math-bar-properties.ts @@ -0,0 +1,11 @@ +// https://www.datypic.com/sc/ooxml/e-m_barPr-1.html +import { XmlComponent } from "@file/xml-components"; + +import { MathBarPos } from "./math-bar-pos"; + +export class MathBarProperties extends XmlComponent { + public constructor(type: string) { + super("m:barPr"); + this.root.push(new MathBarPos({ val: type })); + } +} diff --git a/src/file/paragraph/math/bar/math-bar.spec.ts b/src/file/paragraph/math/bar/math-bar.spec.ts new file mode 100644 index 0000000000..1a0709395e --- /dev/null +++ b/src/file/paragraph/math/bar/math-bar.spec.ts @@ -0,0 +1,38 @@ +import { describe, expect, it } from "vitest"; + +import { Formatter } from "@export/formatter"; + +import { MathBar } from "./math-bar"; +import { MathRun } from "../math-run"; + +describe("MathBar", () => { + describe("#constructor()", () => { + it("should create a MathBar with correct root key", () => { + const mathBar = new MathBar({ type: "top", children: [new MathRun("text")] }); + const tree = new Formatter().format(mathBar); + + expect(tree).to.deep.equal({ + "m:bar": [ + { + "m:barPr": [ + { + "m:pos": { + _attr: { + "w:val": "top", + }, + }, + }, + ], + }, + { + "m:e": [ + { + "m:r": [{ "m:t": ["text"] }], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/bar/math-bar.ts b/src/file/paragraph/math/bar/math-bar.ts new file mode 100644 index 0000000000..e2499b8de7 --- /dev/null +++ b/src/file/paragraph/math/bar/math-bar.ts @@ -0,0 +1,18 @@ +// https://www.datypic.com/sc/ooxml/e-m_bar-1.html +import { XmlComponent } from "@file/xml-components"; + +import { MathBarProperties } from "./math-bar-properties"; +import type { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; + +type MathBarOption = { + 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)); + } +} diff --git a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts index a6a5ee0ef6..e3fe6d76b7 100644 --- a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts @@ -2,7 +2,7 @@ import { XmlComponent } from "@file/xml-components"; import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties"; -import { MathComponent } from "../../math-component"; +import type { MathComponent } from "../../math-component"; import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-ary"; export type IMathPreSubSuperScriptOptions = {