Feature/math improve (#2976)
* add new feature * add test file * update test file * update test file * Fix linting --------- Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
This commit is contained in:
2
src/file/paragraph/math/bar/index.ts
Normal file
2
src/file/paragraph/math/bar/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./math-bar";
|
||||
export * from "./math-bar-properties";
|
11
src/file/paragraph/math/bar/math-bar-pos.ts
Normal file
11
src/file/paragraph/math/bar/math-bar-pos.ts
Normal file
@ -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));
|
||||
}
|
||||
}
|
43
src/file/paragraph/math/bar/math-bar-properties.spec.ts
Normal file
43
src/file/paragraph/math/bar/math-bar-properties.spec.ts
Normal file
@ -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",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
11
src/file/paragraph/math/bar/math-bar-properties.ts
Normal file
11
src/file/paragraph/math/bar/math-bar-properties.ts
Normal file
@ -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 }));
|
||||
}
|
||||
}
|
38
src/file/paragraph/math/bar/math-bar.spec.ts
Normal file
38
src/file/paragraph/math/bar/math-bar.spec.ts
Normal file
@ -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"] }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
18
src/file/paragraph/math/bar/math-bar.ts
Normal file
18
src/file/paragraph/math/bar/math-bar.ts
Normal file
@ -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));
|
||||
}
|
||||
}
|
@ -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 = {
|
||||
|
Reference in New Issue
Block a user