Add math limit component (#2510)
This commit is contained in:
@ -21,6 +21,8 @@ import {
|
|||||||
Packer,
|
Packer,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
TextRun,
|
TextRun,
|
||||||
|
MathLimitLower,
|
||||||
|
MathLimitUpper,
|
||||||
} from "docx";
|
} from "docx";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
@ -316,6 +318,23 @@ const doc = new Document({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathLimitUpper({
|
||||||
|
children: [new MathRun("x")],
|
||||||
|
limit: [new MathRun("-")],
|
||||||
|
}),
|
||||||
|
new MathRun("="),
|
||||||
|
new MathLimitLower({
|
||||||
|
children: [new MathRun("lim")],
|
||||||
|
limit: [new MathRun("x→0")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -263,3 +263,23 @@ new MathAngledBrackets({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Limit
|
||||||
|
|
||||||
|
#### Limit Upper
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathLimitUpper({
|
||||||
|
children: [new MathRun("x")],
|
||||||
|
limit: [new MathRun("-")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Limit Lower
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathLimitLower({
|
||||||
|
children: [new MathRun("lim")],
|
||||||
|
limit: [new MathRun("x→0")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
@ -6,3 +6,6 @@ export * from "./math-sub-script";
|
|||||||
export * from "./math-sum";
|
export * from "./math-sum";
|
||||||
export * from "./math-integral";
|
export * from "./math-integral";
|
||||||
export * from "./math-super-script";
|
export * from "./math-super-script";
|
||||||
|
export * from "./math-limit";
|
||||||
|
export * from "./math-limit-upper";
|
||||||
|
export * from "./math-limit-lower";
|
||||||
|
45
src/file/paragraph/math/n-ary/math-limit-lower.spec.ts
Normal file
45
src/file/paragraph/math/n-ary/math-limit-lower.spec.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { Formatter } from "@export/formatter";
|
||||||
|
|
||||||
|
import { MathRun } from "../math-run";
|
||||||
|
import { MathLimitLower } from "./math-limit-lower";
|
||||||
|
|
||||||
|
describe("MathLimitLower", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a MathLimitLower with correct root key", () => {
|
||||||
|
const mathLimitLower = new MathLimitLower({
|
||||||
|
children: [new MathRun("lim")],
|
||||||
|
limit: [new MathRun("x→0")],
|
||||||
|
});
|
||||||
|
|
||||||
|
const tree = new Formatter().format(mathLimitLower);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"m:limLow": [
|
||||||
|
{
|
||||||
|
"m:e": [
|
||||||
|
{
|
||||||
|
"m:r": [
|
||||||
|
{
|
||||||
|
"m:t": ["lim"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"m:lim": [
|
||||||
|
{
|
||||||
|
"m:r": [
|
||||||
|
{
|
||||||
|
"m:t": ["x→0"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
19
src/file/paragraph/math/n-ary/math-limit-lower.ts
Normal file
19
src/file/paragraph/math/n-ary/math-limit-lower.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// http://www.datypic.com/sc/ooxml/e-m_limLow-1.html
|
||||||
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
import { MathComponent } from "../math-component";
|
||||||
|
import { MathBase } from "./math-base";
|
||||||
|
import { MathLimit } from "./math-limit";
|
||||||
|
|
||||||
|
export interface IMathLimitLowerOptions {
|
||||||
|
readonly children: readonly MathComponent[];
|
||||||
|
readonly limit: readonly MathComponent[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MathLimitLower extends XmlComponent {
|
||||||
|
public constructor(options: IMathLimitLowerOptions) {
|
||||||
|
super("m:limLow");
|
||||||
|
|
||||||
|
this.root.push(new MathBase(options.children));
|
||||||
|
this.root.push(new MathLimit(options.limit));
|
||||||
|
}
|
||||||
|
}
|
45
src/file/paragraph/math/n-ary/math-limit-upper.spec.ts
Normal file
45
src/file/paragraph/math/n-ary/math-limit-upper.spec.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { Formatter } from "@export/formatter";
|
||||||
|
|
||||||
|
import { MathRun } from "../math-run";
|
||||||
|
import { MathLimitUpper } from "./math-limit-upper";
|
||||||
|
|
||||||
|
describe("MathLimitUpper", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a MathLimitUpper with correct root key", () => {
|
||||||
|
const mathLimitUpper = new MathLimitUpper({
|
||||||
|
children: [new MathRun("x")],
|
||||||
|
limit: [new MathRun("-")],
|
||||||
|
});
|
||||||
|
|
||||||
|
const tree = new Formatter().format(mathLimitUpper);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"m:limUpp": [
|
||||||
|
{
|
||||||
|
"m:e": [
|
||||||
|
{
|
||||||
|
"m:r": [
|
||||||
|
{
|
||||||
|
"m:t": ["x"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"m:lim": [
|
||||||
|
{
|
||||||
|
"m:r": [
|
||||||
|
{
|
||||||
|
"m:t": ["-"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
19
src/file/paragraph/math/n-ary/math-limit-upper.ts
Normal file
19
src/file/paragraph/math/n-ary/math-limit-upper.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// http://www.datypic.com/sc/ooxml/e-m_limUpp-1.html
|
||||||
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
import { MathComponent } from "../math-component";
|
||||||
|
import { MathBase } from "./math-base";
|
||||||
|
import { MathLimit } from "./math-limit";
|
||||||
|
|
||||||
|
export interface IMathLimitUpperOptions {
|
||||||
|
readonly children: readonly MathComponent[];
|
||||||
|
readonly limit: readonly MathComponent[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MathLimitUpper extends XmlComponent {
|
||||||
|
public constructor(options: IMathLimitUpperOptions) {
|
||||||
|
super("m:limUpp");
|
||||||
|
|
||||||
|
this.root.push(new MathBase(options.children));
|
||||||
|
this.root.push(new MathLimit(options.limit));
|
||||||
|
}
|
||||||
|
}
|
27
src/file/paragraph/math/n-ary/math-limit.spec.ts
Normal file
27
src/file/paragraph/math/n-ary/math-limit.spec.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { Formatter } from "@export/formatter";
|
||||||
|
|
||||||
|
import { MathRun } from "../math-run";
|
||||||
|
import { MathLimit } from "./math-limit";
|
||||||
|
|
||||||
|
describe("MathLimit", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a MathLimit with correct root key", () => {
|
||||||
|
const mathLimit = new MathLimit([new MathRun("x→0")]);
|
||||||
|
|
||||||
|
const tree = new Formatter().format(mathLimit);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"m:lim": [
|
||||||
|
{
|
||||||
|
"m:r": [
|
||||||
|
{
|
||||||
|
"m:t": ["x→0"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
13
src/file/paragraph/math/n-ary/math-limit.ts
Normal file
13
src/file/paragraph/math/n-ary/math-limit.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// http://www.datypic.com/sc/ooxml/e-m_lim-1.html
|
||||||
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
import { MathComponent } from "../math-component";
|
||||||
|
|
||||||
|
export class MathLimit extends XmlComponent {
|
||||||
|
public constructor(children: readonly MathComponent[]) {
|
||||||
|
super("m:lim");
|
||||||
|
|
||||||
|
for (const child of children) {
|
||||||
|
this.root.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user