Merge branch 'dolanmiu:master' into master
This commit is contained in:
@ -16,6 +16,7 @@ import {
|
|||||||
MathSubScript,
|
MathSubScript,
|
||||||
MathSubSuperScript,
|
MathSubSuperScript,
|
||||||
MathSum,
|
MathSum,
|
||||||
|
MathIntegral,
|
||||||
MathSuperScript,
|
MathSuperScript,
|
||||||
Packer,
|
Packer,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
@ -90,6 +91,35 @@ const doc = new Document({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathIntegral({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
}),
|
||||||
|
new MathIntegral({
|
||||||
|
children: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("e")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
new MathIntegral({
|
||||||
|
children: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
superScript: [new MathRun("10")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
new Math({
|
new Math({
|
||||||
|
@ -2,7 +2,7 @@ import { MathAngledBrackets, MathCurlyBrackets, MathRoundBrackets, MathSquareBra
|
|||||||
import { MathFraction } from "./fraction";
|
import { MathFraction } from "./fraction";
|
||||||
import { MathFunction } from "./function";
|
import { MathFunction } from "./function";
|
||||||
import { MathRun } from "./math-run";
|
import { MathRun } from "./math-run";
|
||||||
import { MathSum } from "./n-ary";
|
import { MathSum, MathIntegral } from "./n-ary";
|
||||||
import { MathRadical } from "./radical";
|
import { MathRadical } from "./radical";
|
||||||
import { MathSubScript, MathSubSuperScript, MathSuperScript } from "./script";
|
import { MathSubScript, MathSubSuperScript, MathSuperScript } from "./script";
|
||||||
|
|
||||||
@ -10,6 +10,7 @@ export type MathComponent =
|
|||||||
| MathRun
|
| MathRun
|
||||||
| MathFraction
|
| MathFraction
|
||||||
| MathSum
|
| MathSum
|
||||||
|
| MathIntegral
|
||||||
| MathSuperScript
|
| MathSuperScript
|
||||||
| MathSubScript
|
| MathSubScript
|
||||||
| MathSubSuperScript
|
| MathSubSuperScript
|
||||||
|
@ -4,4 +4,5 @@ export * from "./math-limit-location";
|
|||||||
export * from "./math-n-ary-properties";
|
export * from "./math-n-ary-properties";
|
||||||
export * from "./math-sub-script";
|
export * from "./math-sub-script";
|
||||||
export * from "./math-sum";
|
export * from "./math-sum";
|
||||||
|
export * from "./math-integral";
|
||||||
export * from "./math-super-script";
|
export * from "./math-super-script";
|
||||||
|
116
src/file/paragraph/math/n-ary/math-integral.spec.ts
Normal file
116
src/file/paragraph/math/n-ary/math-integral.spec.ts
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Formatter } from "@export/formatter";
|
||||||
|
|
||||||
|
import { MathRun } from "../math-run";
|
||||||
|
import { MathIntegral } from "./math-integral";
|
||||||
|
|
||||||
|
describe("MathIntegral", () => {
|
||||||
|
describe("#constructor()", () => {
|
||||||
|
it("should create a MathIntegral with correct root key", () => {
|
||||||
|
const mathIntegral = new MathIntegral({
|
||||||
|
children: [new MathRun("1")],
|
||||||
|
subScript: [new MathRun("2")],
|
||||||
|
superScript: [new MathRun("3")],
|
||||||
|
});
|
||||||
|
|
||||||
|
const tree = new Formatter().format(mathIntegral);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"m:nary": [
|
||||||
|
{
|
||||||
|
"m:naryPr": [
|
||||||
|
{
|
||||||
|
"m:limLoc": {
|
||||||
|
_attr: {
|
||||||
|
"m:val": "undOvr",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"m:sub": [
|
||||||
|
{
|
||||||
|
"m:r": [
|
||||||
|
{
|
||||||
|
"m:t": ["2"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"m:sup": [
|
||||||
|
{
|
||||||
|
"m:r": [
|
||||||
|
{
|
||||||
|
"m:t": ["3"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"m:e": [
|
||||||
|
{
|
||||||
|
"m:r": [
|
||||||
|
{
|
||||||
|
"m:t": ["1"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create a MathIntegral with correct root key without sub-script and super-scripts", () => {
|
||||||
|
const mathIntegral = new MathIntegral({
|
||||||
|
children: [new MathRun("1")],
|
||||||
|
});
|
||||||
|
|
||||||
|
const tree = new Formatter().format(mathIntegral);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"m:nary": [
|
||||||
|
{
|
||||||
|
"m:naryPr": [
|
||||||
|
{
|
||||||
|
"m:limLoc": {
|
||||||
|
_attr: {
|
||||||
|
"m:val": "undOvr",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"m:supHide": {
|
||||||
|
_attr: {
|
||||||
|
"m:val": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"m:subHide": {
|
||||||
|
_attr: {
|
||||||
|
"m:val": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"m:e": [
|
||||||
|
{
|
||||||
|
"m:r": [
|
||||||
|
{
|
||||||
|
"m:t": ["1"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
31
src/file/paragraph/math/n-ary/math-integral.ts
Normal file
31
src/file/paragraph/math/n-ary/math-integral.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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";
|
||||||
|
|
||||||
|
export interface IMathIntegralOptions {
|
||||||
|
readonly children: readonly MathComponent[];
|
||||||
|
readonly subScript?: readonly MathComponent[];
|
||||||
|
readonly superScript?: readonly MathComponent[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MathIntegral extends XmlComponent {
|
||||||
|
public constructor(options: IMathIntegralOptions) {
|
||||||
|
super("m:nary");
|
||||||
|
|
||||||
|
this.root.push(new MathNAryProperties("", !!options.superScript, !!options.subScript));
|
||||||
|
|
||||||
|
if (!!options.subScript) {
|
||||||
|
this.root.push(new MathSubScriptElement(options.subScript));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!!options.superScript) {
|
||||||
|
this.root.push(new MathSuperScriptElement(options.superScript));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.root.push(new MathBase(options.children));
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,9 @@ export class MathNAryProperties extends XmlComponent {
|
|||||||
public constructor(accent: string, hasSuperScript: boolean, hasSubScript: boolean) {
|
public constructor(accent: string, hasSuperScript: boolean, hasSubScript: boolean) {
|
||||||
super("m:naryPr");
|
super("m:naryPr");
|
||||||
|
|
||||||
this.root.push(new MathAccentCharacter(accent));
|
if (!!accent) {
|
||||||
|
this.root.push(new MathAccentCharacter(accent));
|
||||||
|
}
|
||||||
this.root.push(new MathLimitLocation());
|
this.root.push(new MathLimitLocation());
|
||||||
|
|
||||||
if (!hasSuperScript) {
|
if (!hasSuperScript) {
|
||||||
|
Reference in New Issue
Block a user