From a1b9be453bbace564b3c9034aab9462bb4dc9977 Mon Sep 17 00:00:00 2001 From: Dolan Date: Thu, 15 Aug 2019 00:47:55 +0100 Subject: [PATCH 1/8] Add math run and fraction --- demo/47-math.ts | 33 ++++++++++++++ src/file/paragraph/index.ts | 1 + src/file/paragraph/math/fraction/index.ts | 3 ++ .../math/fraction/math-denominator.spec.ts | 25 +++++++++++ .../math/fraction/math-denominator.ts | 11 +++++ .../math/fraction/math-fraction.spec.ts | 45 +++++++++++++++++++ .../paragraph/math/fraction/math-fraction.ts | 18 ++++++++ .../math/fraction/math-numerator.spec.ts | 25 +++++++++++ .../paragraph/math/fraction/math-numerator.ts | 11 +++++ src/file/paragraph/math/index.ts | 3 ++ src/file/paragraph/math/math-run.spec.ts | 21 +++++++++ src/file/paragraph/math/math-run.ts | 11 +++++ src/file/paragraph/math/math-text.spec.ts | 17 +++++++ src/file/paragraph/math/math-text.ts | 9 ++++ src/file/paragraph/math/math.spec.ts | 38 ++++++++++++++++ src/file/paragraph/math/math.ts | 19 ++++++++ src/file/paragraph/paragraph.ts | 3 +- 17 files changed, 292 insertions(+), 1 deletion(-) create mode 100644 demo/47-math.ts create mode 100644 src/file/paragraph/math/fraction/index.ts create mode 100644 src/file/paragraph/math/fraction/math-denominator.spec.ts create mode 100644 src/file/paragraph/math/fraction/math-denominator.ts create mode 100644 src/file/paragraph/math/fraction/math-fraction.spec.ts create mode 100644 src/file/paragraph/math/fraction/math-fraction.ts create mode 100644 src/file/paragraph/math/fraction/math-numerator.spec.ts create mode 100644 src/file/paragraph/math/fraction/math-numerator.ts create mode 100644 src/file/paragraph/math/index.ts create mode 100644 src/file/paragraph/math/math-run.spec.ts create mode 100644 src/file/paragraph/math/math-run.ts create mode 100644 src/file/paragraph/math/math-text.spec.ts create mode 100644 src/file/paragraph/math/math-text.ts create mode 100644 src/file/paragraph/math/math.spec.ts create mode 100644 src/file/paragraph/math/math.ts diff --git a/demo/47-math.ts b/demo/47-math.ts new file mode 100644 index 0000000000..7862feac97 --- /dev/null +++ b/demo/47-math.ts @@ -0,0 +1,33 @@ +// Simple example to add text to a document +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { Document, Math, MathDenominator, MathFraction, MathNumerator, MathRun, Packer, Paragraph, TextRun } from "../build"; + +const doc = new Document(); + +doc.addSection({ + properties: {}, + children: [ + new Paragraph({ + children: [ + new Math({ + children: [ + new MathRun("2+2"), + new MathFraction({ + numerator: new MathNumerator("hi"), + denominator: new MathDenominator("2"), + }), + ], + }), + new TextRun({ + text: "Foo Bar", + bold: true, + }), + ], + }), + ], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/src/file/paragraph/index.ts b/src/file/paragraph/index.ts index 222cb1bf4f..a2ab11a21e 100644 --- a/src/file/paragraph/index.ts +++ b/src/file/paragraph/index.ts @@ -4,3 +4,4 @@ export * from "./properties"; export * from "./run"; export * from "./links"; export * from "./image"; +export * from "./math"; diff --git a/src/file/paragraph/math/fraction/index.ts b/src/file/paragraph/math/fraction/index.ts new file mode 100644 index 0000000000..c8af438329 --- /dev/null +++ b/src/file/paragraph/math/fraction/index.ts @@ -0,0 +1,3 @@ +export * from "./math-fraction"; +export * from "./math-denominator"; +export * from "./math-numerator"; diff --git a/src/file/paragraph/math/fraction/math-denominator.spec.ts b/src/file/paragraph/math/fraction/math-denominator.spec.ts new file mode 100644 index 0000000000..cca8ae0ee1 --- /dev/null +++ b/src/file/paragraph/math/fraction/math-denominator.spec.ts @@ -0,0 +1,25 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathDenominator } from "./math-denominator"; + +describe("MathDenominator", () => { + describe("#constructor()", () => { + it("should create a MathDenominator with correct root key", () => { + const mathDenominator = new MathDenominator("2+2"); + const tree = new Formatter().format(mathDenominator); + expect(tree).to.deep.equal({ + "m:den": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/fraction/math-denominator.ts b/src/file/paragraph/math/fraction/math-denominator.ts new file mode 100644 index 0000000000..da9f283bdc --- /dev/null +++ b/src/file/paragraph/math/fraction/math-denominator.ts @@ -0,0 +1,11 @@ +import { XmlComponent } from "file/xml-components"; + +import { MathRun } from "../math-run"; + +export class MathDenominator extends XmlComponent { + constructor(readonly text: string) { + super("m:den"); + + this.root.push(new MathRun(text)); + } +} diff --git a/src/file/paragraph/math/fraction/math-fraction.spec.ts b/src/file/paragraph/math/fraction/math-fraction.spec.ts new file mode 100644 index 0000000000..9a7386e85e --- /dev/null +++ b/src/file/paragraph/math/fraction/math-fraction.spec.ts @@ -0,0 +1,45 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathDenominator } from "./math-denominator"; +import { MathFraction } from "./math-fraction"; +import { MathNumerator } from "./math-numerator"; + +describe("MathFraction", () => { + describe("#constructor()", () => { + it("should create a MathFraction with correct root key", () => { + const mathFraction = new MathFraction({ + numerator: new MathNumerator("2"), + denominator: new MathDenominator("2"), + }); + const tree = new Formatter().format(mathFraction); + expect(tree).to.deep.equal({ + "m:f": [ + { + "m:num": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + { + "m:den": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/fraction/math-fraction.ts b/src/file/paragraph/math/fraction/math-fraction.ts new file mode 100644 index 0000000000..062c3ef575 --- /dev/null +++ b/src/file/paragraph/math/fraction/math-fraction.ts @@ -0,0 +1,18 @@ +import { XmlComponent } from "file/xml-components"; + +import { MathDenominator } from "./math-denominator"; +import { MathNumerator } from "./math-numerator"; + +export interface IMathFractionOptions { + readonly numerator: MathNumerator; + readonly denominator: MathDenominator; +} + +export class MathFraction extends XmlComponent { + constructor(readonly options: IMathFractionOptions) { + super("m:f"); + + this.root.push(options.numerator); + this.root.push(options.denominator); + } +} diff --git a/src/file/paragraph/math/fraction/math-numerator.spec.ts b/src/file/paragraph/math/fraction/math-numerator.spec.ts new file mode 100644 index 0000000000..1cc5fc4aa4 --- /dev/null +++ b/src/file/paragraph/math/fraction/math-numerator.spec.ts @@ -0,0 +1,25 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathNumerator } from "./math-numerator"; + +describe("MathNumerator", () => { + describe("#constructor()", () => { + it("should create a MathNumerator with correct root key", () => { + const mathNumerator = new MathNumerator("2+2"); + const tree = new Formatter().format(mathNumerator); + expect(tree).to.deep.equal({ + "m:num": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/fraction/math-numerator.ts b/src/file/paragraph/math/fraction/math-numerator.ts new file mode 100644 index 0000000000..68799328cb --- /dev/null +++ b/src/file/paragraph/math/fraction/math-numerator.ts @@ -0,0 +1,11 @@ +import { XmlComponent } from "file/xml-components"; + +import { MathRun } from "../math-run"; + +export class MathNumerator extends XmlComponent { + constructor(readonly text: string) { + super("m:num"); + + this.root.push(new MathRun(text)); + } +} diff --git a/src/file/paragraph/math/index.ts b/src/file/paragraph/math/index.ts new file mode 100644 index 0000000000..9f3b22b5fa --- /dev/null +++ b/src/file/paragraph/math/index.ts @@ -0,0 +1,3 @@ +export * from "./math"; +export * from "./math-run"; +export * from "./fraction"; diff --git a/src/file/paragraph/math/math-run.spec.ts b/src/file/paragraph/math/math-run.spec.ts new file mode 100644 index 0000000000..2773a0fb9c --- /dev/null +++ b/src/file/paragraph/math/math-run.spec.ts @@ -0,0 +1,21 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "./math-run"; + +describe("MathRun", () => { + describe("#constructor()", () => { + it("should create a MathRun with correct root key", () => { + const mathRun = new MathRun("2+2"); + const tree = new Formatter().format(mathRun); + expect(tree).to.deep.equal({ + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/math-run.ts b/src/file/paragraph/math/math-run.ts new file mode 100644 index 0000000000..5b9b9536c4 --- /dev/null +++ b/src/file/paragraph/math/math-run.ts @@ -0,0 +1,11 @@ +import { XmlComponent } from "file/xml-components"; + +import { MathText } from "./math-text"; + +export class MathRun extends XmlComponent { + constructor(readonly text: string) { + super("m:r"); + + this.root.push(new MathText(text)); + } +} diff --git a/src/file/paragraph/math/math-text.spec.ts b/src/file/paragraph/math/math-text.spec.ts new file mode 100644 index 0000000000..0001816ed1 --- /dev/null +++ b/src/file/paragraph/math/math-text.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathText } from "./math-text"; + +describe("MathText", () => { + describe("#constructor()", () => { + it("should create a MathText with correct root key", () => { + const mathText = new MathText("2+2"); + const tree = new Formatter().format(mathText); + expect(tree).to.deep.equal({ + "m:t": ["2+2"], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/math-text.ts b/src/file/paragraph/math/math-text.ts new file mode 100644 index 0000000000..907294aab9 --- /dev/null +++ b/src/file/paragraph/math/math-text.ts @@ -0,0 +1,9 @@ +import { XmlComponent } from "file/xml-components"; + +export class MathText extends XmlComponent { + constructor(readonly text: string) { + super("m:t"); + + this.root.push(text); + } +} diff --git a/src/file/paragraph/math/math.spec.ts b/src/file/paragraph/math/math.spec.ts new file mode 100644 index 0000000000..d5c4f6f494 --- /dev/null +++ b/src/file/paragraph/math/math.spec.ts @@ -0,0 +1,38 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { Math } from "./math"; +import { MathRun } from "./math-run"; + +describe("Math", () => { + describe("#constructor()", () => { + it("should create a Math with correct root key", () => { + const math = new Math({ + children: [], + }); + const tree = new Formatter().format(math); + expect(tree).to.deep.equal({ + "m:oMath": {}, + }); + }); + + it("should be able to add children", () => { + const math = new Math({ + children: [new MathRun("2+2")], + }); + const tree = new Formatter().format(math); + expect(tree).to.deep.equal({ + "m:oMath": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/math.ts b/src/file/paragraph/math/math.ts new file mode 100644 index 0000000000..eee6fdff65 --- /dev/null +++ b/src/file/paragraph/math/math.ts @@ -0,0 +1,19 @@ +// http://www.datypic.com/sc/ooxml/e-m_oMath-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathFraction } from "./fraction"; +import { MathRun } from "./math-run"; + +export interface IMathOptions { + readonly children: Array; +} + +export class Math extends XmlComponent { + constructor(readonly options: IMathOptions) { + super("m:oMath"); + + for (const child of options.children) { + this.root.push(child); + } + } +} diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index 3f39ba68bc..c0375fac5c 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -15,6 +15,7 @@ import { HeadingLevel, Style } from "./formatting/style"; import { CenterTabStop, LeaderType, LeftTabStop, MaxRightTabStop, RightTabStop } from "./formatting/tab-stop"; import { NumberProperties } from "./formatting/unordered-list"; import { Bookmark, Hyperlink, OutlineLevel } from "./links"; +import { Math } from "./math"; import { ParagraphProperties } from "./properties"; import { PictureRun, Run, SequentialIdentifier, TextRun } from "./run"; @@ -54,7 +55,7 @@ export interface IParagraphOptions { readonly level: number; readonly custom?: boolean; }; - readonly children?: Array; + readonly children?: Array; } export class Paragraph extends XmlComponent { From 4f8d435e166fe3445649ea3b959cec90b87d226a Mon Sep 17 00:00:00 2001 From: Dolan Date: Tue, 20 Aug 2019 20:40:40 +0100 Subject: [PATCH 2/8] Add Math Summation --- demo/47-math.ts | 13 +++- src/file/paragraph/math/index.ts | 1 + src/file/paragraph/math/math-run.ts | 1 + src/file/paragraph/math/math.ts | 3 +- src/file/paragraph/math/n-ary/index.ts | 7 ++ .../math/n-ary/math-accent-character.spec.ts | 22 ++++++ .../math/n-ary/math-accent-character.ts | 14 ++++ .../paragraph/math/n-ary/math-base.spec.ts | 27 +++++++ src/file/paragraph/math/n-ary/math-base.ts | 12 +++ .../math/n-ary/math-limit-location.spec.ts | 22 ++++++ .../math/n-ary/math-limit-location.ts | 14 ++++ .../math/n-ary/math-naray-properties.spec.ts | 33 ++++++++ .../math/n-ary/math-naray-properties.ts | 14 ++++ .../math/n-ary/math-sub-script.spec.ts | 27 +++++++ .../paragraph/math/n-ary/math-sub-script.ts | 12 +++ .../paragraph/math/n-ary/math-sum.spec.ts | 75 +++++++++++++++++++ src/file/paragraph/math/n-ary/math-sum.ts | 25 +++++++ .../math/n-ary/math-super-script.spec.ts | 27 +++++++ .../paragraph/math/n-ary/math-super-script.ts | 12 +++ 19 files changed, 359 insertions(+), 2 deletions(-) create mode 100644 src/file/paragraph/math/n-ary/index.ts create mode 100644 src/file/paragraph/math/n-ary/math-accent-character.spec.ts create mode 100644 src/file/paragraph/math/n-ary/math-accent-character.ts create mode 100644 src/file/paragraph/math/n-ary/math-base.spec.ts create mode 100644 src/file/paragraph/math/n-ary/math-base.ts create mode 100644 src/file/paragraph/math/n-ary/math-limit-location.spec.ts create mode 100644 src/file/paragraph/math/n-ary/math-limit-location.ts create mode 100644 src/file/paragraph/math/n-ary/math-naray-properties.spec.ts create mode 100644 src/file/paragraph/math/n-ary/math-naray-properties.ts create mode 100644 src/file/paragraph/math/n-ary/math-sub-script.spec.ts create mode 100644 src/file/paragraph/math/n-ary/math-sub-script.ts create mode 100644 src/file/paragraph/math/n-ary/math-sum.spec.ts create mode 100644 src/file/paragraph/math/n-ary/math-sum.ts create mode 100644 src/file/paragraph/math/n-ary/math-super-script.spec.ts create mode 100644 src/file/paragraph/math/n-ary/math-super-script.ts diff --git a/demo/47-math.ts b/demo/47-math.ts index 7862feac97..5cad1707de 100644 --- a/demo/47-math.ts +++ b/demo/47-math.ts @@ -1,7 +1,7 @@ // Simple example to add text to a document // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { Document, Math, MathDenominator, MathFraction, MathNumerator, MathRun, Packer, Paragraph, TextRun } from "../build"; +import { Document, Math, MathDenominator, MathFraction, MathNumerator, MathRun, MathSum, Packer, Paragraph, TextRun } from "../build"; const doc = new Document(); @@ -25,6 +25,17 @@ doc.addSection({ }), ], }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSum({ + child: new MathRun("test"), + }), + ], + }), + ], + }), ], }); diff --git a/src/file/paragraph/math/index.ts b/src/file/paragraph/math/index.ts index 9f3b22b5fa..063678689c 100644 --- a/src/file/paragraph/math/index.ts +++ b/src/file/paragraph/math/index.ts @@ -1,3 +1,4 @@ export * from "./math"; export * from "./math-run"; export * from "./fraction"; +export * from "./n-ary"; diff --git a/src/file/paragraph/math/math-run.ts b/src/file/paragraph/math/math-run.ts index 5b9b9536c4..3b7cceb362 100644 --- a/src/file/paragraph/math/math-run.ts +++ b/src/file/paragraph/math/math-run.ts @@ -1,3 +1,4 @@ +// http://www.datypic.com/sc/ooxml/e-m_r-1.html import { XmlComponent } from "file/xml-components"; import { MathText } from "./math-text"; diff --git a/src/file/paragraph/math/math.ts b/src/file/paragraph/math/math.ts index eee6fdff65..43272ed941 100644 --- a/src/file/paragraph/math/math.ts +++ b/src/file/paragraph/math/math.ts @@ -3,9 +3,10 @@ import { XmlComponent } from "file/xml-components"; import { MathFraction } from "./fraction"; import { MathRun } from "./math-run"; +import { MathSum } from "./n-ary"; export interface IMathOptions { - readonly children: Array; + readonly children: Array; } export class Math extends XmlComponent { diff --git a/src/file/paragraph/math/n-ary/index.ts b/src/file/paragraph/math/n-ary/index.ts new file mode 100644 index 0000000000..6929544152 --- /dev/null +++ b/src/file/paragraph/math/n-ary/index.ts @@ -0,0 +1,7 @@ +export * from "./math-accent-character"; +export * from "./math-base"; +export * from "./math-limit-location"; +export * from "./math-naray-properties"; +export * from "./math-sub-script"; +export * from "./math-sum"; +export * from "./math-super-script"; diff --git a/src/file/paragraph/math/n-ary/math-accent-character.spec.ts b/src/file/paragraph/math/n-ary/math-accent-character.spec.ts new file mode 100644 index 0000000000..b414f4c744 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-accent-character.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathAccentCharacter } from "./math-accent-character"; + +describe("MathAccentCharacter", () => { + describe("#constructor()", () => { + it("should create a MathAccentCharacter with correct root key", () => { + const mathAccentCharacter = new MathAccentCharacter("∑"); + + const tree = new Formatter().format(mathAccentCharacter); + expect(tree).to.deep.equal({ + "m:chr": { + _attr: { + "m:val": "∑", + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-accent-character.ts b/src/file/paragraph/math/n-ary/math-accent-character.ts new file mode 100644 index 0000000000..3a5a10d7d2 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-accent-character.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_chr-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathAccentCharacterAttributes extends XmlAttributeComponent<{ readonly accent: string }> { + protected readonly xmlKeys = { accent: "m:val" }; +} + +export class MathAccentCharacter extends XmlComponent { + constructor(readonly accent: string) { + super("m:chr"); + + this.root.push(new MathAccentCharacterAttributes({ accent })); + } +} diff --git a/src/file/paragraph/math/n-ary/math-base.spec.ts b/src/file/paragraph/math/n-ary/math-base.spec.ts new file mode 100644 index 0000000000..012147c4d9 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-base.spec.ts @@ -0,0 +1,27 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathBase } from "./math-base"; + +describe("MathBase", () => { + describe("#constructor()", () => { + it("should create a MathBase with correct root key", () => { + const mathBase = new MathBase(new MathRun("2+2")); + + const tree = new Formatter().format(mathBase); + expect(tree).to.deep.equal({ + "m:e": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-base.ts b/src/file/paragraph/math/n-ary/math-base.ts new file mode 100644 index 0000000000..e75231cdb2 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-base.ts @@ -0,0 +1,12 @@ +// http://www.datypic.com/sc/ooxml/e-m_e-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathRun } from "../math-run"; + +export class MathBase extends XmlComponent { + constructor(readonly run: MathRun) { + super("m:e"); + + this.root.push(run); + } +} diff --git a/src/file/paragraph/math/n-ary/math-limit-location.spec.ts b/src/file/paragraph/math/n-ary/math-limit-location.spec.ts new file mode 100644 index 0000000000..426f3d0198 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-limit-location.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathLimitLocation } from "./math-limit-location"; + +describe("MathLimitLocation", () => { + describe("#constructor()", () => { + it("should create a MathLimitLocation with correct root key", () => { + const mathLimitLocation = new MathLimitLocation(); + + const tree = new Formatter().format(mathLimitLocation); + expect(tree).to.deep.equal({ + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-limit-location.ts b/src/file/paragraph/math/n-ary/math-limit-location.ts new file mode 100644 index 0000000000..5504e1890d --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-limit-location.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_limLoc-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathLimitLocationAttributes extends XmlAttributeComponent<{ readonly value: string }> { + protected readonly xmlKeys = { value: "m:val" }; +} + +export class MathLimitLocation extends XmlComponent { + constructor() { + super("m:limLoc"); + + this.root.push(new MathLimitLocationAttributes({ value: "undOvr" })); + } +} diff --git a/src/file/paragraph/math/n-ary/math-naray-properties.spec.ts b/src/file/paragraph/math/n-ary/math-naray-properties.spec.ts new file mode 100644 index 0000000000..01ac55fb03 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-naray-properties.spec.ts @@ -0,0 +1,33 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathNArayProperties } from "./math-naray-properties"; + +describe("MathNArayProperties", () => { + describe("#constructor()", () => { + it("should create a MathNArayProperties with correct root key", () => { + const mathNArayProperties = new MathNArayProperties("∑"); + + const tree = new Formatter().format(mathNArayProperties); + expect(tree).to.deep.equal({ + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "∑", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-naray-properties.ts b/src/file/paragraph/math/n-ary/math-naray-properties.ts new file mode 100644 index 0000000000..4b28b58794 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-naray-properties.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_naryPr-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathAccentCharacter } from "./math-accent-character"; +import { MathLimitLocation } from "./math-limit-location"; + +export class MathNArayProperties extends XmlComponent { + constructor(readonly accent: string) { + super("m:naryPr"); + + this.root.push(new MathAccentCharacter(accent)); + this.root.push(new MathLimitLocation()); + } +} diff --git a/src/file/paragraph/math/n-ary/math-sub-script.spec.ts b/src/file/paragraph/math/n-ary/math-sub-script.spec.ts new file mode 100644 index 0000000000..d09908b192 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sub-script.spec.ts @@ -0,0 +1,27 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathSubScript } from "./math-sub-script"; + +describe("MathSubScript", () => { + describe("#constructor()", () => { + it("should create a MathSubScript with correct root key", () => { + const mathSubScript = new MathSubScript(new MathRun("2+2")); + + const tree = new Formatter().format(mathSubScript); + expect(tree).to.deep.equal({ + "m:sub": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-sub-script.ts b/src/file/paragraph/math/n-ary/math-sub-script.ts new file mode 100644 index 0000000000..25fe8da894 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sub-script.ts @@ -0,0 +1,12 @@ +// http://www.datypic.com/sc/ooxml/e-m_e-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathRun } from "../math-run"; + +export class MathSubScript extends XmlComponent { + constructor(readonly run: MathRun) { + super("m:sub"); + + this.root.push(run); + } +} diff --git a/src/file/paragraph/math/n-ary/math-sum.spec.ts b/src/file/paragraph/math/n-ary/math-sum.spec.ts new file mode 100644 index 0000000000..e168792b1f --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sum.spec.ts @@ -0,0 +1,75 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathSum } from "./math-sum"; + +describe("MathSum", () => { + describe("#constructor()", () => { + it("should create a MathSum with correct root key", () => { + const mathSum = new MathSum({ + child: new MathRun("1"), + subScript: new MathRun("2"), + superScript: new MathRun("3"), + }); + + const tree = new Formatter().format(mathSum); + expect(tree).to.deep.equal({ + "m:nary": [ + { + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "∑", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + ], + }, + { + "m:sub": [ + { + "m:r": [ + { + "m:t": ["1"], + }, + ], + }, + ], + }, + { + "m:sup": [ + { + "m:r": [ + { + "m:t": ["1"], + }, + ], + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["1"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-sum.ts b/src/file/paragraph/math/n-ary/math-sum.ts new file mode 100644 index 0000000000..2664b87fad --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sum.ts @@ -0,0 +1,25 @@ +// http://www.datypic.com/sc/ooxml/e-m_nary-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathRun } from "../math-run"; +import { MathBase } from "./math-base"; +import { MathNArayProperties } from "./math-naray-properties"; +import { MathSubScript } from "./math-sub-script"; +import { MathSuperScript } from "./math-super-script"; + +export interface IMathSumOptions { + readonly child: MathRun; + readonly subScript?: MathRun; + readonly superScript?: MathRun; +} + +export class MathSum extends XmlComponent { + constructor(readonly options: IMathSumOptions) { + super("m:nary"); + + this.root.push(new MathNArayProperties("∑")); + this.root.push(new MathSubScript(options.child)); + this.root.push(new MathSuperScript(options.child)); + this.root.push(new MathBase(options.child)); + } +} diff --git a/src/file/paragraph/math/n-ary/math-super-script.spec.ts b/src/file/paragraph/math/n-ary/math-super-script.spec.ts new file mode 100644 index 0000000000..7270276c28 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-super-script.spec.ts @@ -0,0 +1,27 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathSuperScript } from "./math-super-script"; + +describe("MathSuperScript", () => { + describe("#constructor()", () => { + it("should create a MathSuperScript with correct root key", () => { + const mathSuperScript = new MathSuperScript(new MathRun("2+2")); + + const tree = new Formatter().format(mathSuperScript); + expect(tree).to.deep.equal({ + "m:sup": [ + { + "m:r": [ + { + "m:t": ["2+2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-super-script.ts b/src/file/paragraph/math/n-ary/math-super-script.ts new file mode 100644 index 0000000000..8296c59f6a --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-super-script.ts @@ -0,0 +1,12 @@ +// http://www.datypic.com/sc/ooxml/e-m_e-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathRun } from "../math-run"; + +export class MathSuperScript extends XmlComponent { + constructor(readonly run: MathRun) { + super("m:sup"); + + this.root.push(run); + } +} From 700a74fd4ca689d39b6fd8d10c2aaa187c481d71 Mon Sep 17 00:00:00 2001 From: Dolan Date: Sat, 10 Oct 2020 13:41:26 +0100 Subject: [PATCH 3/8] More math components --- demo/47-math.ts | 44 --- demo/55-math.ts | 259 ++++++++++++++++++ package-lock.json | 37 +-- package.json | 2 +- src/file/drawing/inline/inline.ts | 2 +- src/file/paragraph/math/brackets/index.ts | 4 + .../brackets/math-angled-brackets.spec.ts | 51 ++++ .../math/brackets/math-angled-brackets.ts | 20 ++ .../brackets/math-beginning-character.spec.ts | 22 ++ .../math/brackets/math-beginning-character.ts | 14 + .../brackets/math-bracket-properties.spec.ts | 45 +++ .../math/brackets/math-bracket-properties.ts | 16 ++ .../math/brackets/math-curly-brackets.spec.ts | 51 ++++ .../math/brackets/math-curly-brackets.ts | 20 ++ .../math/brackets/math-ending-char.ts | 14 + .../brackets/math-ending-character.spec.ts | 22 ++ .../math/brackets/math-round-brackets.spec.ts | 36 +++ .../math/brackets/math-round-brackets.ts | 15 + .../brackets/math-square-brackets.spec.ts | 51 ++++ .../math/brackets/math-square-brackets.ts | 20 ++ .../math/fraction/math-denominator.ts | 2 +- .../paragraph/math/fraction/math-fraction.ts | 2 +- .../paragraph/math/fraction/math-numerator.ts | 2 +- src/file/paragraph/math/function/index.ts | 3 + .../math/function/math-function-name.spec.ts | 27 ++ .../math/function/math-function-name.ts | 11 + .../function/math-function-properties.spec.ts | 18 ++ .../math/function/math-function-properties.ts | 8 + .../math/function/math-function.spec.ts | 48 ++++ .../paragraph/math/function/math-function.ts | 22 ++ src/file/paragraph/math/index.ts | 5 + src/file/paragraph/math/math-component.ts | 21 ++ src/file/paragraph/math/math-run.ts | 2 +- src/file/paragraph/math/math-text.ts | 2 +- src/file/paragraph/math/math.ts | 8 +- .../math/n-ary/math-accent-character.ts | 2 +- src/file/paragraph/math/n-ary/math-base.ts | 4 +- .../math/n-ary/math-naray-properties.spec.ts | 102 ++++++- .../math/n-ary/math-naray-properties.ts | 12 +- .../math/n-ary/math-sub-script-hide.spec.ts | 22 ++ .../math/n-ary/math-sub-script-hide.ts | 14 + .../math/n-ary/math-sub-script.spec.ts | 10 +- .../paragraph/math/n-ary/math-sub-script.ts | 10 +- .../paragraph/math/n-ary/math-sum.spec.ts | 4 +- src/file/paragraph/math/n-ary/math-sum.ts | 27 +- .../math/n-ary/math-super-script-hide.spec.ts | 22 ++ .../math/n-ary/math-super-script-hide.ts | 14 + .../math/n-ary/math-super-script.spec.ts | 10 +- .../paragraph/math/n-ary/math-super-script.ts | 10 +- src/file/paragraph/math/radical/index.ts | 3 + .../math/radical/math-degree-hide.spec.ts | 22 ++ .../math/radical/math-degree-hide.ts | 14 + .../math/radical/math-degree.spec.ts | 36 +++ .../paragraph/math/radical/math-degree.ts | 13 + .../radical/math-radical-properties.spec.ts | 35 +++ .../math/radical/math-radical-properties.ts | 13 + .../math/radical/math-radical.spec.ts | 48 ++++ .../paragraph/math/radical/math-radical.ts | 22 ++ src/file/paragraph/math/script/index.ts | 4 + .../math/script/pre-sub-super-script/index.ts | 2 + ...b-super-script-function-properties.spec.ts | 17 ++ ...re-sub-super-script-function-properties.ts | 8 + ...math-pre-sub-super-script-function.spec.ts | 60 ++++ .../math-pre-sub-super-script-function.ts | 23 ++ .../paragraph/math/script/sub-script/index.ts | 2 + ...ath-sub-script-function-properties.spec.ts | 17 ++ .../math-sub-script-function-properties.ts | 8 + .../math-sub-script-function.spec.ts | 48 ++++ .../sub-script/math-sub-script-function.ts | 21 ++ .../math/script/sub-super-script/index.ts | 2 + ...b-super-script-function-properties.spec.ts | 17 ++ ...th-sub-super-script-function-properties.ts | 8 + .../math-sub-super-script-function.spec.ts | 60 ++++ .../math-sub-super-script-function.ts | 23 ++ .../math/script/super-script/index.ts | 2 + ...h-super-script-function-properties.spec.ts | 17 ++ .../math-super-script-function-properties.ts | 8 + .../math-super-script-function.spec.ts | 48 ++++ .../math-super-script-function.ts | 21 ++ src/file/paragraph/paragraph.ts | 4 +- src/file/settings/settings.ts | 6 +- .../deleted-text-run.spec.ts | 2 +- .../deleted-text-run.ts | 9 +- .../inserted-text-run.ts | 5 +- tslint.json | 2 + 85 files changed, 1716 insertions(+), 123 deletions(-) delete mode 100644 demo/47-math.ts create mode 100644 demo/55-math.ts create mode 100644 src/file/paragraph/math/brackets/index.ts create mode 100644 src/file/paragraph/math/brackets/math-angled-brackets.spec.ts create mode 100644 src/file/paragraph/math/brackets/math-angled-brackets.ts create mode 100644 src/file/paragraph/math/brackets/math-beginning-character.spec.ts create mode 100644 src/file/paragraph/math/brackets/math-beginning-character.ts create mode 100644 src/file/paragraph/math/brackets/math-bracket-properties.spec.ts create mode 100644 src/file/paragraph/math/brackets/math-bracket-properties.ts create mode 100644 src/file/paragraph/math/brackets/math-curly-brackets.spec.ts create mode 100644 src/file/paragraph/math/brackets/math-curly-brackets.ts create mode 100644 src/file/paragraph/math/brackets/math-ending-char.ts create mode 100644 src/file/paragraph/math/brackets/math-ending-character.spec.ts create mode 100644 src/file/paragraph/math/brackets/math-round-brackets.spec.ts create mode 100644 src/file/paragraph/math/brackets/math-round-brackets.ts create mode 100644 src/file/paragraph/math/brackets/math-square-brackets.spec.ts create mode 100644 src/file/paragraph/math/brackets/math-square-brackets.ts create mode 100644 src/file/paragraph/math/function/index.ts create mode 100644 src/file/paragraph/math/function/math-function-name.spec.ts create mode 100644 src/file/paragraph/math/function/math-function-name.ts create mode 100644 src/file/paragraph/math/function/math-function-properties.spec.ts create mode 100644 src/file/paragraph/math/function/math-function-properties.ts create mode 100644 src/file/paragraph/math/function/math-function.spec.ts create mode 100644 src/file/paragraph/math/function/math-function.ts create mode 100644 src/file/paragraph/math/math-component.ts create mode 100644 src/file/paragraph/math/n-ary/math-sub-script-hide.spec.ts create mode 100644 src/file/paragraph/math/n-ary/math-sub-script-hide.ts create mode 100644 src/file/paragraph/math/n-ary/math-super-script-hide.spec.ts create mode 100644 src/file/paragraph/math/n-ary/math-super-script-hide.ts create mode 100644 src/file/paragraph/math/radical/index.ts create mode 100644 src/file/paragraph/math/radical/math-degree-hide.spec.ts create mode 100644 src/file/paragraph/math/radical/math-degree-hide.ts create mode 100644 src/file/paragraph/math/radical/math-degree.spec.ts create mode 100644 src/file/paragraph/math/radical/math-degree.ts create mode 100644 src/file/paragraph/math/radical/math-radical-properties.spec.ts create mode 100644 src/file/paragraph/math/radical/math-radical-properties.ts create mode 100644 src/file/paragraph/math/radical/math-radical.spec.ts create mode 100644 src/file/paragraph/math/radical/math-radical.ts create mode 100644 src/file/paragraph/math/script/index.ts create mode 100644 src/file/paragraph/math/script/pre-sub-super-script/index.ts create mode 100644 src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.spec.ts create mode 100644 src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.ts create mode 100644 src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.spec.ts create mode 100644 src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts create mode 100644 src/file/paragraph/math/script/sub-script/index.ts create mode 100644 src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.spec.ts create mode 100644 src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.ts create mode 100644 src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts create mode 100644 src/file/paragraph/math/script/sub-script/math-sub-script-function.ts create mode 100644 src/file/paragraph/math/script/sub-super-script/index.ts create mode 100644 src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.spec.ts create mode 100644 src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.ts create mode 100644 src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts create mode 100644 src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts create mode 100644 src/file/paragraph/math/script/super-script/index.ts create mode 100644 src/file/paragraph/math/script/super-script/math-super-script-function-properties.spec.ts create mode 100644 src/file/paragraph/math/script/super-script/math-super-script-function-properties.ts create mode 100644 src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts create mode 100644 src/file/paragraph/math/script/super-script/math-super-script-function.ts diff --git a/demo/47-math.ts b/demo/47-math.ts deleted file mode 100644 index 5cad1707de..0000000000 --- a/demo/47-math.ts +++ /dev/null @@ -1,44 +0,0 @@ -// Simple example to add text to a document -// Import from 'docx' rather than '../build' if you install from npm -import * as fs from "fs"; -import { Document, Math, MathDenominator, MathFraction, MathNumerator, MathRun, MathSum, Packer, Paragraph, TextRun } from "../build"; - -const doc = new Document(); - -doc.addSection({ - properties: {}, - children: [ - new Paragraph({ - children: [ - new Math({ - children: [ - new MathRun("2+2"), - new MathFraction({ - numerator: new MathNumerator("hi"), - denominator: new MathDenominator("2"), - }), - ], - }), - new TextRun({ - text: "Foo Bar", - bold: true, - }), - ], - }), - new Paragraph({ - children: [ - new Math({ - children: [ - new MathSum({ - child: new MathRun("test"), - }), - ], - }), - ], - }), - ], -}); - -Packer.toBuffer(doc).then((buffer) => { - fs.writeFileSync("My Document.docx", buffer); -}); diff --git a/demo/55-math.ts b/demo/55-math.ts new file mode 100644 index 0000000000..92993a695a --- /dev/null +++ b/demo/55-math.ts @@ -0,0 +1,259 @@ +// Simple example to add text to a document +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { + Document, + Math, + MathAngledBrackets, + MathCurlyBrackets, + MathDenominator, + MathFraction, + MathFunction, + MathNumerator, + MathPreSubSuperScript, + MathRadical, + MathRoundBrackets, + MathRun, + MathSquareBrackets, + MathSubScript, + MathSubSuperScript, + MathSum, + MathSuperScript, + Packer, + Paragraph, + TextRun, +} from "../build"; + +const doc = new Document(); + +doc.addSection({ + properties: {}, + children: [ + new Paragraph({ + children: [ + new Math({ + children: [ + new MathRun("2+2"), + new MathFraction({ + numerator: new MathNumerator("hi"), + denominator: new MathDenominator("2"), + }), + ], + }), + new TextRun({ + text: "Foo Bar", + bold: true, + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSum({ + child: new MathRun("test"), + }), + new MathSum({ + child: new MathSuperScript({ + child: new MathRun("e"), + superScript: new MathRun("2"), + }), + subScript: new MathRun("i"), + }), + new MathSum({ + child: new MathRadical({ + child: new MathRun("i"), + }), + subScript: new MathRun("i"), + superScript: new MathRun("10"), + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSuperScript({ + child: new MathRun("test"), + superScript: new MathRun("hello"), + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubScript({ + child: new MathRun("test"), + subScript: new MathRun("hello"), + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubScript({ + child: new MathRun("x"), + subScript: new MathSuperScript({ + child: new MathRun("y"), + superScript: new MathRun("2"), + }), + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubSuperScript({ + child: new MathRun("test"), + superScript: new MathRun("hello"), + subScript: new MathRun("world"), + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathPreSubSuperScript({ + child: new MathRun("test"), + superScript: new MathRun("hello"), + subScript: new MathRun("world"), + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubScript({ + child: new MathFraction({ + numerator: new MathNumerator("1"), + denominator: new MathDenominator("2"), + }), + subScript: new MathRun("4"), + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubScript({ + child: new MathRadical({ + child: new MathFraction({ + numerator: new MathNumerator("1"), + denominator: new MathDenominator("2"), + }), + degree: new MathRun("4"), + }), + subScript: new MathRun("x"), + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathRadical({ + child: new MathRun("4"), + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathFunction({ + name: new MathSuperScript({ + child: new MathRun("cos"), + superScript: new MathRun("-1"), + }), + child: new MathRun("100"), + }), + new MathRun("×"), + new MathFunction({ + name: new MathRun("sin"), + child: new MathRun("360"), + }), + new MathRun("= x"), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathRoundBrackets({ + child: new MathFraction({ + numerator: new MathNumerator("1"), + denominator: new MathDenominator("2"), + }), + }), + new MathSquareBrackets({ + child: new MathFraction({ + numerator: new MathNumerator("1"), + denominator: new MathDenominator("2"), + }), + }), + new MathCurlyBrackets({ + child: new MathFraction({ + numerator: new MathNumerator("1"), + denominator: new MathDenominator("2"), + }), + }), + new MathAngledBrackets({ + child: new MathFraction({ + numerator: new MathNumerator("1"), + denominator: new MathDenominator("2"), + }), + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathFraction({ + numerator: new Math({ + children: [ + new MathRadical({ + child: new MathRun("4"), + }), + ], + }), + demoninator: new MathRun("2a"), + }), + ], + }), + ], + }), + ], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/package-lock.json b/package-lock.json index d73f9f5d71..7d28a68d7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1088,7 +1088,7 @@ }, "awesome-typescript-loader": { "version": "3.5.0", - "resolved": "http://registry.npmjs.org/awesome-typescript-loader/-/awesome-typescript-loader-3.5.0.tgz", + "resolved": "https://registry.npmjs.org/awesome-typescript-loader/-/awesome-typescript-loader-3.5.0.tgz", "integrity": "sha512-qzgm9SEvodVkSi9QY7Me1/rujg+YBNMjayNSAyzNghwTEez++gXoPCwMvpbHRG7wrOkDCiF6dquvv9ESmUBAuw==", "dev": true, "requires": { @@ -1665,7 +1665,7 @@ }, "chai": { "version": "3.5.0", - "resolved": "http://registry.npmjs.org/chai/-/chai-3.5.0.tgz", + "resolved": "https://registry.npmjs.org/chai/-/chai-3.5.0.tgz", "integrity": "sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc=", "dev": true, "requires": { @@ -2153,7 +2153,7 @@ }, "deep-eql": { "version": "0.1.3", - "resolved": "http://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", "integrity": "sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=", "dev": true, "requires": { @@ -4373,7 +4373,7 @@ "is-buffer": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", - "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", + "integrity": "sha1-76ouqdqg16suoTqXsritUf776L4=", "dev": true }, "is-ci": { @@ -4843,7 +4843,7 @@ }, "jsesc": { "version": "1.3.0", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", + "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", "integrity": "sha1-RsP+yMGJKxKwgz25vHYiF226s0s=", "dev": true }, @@ -5098,7 +5098,7 @@ }, "load-json-file": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", "dev": true, "requires": { @@ -5395,7 +5395,7 @@ "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=", "dev": true, "requires": { "brace-expansion": "^1.1.7" @@ -5585,7 +5585,7 @@ }, "ncp": { "version": "1.0.1", - "resolved": "http://registry.npmjs.org/ncp/-/ncp-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/ncp/-/ncp-1.0.1.tgz", "integrity": "sha1-0VNn5cuHQyuhF9K/gP30Wuz7QkY=", "dev": true }, @@ -5603,7 +5603,7 @@ }, "next-tick": { "version": "1.0.0", - "resolved": "http://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=", "dev": true }, @@ -7116,7 +7116,7 @@ }, "safe-regex": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", "dev": true, "requires": { @@ -7719,7 +7719,7 @@ }, "strip-eof": { "version": "1.0.0", - "resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "dev": true }, @@ -7996,10 +7996,13 @@ } }, "tslint-immutable": { - "version": "4.9.1", - "resolved": "https://registry.npmjs.org/tslint-immutable/-/tslint-immutable-4.9.1.tgz", - "integrity": "sha512-iIFCq08H4YyNIX0bV5N6fGQtAmjc4OQZKQCgBP5WHgQaITyGAHPVmAw+Yf7qe0zbRCvCDZdrdEC/191fLGFiww==", - "dev": true + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/tslint-immutable/-/tslint-immutable-6.0.1.tgz", + "integrity": "sha512-3GQ6HffN64gLmT/N1YzyVMqyf6uBjMvhNaevK8B0K01/QC0OU5AQZrH4TjMHo1IdG3JpqsZvuRy9IW1LA3zjwA==", + "dev": true, + "requires": { + "tsutils": "^2.28.0 || ^3.0.0" + } }, "tsutils": { "version": "2.29.0", @@ -8654,7 +8657,7 @@ }, "load-json-file": { "version": "2.0.0", - "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", "integrity": "sha1-eUfkIUmvgNaWy/eXvKq8/h/inKg=", "dev": true, "requires": { @@ -8855,7 +8858,7 @@ }, "winston": { "version": "2.1.1", - "resolved": "http://registry.npmjs.org/winston/-/winston-2.1.1.tgz", + "resolved": "https://registry.npmjs.org/winston/-/winston-2.1.1.tgz", "integrity": "sha1-PJNJ0ZYgf9G9/51LxD73JRDjoS4=", "dev": true, "requires": { diff --git a/package.json b/package.json index 51e1b246c3..f9a27f0fcb 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "sinon": "^9.0.2", "ts-node": "^9.0.0", "tslint": "^6.1.3", - "tslint-immutable": "^4.9.0", + "tslint-immutable": "^6.0.1", "typedoc": "^0.16.11", "typescript": "2.9.2", "webpack": "^3.10.0" diff --git a/src/file/drawing/inline/inline.ts b/src/file/drawing/inline/inline.ts index 7c40e7c3b3..bf83e36764 100644 --- a/src/file/drawing/inline/inline.ts +++ b/src/file/drawing/inline/inline.ts @@ -12,7 +12,7 @@ export class Inline extends XmlComponent { private readonly extent: Extent; private readonly graphic: Graphic; - constructor(readonly mediaData: IMediaData, private readonly dimensions: IMediaDataDimensions) { + constructor(mediaData: IMediaData, private readonly dimensions: IMediaDataDimensions) { super("wp:inline"); this.root.push( diff --git a/src/file/paragraph/math/brackets/index.ts b/src/file/paragraph/math/brackets/index.ts new file mode 100644 index 0000000000..e6559cde29 --- /dev/null +++ b/src/file/paragraph/math/brackets/index.ts @@ -0,0 +1,4 @@ +export * from "./math-round-brackets"; +export * from "./math-square-brackets"; +export * from "./math-curly-brackets"; +export * from "./math-angled-brackets"; diff --git a/src/file/paragraph/math/brackets/math-angled-brackets.spec.ts b/src/file/paragraph/math/brackets/math-angled-brackets.spec.ts new file mode 100644 index 0000000000..735e0da272 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-angled-brackets.spec.ts @@ -0,0 +1,51 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathAngledBrackets } from "./math-angled-brackets"; + +describe("MathAngledBrackets", () => { + describe("#constructor()", () => { + it("should create a MathAngledBrackets with correct root key", () => { + const mathAngledBrackets = new MathAngledBrackets({ + child: new MathRun("60"), + }); + + const tree = new Formatter().format(mathAngledBrackets); + expect(tree).to.deep.equal({ + "m:d": [ + { + "m:dPr": [ + { + "m:begChr": { + _attr: { + "m:val": "〈", + }, + }, + }, + { + "m:endChr": { + _attr: { + "m:val": "〉", + }, + }, + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["60"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-angled-brackets.ts b/src/file/paragraph/math/brackets/math-angled-brackets.ts new file mode 100644 index 0000000000..fbafb7e738 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-angled-brackets.ts @@ -0,0 +1,20 @@ +// http://www.datypic.com/sc/ooxml/e-m_d-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathBracketProperties } from "./math-bracket-properties"; + +export class MathAngledBrackets extends XmlComponent { + constructor(options: { readonly child: MathComponent }) { + super("m:d"); + + this.root.push( + new MathBracketProperties({ + beginningCharacter: "〈", + endingCharacter: "〉", + }), + ); + this.root.push(new MathBase(options.child)); + } +} diff --git a/src/file/paragraph/math/brackets/math-beginning-character.spec.ts b/src/file/paragraph/math/brackets/math-beginning-character.spec.ts new file mode 100644 index 0000000000..bf9196c0a9 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-beginning-character.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathBeginningCharacter } from "./math-beginning-character"; + +describe("MathBeginningCharacter", () => { + describe("#constructor()", () => { + it("should create a MathBeginningCharacter with correct root key", () => { + const mathBeginningCharacter = new MathBeginningCharacter("["); + + const tree = new Formatter().format(mathBeginningCharacter); + expect(tree).to.deep.equal({ + "m:begChr": { + _attr: { + "m:val": "[", + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-beginning-character.ts b/src/file/paragraph/math/brackets/math-beginning-character.ts new file mode 100644 index 0000000000..aa9e06d87a --- /dev/null +++ b/src/file/paragraph/math/brackets/math-beginning-character.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_begChr-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathBeginningCharacterAttributes extends XmlAttributeComponent<{ readonly character: string }> { + protected readonly xmlKeys = { character: "m:val" }; +} + +export class MathBeginningCharacter extends XmlComponent { + constructor(character: string) { + super("m:begChr"); + + this.root.push(new MathBeginningCharacterAttributes({ character })); + } +} diff --git a/src/file/paragraph/math/brackets/math-bracket-properties.spec.ts b/src/file/paragraph/math/brackets/math-bracket-properties.spec.ts new file mode 100644 index 0000000000..d80976d8f6 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-bracket-properties.spec.ts @@ -0,0 +1,45 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathBracketProperties } from "./math-bracket-properties"; + +describe("MathBracketProperties", () => { + describe("#constructor()", () => { + it("should create a MathBracketProperties with correct root key", () => { + const mathBracketProperties = new MathBracketProperties(); + + const tree = new Formatter().format(mathBracketProperties); + expect(tree).to.deep.equal({ + "m:dPr": {}, + }); + }); + + it("should create a MathBracketProperties with correct root key and add brackets", () => { + const mathBracketProperties = new MathBracketProperties({ + beginningCharacter: "[", + endingCharacter: "]", + }); + + const tree = new Formatter().format(mathBracketProperties); + expect(tree).to.deep.equal({ + "m:dPr": [ + { + "m:begChr": { + _attr: { + "m:val": "[", + }, + }, + }, + { + "m:endChr": { + _attr: { + "m:val": "]", + }, + }, + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-bracket-properties.ts b/src/file/paragraph/math/brackets/math-bracket-properties.ts new file mode 100644 index 0000000000..5bba7bf935 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-bracket-properties.ts @@ -0,0 +1,16 @@ +// http://www.datypic.com/sc/ooxml/e-m_dPr-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathBeginningCharacter } from "./math-beginning-character"; +import { MathEndingCharacter } from "./math-ending-char"; + +export class MathBracketProperties extends XmlComponent { + constructor(options?: { readonly beginningCharacter: string; readonly endingCharacter: string }) { + super("m:dPr"); + + if (!!options) { + this.root.push(new MathBeginningCharacter(options.beginningCharacter)); + this.root.push(new MathEndingCharacter(options.endingCharacter)); + } + } +} diff --git a/src/file/paragraph/math/brackets/math-curly-brackets.spec.ts b/src/file/paragraph/math/brackets/math-curly-brackets.spec.ts new file mode 100644 index 0000000000..6e44621b21 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-curly-brackets.spec.ts @@ -0,0 +1,51 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathCurlyBrackets } from "./math-curly-brackets"; + +describe("MathCurlyBrackets", () => { + describe("#constructor()", () => { + it("should create a MathCurlyBrackets with correct root key", () => { + const mathCurlyBrackets = new MathCurlyBrackets({ + child: new MathRun("60"), + }); + + const tree = new Formatter().format(mathCurlyBrackets); + expect(tree).to.deep.equal({ + "m:d": [ + { + "m:dPr": [ + { + "m:begChr": { + _attr: { + "m:val": "{", + }, + }, + }, + { + "m:endChr": { + _attr: { + "m:val": "}", + }, + }, + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["60"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-curly-brackets.ts b/src/file/paragraph/math/brackets/math-curly-brackets.ts new file mode 100644 index 0000000000..4d540ec8bc --- /dev/null +++ b/src/file/paragraph/math/brackets/math-curly-brackets.ts @@ -0,0 +1,20 @@ +// http://www.datypic.com/sc/ooxml/e-m_d-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathBracketProperties } from "./math-bracket-properties"; + +export class MathCurlyBrackets extends XmlComponent { + constructor(options: { readonly child: MathComponent }) { + super("m:d"); + + this.root.push( + new MathBracketProperties({ + beginningCharacter: "{", + endingCharacter: "}", + }), + ); + this.root.push(new MathBase(options.child)); + } +} diff --git a/src/file/paragraph/math/brackets/math-ending-char.ts b/src/file/paragraph/math/brackets/math-ending-char.ts new file mode 100644 index 0000000000..86d0a0a58c --- /dev/null +++ b/src/file/paragraph/math/brackets/math-ending-char.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_endChr-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathEndingCharacterAttributes extends XmlAttributeComponent<{ readonly character: string }> { + protected readonly xmlKeys = { character: "m:val" }; +} + +export class MathEndingCharacter extends XmlComponent { + constructor(character: string) { + super("m:endChr"); + + this.root.push(new MathEndingCharacterAttributes({ character })); + } +} diff --git a/src/file/paragraph/math/brackets/math-ending-character.spec.ts b/src/file/paragraph/math/brackets/math-ending-character.spec.ts new file mode 100644 index 0000000000..ba28ac7840 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-ending-character.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathEndingCharacter } from "./math-ending-char"; + +describe("MathEndingCharacter", () => { + describe("#constructor()", () => { + it("should create a MathEndingCharacter with correct root key", () => { + const mathEndingCharacter = new MathEndingCharacter("]"); + + const tree = new Formatter().format(mathEndingCharacter); + expect(tree).to.deep.equal({ + "m:endChr": { + _attr: { + "m:val": "]", + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-round-brackets.spec.ts b/src/file/paragraph/math/brackets/math-round-brackets.spec.ts new file mode 100644 index 0000000000..cb28126a20 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-round-brackets.spec.ts @@ -0,0 +1,36 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathRoundBrackets } from "./math-round-brackets"; + +describe("MathRoundBrackets", () => { + describe("#constructor()", () => { + it("should create a MathRoundBrackets with correct root key", () => { + const mathRoundBrackets = new MathRoundBrackets({ + child: new MathRun("60"), + }); + + const tree = new Formatter().format(mathRoundBrackets); + expect(tree).to.deep.equal({ + "m:d": [ + { + "m:dPr": {}, + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["60"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-round-brackets.ts b/src/file/paragraph/math/brackets/math-round-brackets.ts new file mode 100644 index 0000000000..2302fa30f1 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-round-brackets.ts @@ -0,0 +1,15 @@ +// http://www.datypic.com/sc/ooxml/e-m_d-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathBracketProperties } from "./math-bracket-properties"; + +export class MathRoundBrackets extends XmlComponent { + constructor(options: { readonly child: MathComponent }) { + super("m:d"); + + this.root.push(new MathBracketProperties()); + this.root.push(new MathBase(options.child)); + } +} diff --git a/src/file/paragraph/math/brackets/math-square-brackets.spec.ts b/src/file/paragraph/math/brackets/math-square-brackets.spec.ts new file mode 100644 index 0000000000..03b8aef03d --- /dev/null +++ b/src/file/paragraph/math/brackets/math-square-brackets.spec.ts @@ -0,0 +1,51 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathSquareBrackets } from "./math-square-brackets"; + +describe("MathSquareBrackets", () => { + describe("#constructor()", () => { + it("should create a MathSquareBrackets with correct root key", () => { + const mathSquareBrackets = new MathSquareBrackets({ + child: new MathRun("60"), + }); + + const tree = new Formatter().format(mathSquareBrackets); + expect(tree).to.deep.equal({ + "m:d": [ + { + "m:dPr": [ + { + "m:begChr": { + _attr: { + "m:val": "[", + }, + }, + }, + { + "m:endChr": { + _attr: { + "m:val": "]", + }, + }, + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["60"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/brackets/math-square-brackets.ts b/src/file/paragraph/math/brackets/math-square-brackets.ts new file mode 100644 index 0000000000..3c3d385357 --- /dev/null +++ b/src/file/paragraph/math/brackets/math-square-brackets.ts @@ -0,0 +1,20 @@ +// http://www.datypic.com/sc/ooxml/e-m_d-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathBracketProperties } from "./math-bracket-properties"; + +export class MathSquareBrackets extends XmlComponent { + constructor(options: { readonly child: MathComponent }) { + super("m:d"); + + this.root.push( + new MathBracketProperties({ + beginningCharacter: "[", + endingCharacter: "]", + }), + ); + this.root.push(new MathBase(options.child)); + } +} diff --git a/src/file/paragraph/math/fraction/math-denominator.ts b/src/file/paragraph/math/fraction/math-denominator.ts index da9f283bdc..f640324c2e 100644 --- a/src/file/paragraph/math/fraction/math-denominator.ts +++ b/src/file/paragraph/math/fraction/math-denominator.ts @@ -3,7 +3,7 @@ import { XmlComponent } from "file/xml-components"; import { MathRun } from "../math-run"; export class MathDenominator extends XmlComponent { - constructor(readonly text: string) { + constructor(text: string) { super("m:den"); this.root.push(new MathRun(text)); diff --git a/src/file/paragraph/math/fraction/math-fraction.ts b/src/file/paragraph/math/fraction/math-fraction.ts index 062c3ef575..574a989bba 100644 --- a/src/file/paragraph/math/fraction/math-fraction.ts +++ b/src/file/paragraph/math/fraction/math-fraction.ts @@ -9,7 +9,7 @@ export interface IMathFractionOptions { } export class MathFraction extends XmlComponent { - constructor(readonly options: IMathFractionOptions) { + constructor(options: IMathFractionOptions) { super("m:f"); this.root.push(options.numerator); diff --git a/src/file/paragraph/math/fraction/math-numerator.ts b/src/file/paragraph/math/fraction/math-numerator.ts index 68799328cb..f7e68715b8 100644 --- a/src/file/paragraph/math/fraction/math-numerator.ts +++ b/src/file/paragraph/math/fraction/math-numerator.ts @@ -3,7 +3,7 @@ import { XmlComponent } from "file/xml-components"; import { MathRun } from "../math-run"; export class MathNumerator extends XmlComponent { - constructor(readonly text: string) { + constructor(text: string) { super("m:num"); this.root.push(new MathRun(text)); diff --git a/src/file/paragraph/math/function/index.ts b/src/file/paragraph/math/function/index.ts new file mode 100644 index 0000000000..58243c2710 --- /dev/null +++ b/src/file/paragraph/math/function/index.ts @@ -0,0 +1,3 @@ +export * from "./math-function"; +export * from "./math-function-name"; +export * from "./math-function-properties"; diff --git a/src/file/paragraph/math/function/math-function-name.spec.ts b/src/file/paragraph/math/function/math-function-name.spec.ts new file mode 100644 index 0000000000..bdb38d7596 --- /dev/null +++ b/src/file/paragraph/math/function/math-function-name.spec.ts @@ -0,0 +1,27 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathFunctionName } from "./math-function-name"; + +describe("MathFunctionName", () => { + describe("#constructor()", () => { + it("should create a MathFunctionName with correct root key", () => { + const mathFunctionName = new MathFunctionName(new MathRun("2")); + + const tree = new Formatter().format(mathFunctionName); + expect(tree).to.deep.equal({ + "m:fName": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/function/math-function-name.ts b/src/file/paragraph/math/function/math-function-name.ts new file mode 100644 index 0000000000..011e82133a --- /dev/null +++ b/src/file/paragraph/math/function/math-function-name.ts @@ -0,0 +1,11 @@ +// http://www.datypic.com/sc/ooxml/e-m_fName-1.html +import { XmlComponent } from "file/xml-components"; +import { MathComponent } from "../math-component"; + +export class MathFunctionName extends XmlComponent { + constructor(child: MathComponent) { + super("m:fName"); + + this.root.push(child); + } +} diff --git a/src/file/paragraph/math/function/math-function-properties.spec.ts b/src/file/paragraph/math/function/math-function-properties.spec.ts new file mode 100644 index 0000000000..63ec2e4f60 --- /dev/null +++ b/src/file/paragraph/math/function/math-function-properties.spec.ts @@ -0,0 +1,18 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathFunctionProperties } from "./math-function-properties"; + +describe("MathFunctionProperties", () => { + describe("#constructor()", () => { + it("should create a MathFunctionProperties with correct root key", () => { + const mathFunctionProperties = new MathFunctionProperties(); + + const tree = new Formatter().format(mathFunctionProperties); + expect(tree).to.deep.equal({ + "m:funcPr": {}, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/function/math-function-properties.ts b/src/file/paragraph/math/function/math-function-properties.ts new file mode 100644 index 0000000000..f6e8d608ac --- /dev/null +++ b/src/file/paragraph/math/function/math-function-properties.ts @@ -0,0 +1,8 @@ +// http://www.datypic.com/sc/ooxml/e-m_radPr-1.html +import { XmlComponent } from "file/xml-components"; + +export class MathFunctionProperties extends XmlComponent { + constructor() { + super("m:funcPr"); + } +} diff --git a/src/file/paragraph/math/function/math-function.spec.ts b/src/file/paragraph/math/function/math-function.spec.ts new file mode 100644 index 0000000000..4320a853c6 --- /dev/null +++ b/src/file/paragraph/math/function/math-function.spec.ts @@ -0,0 +1,48 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathFunction } from "./math-function"; + +describe("MathFunction", () => { + describe("#constructor()", () => { + it("should create a MathFunction with correct root key", () => { + const mathFunction = new MathFunction({ + name: new MathRun("sin"), + child: new MathRun("60"), + }); + + const tree = new Formatter().format(mathFunction); + expect(tree).to.deep.equal({ + "m:func": [ + { + "m:funcPr": {}, + }, + { + "m:fName": [ + { + "m:r": [ + { + "m:t": ["sin"], + }, + ], + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["60"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/function/math-function.ts b/src/file/paragraph/math/function/math-function.ts new file mode 100644 index 0000000000..b3de75ddb8 --- /dev/null +++ b/src/file/paragraph/math/function/math-function.ts @@ -0,0 +1,22 @@ +// http://www.datypic.com/sc/ooxml/e-m_func-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathFunctionName } from "./math-function-name"; +import { MathFunctionProperties } from "./math-function-properties"; + +export interface IMathFunctionOptions { + readonly child: MathComponent; + readonly name: MathComponent; +} + +export class MathFunction extends XmlComponent { + constructor(options: IMathFunctionOptions) { + super("m:func"); + + this.root.push(new MathFunctionProperties()); + this.root.push(new MathFunctionName(options.name)); + this.root.push(new MathBase(options.child)); + } +} diff --git a/src/file/paragraph/math/index.ts b/src/file/paragraph/math/index.ts index 063678689c..b42ec908f6 100644 --- a/src/file/paragraph/math/index.ts +++ b/src/file/paragraph/math/index.ts @@ -2,3 +2,8 @@ export * from "./math"; export * from "./math-run"; export * from "./fraction"; export * from "./n-ary"; +export * from "./script"; +export * from "./math-component"; +export * from "./radical"; +export * from "./function"; +export * from "./brackets"; diff --git a/src/file/paragraph/math/math-component.ts b/src/file/paragraph/math/math-component.ts new file mode 100644 index 0000000000..afe83235f4 --- /dev/null +++ b/src/file/paragraph/math/math-component.ts @@ -0,0 +1,21 @@ +import { MathAngledBrackets, MathCurlyBrackets, MathRoundBrackets, MathSquareBrackets } from "./brackets"; +import { MathFraction } from "./fraction"; +import { MathFunction } from "./function"; +import { MathRun } from "./math-run"; +import { MathSum } from "./n-ary"; +import { MathRadical } from "./radical"; +import { MathSubScript, MathSubSuperScript, MathSuperScript } from "./script"; + +export type MathComponent = + | MathRun + | MathFraction + | MathSum + | MathSuperScript + | MathSubScript + | MathSubSuperScript + | MathRadical + | MathFunction + | MathRoundBrackets + | MathCurlyBrackets + | MathAngledBrackets + | MathSquareBrackets; diff --git a/src/file/paragraph/math/math-run.ts b/src/file/paragraph/math/math-run.ts index 3b7cceb362..0d2c48910f 100644 --- a/src/file/paragraph/math/math-run.ts +++ b/src/file/paragraph/math/math-run.ts @@ -4,7 +4,7 @@ import { XmlComponent } from "file/xml-components"; import { MathText } from "./math-text"; export class MathRun extends XmlComponent { - constructor(readonly text: string) { + constructor(text: string) { super("m:r"); this.root.push(new MathText(text)); diff --git a/src/file/paragraph/math/math-text.ts b/src/file/paragraph/math/math-text.ts index 907294aab9..6087c7e611 100644 --- a/src/file/paragraph/math/math-text.ts +++ b/src/file/paragraph/math/math-text.ts @@ -1,7 +1,7 @@ import { XmlComponent } from "file/xml-components"; export class MathText extends XmlComponent { - constructor(readonly text: string) { + constructor(text: string) { super("m:t"); this.root.push(text); diff --git a/src/file/paragraph/math/math.ts b/src/file/paragraph/math/math.ts index 43272ed941..69ebae4dff 100644 --- a/src/file/paragraph/math/math.ts +++ b/src/file/paragraph/math/math.ts @@ -1,16 +1,14 @@ // http://www.datypic.com/sc/ooxml/e-m_oMath-1.html import { XmlComponent } from "file/xml-components"; -import { MathFraction } from "./fraction"; -import { MathRun } from "./math-run"; -import { MathSum } from "./n-ary"; +import { MathComponent } from "./math-component"; export interface IMathOptions { - readonly children: Array; + readonly children: MathComponent[]; } export class Math extends XmlComponent { - constructor(readonly options: IMathOptions) { + constructor(options: IMathOptions) { super("m:oMath"); for (const child of options.children) { diff --git a/src/file/paragraph/math/n-ary/math-accent-character.ts b/src/file/paragraph/math/n-ary/math-accent-character.ts index 3a5a10d7d2..00182bd1f2 100644 --- a/src/file/paragraph/math/n-ary/math-accent-character.ts +++ b/src/file/paragraph/math/n-ary/math-accent-character.ts @@ -6,7 +6,7 @@ class MathAccentCharacterAttributes extends XmlAttributeComponent<{ readonly acc } export class MathAccentCharacter extends XmlComponent { - constructor(readonly accent: string) { + constructor(accent: string) { super("m:chr"); this.root.push(new MathAccentCharacterAttributes({ accent })); diff --git a/src/file/paragraph/math/n-ary/math-base.ts b/src/file/paragraph/math/n-ary/math-base.ts index e75231cdb2..7c06a67c23 100644 --- a/src/file/paragraph/math/n-ary/math-base.ts +++ b/src/file/paragraph/math/n-ary/math-base.ts @@ -1,10 +1,10 @@ // http://www.datypic.com/sc/ooxml/e-m_e-1.html import { XmlComponent } from "file/xml-components"; -import { MathRun } from "../math-run"; +import { MathComponent } from "../math-component"; export class MathBase extends XmlComponent { - constructor(readonly run: MathRun) { + constructor(run: MathComponent) { super("m:e"); this.root.push(run); diff --git a/src/file/paragraph/math/n-ary/math-naray-properties.spec.ts b/src/file/paragraph/math/n-ary/math-naray-properties.spec.ts index 01ac55fb03..70aa74a1c4 100644 --- a/src/file/paragraph/math/n-ary/math-naray-properties.spec.ts +++ b/src/file/paragraph/math/n-ary/math-naray-properties.spec.ts @@ -7,7 +7,7 @@ import { MathNArayProperties } from "./math-naray-properties"; describe("MathNArayProperties", () => { describe("#constructor()", () => { it("should create a MathNArayProperties with correct root key", () => { - const mathNArayProperties = new MathNArayProperties("∑"); + const mathNArayProperties = new MathNArayProperties("∑", true, true); const tree = new Formatter().format(mathNArayProperties); expect(tree).to.deep.equal({ @@ -29,5 +29,105 @@ describe("MathNArayProperties", () => { ], }); }); + + it("should add super-script hide attributes", () => { + const mathNArayProperties = new MathNArayProperties("∑", false, true); + + const tree = new Formatter().format(mathNArayProperties); + expect(tree).to.deep.equal({ + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "∑", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + { + "m:supHide": { + _attr: { + "m:val": 1, + }, + }, + }, + ], + }); + }); + + it("should add sub-script hide attributes", () => { + const mathNArayProperties = new MathNArayProperties("∑", true, false); + + const tree = new Formatter().format(mathNArayProperties); + expect(tree).to.deep.equal({ + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "∑", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + { + "m:subHide": { + _attr: { + "m:val": 1, + }, + }, + }, + ], + }); + }); + + it("should add both super-script and sub-script hide attributes", () => { + const mathNArayProperties = new MathNArayProperties("∑", false, false); + + const tree = new Formatter().format(mathNArayProperties); + expect(tree).to.deep.equal({ + "m:naryPr": [ + { + "m:chr": { + _attr: { + "m:val": "∑", + }, + }, + }, + { + "m:limLoc": { + _attr: { + "m:val": "undOvr", + }, + }, + }, + { + "m:supHide": { + _attr: { + "m:val": 1, + }, + }, + }, + { + "m:subHide": { + _attr: { + "m:val": 1, + }, + }, + }, + ], + }); + }); }); }); diff --git a/src/file/paragraph/math/n-ary/math-naray-properties.ts b/src/file/paragraph/math/n-ary/math-naray-properties.ts index 4b28b58794..f8e91e746a 100644 --- a/src/file/paragraph/math/n-ary/math-naray-properties.ts +++ b/src/file/paragraph/math/n-ary/math-naray-properties.ts @@ -3,12 +3,22 @@ import { 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"; export class MathNArayProperties extends XmlComponent { - constructor(readonly accent: string) { + constructor(accent: string, hasSuperScript: boolean, hasSubScript: boolean) { super("m:naryPr"); this.root.push(new MathAccentCharacter(accent)); this.root.push(new MathLimitLocation()); + + if (!hasSuperScript) { + this.root.push(new MathSuperScriptHide()); + } + + if (!hasSubScript) { + this.root.push(new MathSubScriptHide()); + } } } diff --git a/src/file/paragraph/math/n-ary/math-sub-script-hide.spec.ts b/src/file/paragraph/math/n-ary/math-sub-script-hide.spec.ts new file mode 100644 index 0000000000..2e9845172f --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sub-script-hide.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathSubScriptHide } from "./math-sub-script-hide"; + +describe("MathSubScriptHide", () => { + describe("#constructor()", () => { + it("should create a MathSubScriptHide with correct root key", () => { + const mathSubScriptHide = new MathSubScriptHide(); + + const tree = new Formatter().format(mathSubScriptHide); + expect(tree).to.deep.equal({ + "m:subHide": { + _attr: { + "m:val": 1, + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-sub-script-hide.ts b/src/file/paragraph/math/n-ary/math-sub-script-hide.ts new file mode 100644 index 0000000000..ef735744e0 --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-sub-script-hide.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_subHide-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathSubScriptHideAttributes extends XmlAttributeComponent<{ readonly hide: number }> { + protected readonly xmlKeys = { hide: "m:val" }; +} + +export class MathSubScriptHide extends XmlComponent { + constructor() { + super("m:subHide"); + + this.root.push(new MathSubScriptHideAttributes({ hide: 1 })); + } +} diff --git a/src/file/paragraph/math/n-ary/math-sub-script.spec.ts b/src/file/paragraph/math/n-ary/math-sub-script.spec.ts index d09908b192..5a4009811e 100644 --- a/src/file/paragraph/math/n-ary/math-sub-script.spec.ts +++ b/src/file/paragraph/math/n-ary/math-sub-script.spec.ts @@ -3,14 +3,14 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; import { MathRun } from "../math-run"; -import { MathSubScript } from "./math-sub-script"; +import { MathSubScriptElement } from "./math-sub-script"; -describe("MathSubScript", () => { +describe("MathSubScriptElement", () => { describe("#constructor()", () => { - it("should create a MathSubScript with correct root key", () => { - const mathSubScript = new MathSubScript(new MathRun("2+2")); + it("should create a MathSubScriptElement with correct root key", () => { + const mathSubScriptElement = new MathSubScriptElement(new MathRun("2+2")); - const tree = new Formatter().format(mathSubScript); + const tree = new Formatter().format(mathSubScriptElement); expect(tree).to.deep.equal({ "m:sub": [ { diff --git a/src/file/paragraph/math/n-ary/math-sub-script.ts b/src/file/paragraph/math/n-ary/math-sub-script.ts index 25fe8da894..aaa8530e74 100644 --- a/src/file/paragraph/math/n-ary/math-sub-script.ts +++ b/src/file/paragraph/math/n-ary/math-sub-script.ts @@ -1,12 +1,12 @@ -// http://www.datypic.com/sc/ooxml/e-m_e-1.html +// http://www.datypic.com/sc/ooxml/e-m_sub-3.html import { XmlComponent } from "file/xml-components"; -import { MathRun } from "../math-run"; +import { MathComponent } from "../math-component"; -export class MathSubScript extends XmlComponent { - constructor(readonly run: MathRun) { +export class MathSubScriptElement extends XmlComponent { + constructor(child: MathComponent) { super("m:sub"); - this.root.push(run); + this.root.push(child); } } diff --git a/src/file/paragraph/math/n-ary/math-sum.spec.ts b/src/file/paragraph/math/n-ary/math-sum.spec.ts index e168792b1f..9f0d213aa4 100644 --- a/src/file/paragraph/math/n-ary/math-sum.spec.ts +++ b/src/file/paragraph/math/n-ary/math-sum.spec.ts @@ -40,7 +40,7 @@ describe("MathSum", () => { { "m:r": [ { - "m:t": ["1"], + "m:t": ["2"], }, ], }, @@ -51,7 +51,7 @@ describe("MathSum", () => { { "m:r": [ { - "m:t": ["1"], + "m:t": ["3"], }, ], }, diff --git a/src/file/paragraph/math/n-ary/math-sum.ts b/src/file/paragraph/math/n-ary/math-sum.ts index 2664b87fad..a16603982d 100644 --- a/src/file/paragraph/math/n-ary/math-sum.ts +++ b/src/file/paragraph/math/n-ary/math-sum.ts @@ -1,25 +1,32 @@ // http://www.datypic.com/sc/ooxml/e-m_nary-1.html import { XmlComponent } from "file/xml-components"; -import { MathRun } from "../math-run"; +import { MathComponent } from "../math-component"; import { MathBase } from "./math-base"; import { MathNArayProperties } from "./math-naray-properties"; -import { MathSubScript } from "./math-sub-script"; -import { MathSuperScript } from "./math-super-script"; +import { MathSubScriptElement } from "./math-sub-script"; +import { MathSuperScriptElement } from "./math-super-script"; export interface IMathSumOptions { - readonly child: MathRun; - readonly subScript?: MathRun; - readonly superScript?: MathRun; + readonly child: MathComponent; + readonly subScript?: MathComponent; + readonly superScript?: MathComponent; } export class MathSum extends XmlComponent { - constructor(readonly options: IMathSumOptions) { + constructor(options: IMathSumOptions) { super("m:nary"); - this.root.push(new MathNArayProperties("∑")); - this.root.push(new MathSubScript(options.child)); - this.root.push(new MathSuperScript(options.child)); + this.root.push(new MathNArayProperties("∑", !!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.child)); } } diff --git a/src/file/paragraph/math/n-ary/math-super-script-hide.spec.ts b/src/file/paragraph/math/n-ary/math-super-script-hide.spec.ts new file mode 100644 index 0000000000..89a28564ac --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-super-script-hide.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathSuperScriptHide } from "./math-super-script-hide"; + +describe("MathSuperScriptHide", () => { + describe("#constructor()", () => { + it("should create a MathSuperScriptHide with correct root key", () => { + const mathSuperScriptHide = new MathSuperScriptHide(); + + const tree = new Formatter().format(mathSuperScriptHide); + expect(tree).to.deep.equal({ + "m:supHide": { + _attr: { + "m:val": 1, + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/n-ary/math-super-script-hide.ts b/src/file/paragraph/math/n-ary/math-super-script-hide.ts new file mode 100644 index 0000000000..a55c15a7ad --- /dev/null +++ b/src/file/paragraph/math/n-ary/math-super-script-hide.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_subHide-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathSuperScriptHideAttributes extends XmlAttributeComponent<{ readonly hide: number }> { + protected readonly xmlKeys = { hide: "m:val" }; +} + +export class MathSuperScriptHide extends XmlComponent { + constructor() { + super("m:supHide"); + + this.root.push(new MathSuperScriptHideAttributes({ hide: 1 })); + } +} diff --git a/src/file/paragraph/math/n-ary/math-super-script.spec.ts b/src/file/paragraph/math/n-ary/math-super-script.spec.ts index 7270276c28..85a5195c0f 100644 --- a/src/file/paragraph/math/n-ary/math-super-script.spec.ts +++ b/src/file/paragraph/math/n-ary/math-super-script.spec.ts @@ -3,14 +3,14 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; import { MathRun } from "../math-run"; -import { MathSuperScript } from "./math-super-script"; +import { MathSuperScriptElement } from "./math-super-script"; -describe("MathSuperScript", () => { +describe("MathSuperScriptElement", () => { describe("#constructor()", () => { - it("should create a MathSuperScript with correct root key", () => { - const mathSuperScript = new MathSuperScript(new MathRun("2+2")); + it("should create a MathSuperScriptElement with correct root key", () => { + const mathSuperScriptElement = new MathSuperScriptElement(new MathRun("2+2")); - const tree = new Formatter().format(mathSuperScript); + const tree = new Formatter().format(mathSuperScriptElement); expect(tree).to.deep.equal({ "m:sup": [ { diff --git a/src/file/paragraph/math/n-ary/math-super-script.ts b/src/file/paragraph/math/n-ary/math-super-script.ts index 8296c59f6a..1d29bda52b 100644 --- a/src/file/paragraph/math/n-ary/math-super-script.ts +++ b/src/file/paragraph/math/n-ary/math-super-script.ts @@ -1,12 +1,12 @@ -// http://www.datypic.com/sc/ooxml/e-m_e-1.html +// http://www.datypic.com/sc/ooxml/e-m_sup-3.html import { XmlComponent } from "file/xml-components"; -import { MathRun } from "../math-run"; +import { MathComponent } from "../math-component"; -export class MathSuperScript extends XmlComponent { - constructor(readonly run: MathRun) { +export class MathSuperScriptElement extends XmlComponent { + constructor(child: MathComponent) { super("m:sup"); - this.root.push(run); + this.root.push(child); } } diff --git a/src/file/paragraph/math/radical/index.ts b/src/file/paragraph/math/radical/index.ts new file mode 100644 index 0000000000..78240ccd13 --- /dev/null +++ b/src/file/paragraph/math/radical/index.ts @@ -0,0 +1,3 @@ +export * from "./math-degree"; +export * from "./math-radical"; +export * from "./math-radical-properties"; diff --git a/src/file/paragraph/math/radical/math-degree-hide.spec.ts b/src/file/paragraph/math/radical/math-degree-hide.spec.ts new file mode 100644 index 0000000000..0c3f335a13 --- /dev/null +++ b/src/file/paragraph/math/radical/math-degree-hide.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathDegreeHide } from "./math-degree-hide"; + +describe("MathDegreeHide", () => { + describe("#constructor()", () => { + it("should create a MathDegreeHide with correct root key", () => { + const mathDegreeHide = new MathDegreeHide(); + + const tree = new Formatter().format(mathDegreeHide); + expect(tree).to.deep.equal({ + "m:degHide": { + _attr: { + "m:val": 1, + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/radical/math-degree-hide.ts b/src/file/paragraph/math/radical/math-degree-hide.ts new file mode 100644 index 0000000000..c1b9dd2ae5 --- /dev/null +++ b/src/file/paragraph/math/radical/math-degree-hide.ts @@ -0,0 +1,14 @@ +// http://www.datypic.com/sc/ooxml/e-m_degHide-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +class MathDegreeHideAttributes extends XmlAttributeComponent<{ readonly hide: number }> { + protected readonly xmlKeys = { hide: "m:val" }; +} + +export class MathDegreeHide extends XmlComponent { + constructor() { + super("m:degHide"); + + this.root.push(new MathDegreeHideAttributes({ hide: 1 })); + } +} diff --git a/src/file/paragraph/math/radical/math-degree.spec.ts b/src/file/paragraph/math/radical/math-degree.spec.ts new file mode 100644 index 0000000000..6a1c28656b --- /dev/null +++ b/src/file/paragraph/math/radical/math-degree.spec.ts @@ -0,0 +1,36 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathDegree } from "./math-degree"; + +describe("MathDegree", () => { + describe("#constructor()", () => { + it("should create a MathDegree with correct root key", () => { + const mathDegree = new MathDegree(); + + const tree = new Formatter().format(mathDegree); + expect(tree).to.deep.equal({ + "m:deg": {}, + }); + }); + + it("should create a MathDegree with correct root key with child", () => { + const mathDegree = new MathDegree(new MathRun("2")); + + const tree = new Formatter().format(mathDegree); + expect(tree).to.deep.equal({ + "m:deg": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/radical/math-degree.ts b/src/file/paragraph/math/radical/math-degree.ts new file mode 100644 index 0000000000..402ee8ffda --- /dev/null +++ b/src/file/paragraph/math/radical/math-degree.ts @@ -0,0 +1,13 @@ +// http://www.datypic.com/sc/ooxml/e-m_deg-1.html +import { XmlComponent } from "file/xml-components"; +import { MathComponent } from "../math-component"; + +export class MathDegree extends XmlComponent { + constructor(child?: MathComponent) { + super("m:deg"); + + if (!!child) { + this.root.push(child); + } + } +} diff --git a/src/file/paragraph/math/radical/math-radical-properties.spec.ts b/src/file/paragraph/math/radical/math-radical-properties.spec.ts new file mode 100644 index 0000000000..12d29a2962 --- /dev/null +++ b/src/file/paragraph/math/radical/math-radical-properties.spec.ts @@ -0,0 +1,35 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRadicalProperties } from "./math-radical-properties"; + +describe("MathRadicalProperties", () => { + describe("#constructor()", () => { + it("should create a MathRadicalProperties with correct root key", () => { + const mathRadicalProperties = new MathRadicalProperties(true); + + const tree = new Formatter().format(mathRadicalProperties); + expect(tree).to.deep.equal({ + "m:radPr": {}, + }); + }); + + it("should create a MathRadicalProperties with correct root key with degree hide", () => { + const mathRadicalProperties = new MathRadicalProperties(false); + + const tree = new Formatter().format(mathRadicalProperties); + expect(tree).to.deep.equal({ + "m:radPr": [ + { + "m:degHide": { + _attr: { + "m:val": 1, + }, + }, + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/radical/math-radical-properties.ts b/src/file/paragraph/math/radical/math-radical-properties.ts new file mode 100644 index 0000000000..b4e90ed4df --- /dev/null +++ b/src/file/paragraph/math/radical/math-radical-properties.ts @@ -0,0 +1,13 @@ +// http://www.datypic.com/sc/ooxml/e-m_radPr-1.html +import { XmlComponent } from "file/xml-components"; +import { MathDegreeHide } from "./math-degree-hide"; + +export class MathRadicalProperties extends XmlComponent { + constructor(hasDegree: boolean) { + super("m:radPr"); + + if (!hasDegree) { + this.root.push(new MathDegreeHide()); + } + } +} diff --git a/src/file/paragraph/math/radical/math-radical.spec.ts b/src/file/paragraph/math/radical/math-radical.spec.ts new file mode 100644 index 0000000000..7d7d7c4225 --- /dev/null +++ b/src/file/paragraph/math/radical/math-radical.spec.ts @@ -0,0 +1,48 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../math-run"; +import { MathRadical } from "./math-radical"; + +describe("MathRadical", () => { + describe("#constructor()", () => { + it("should create a MathRadical with correct root key", () => { + const mathRadical = new MathRadical({ + child: new MathRun("e"), + degree: new MathRun("2"), + }); + + const tree = new Formatter().format(mathRadical); + expect(tree).to.deep.equal({ + "m:rad": [ + { + "m:radPr": {}, + }, + { + "m:deg": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["e"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/radical/math-radical.ts b/src/file/paragraph/math/radical/math-radical.ts new file mode 100644 index 0000000000..76fc2dc7ca --- /dev/null +++ b/src/file/paragraph/math/radical/math-radical.ts @@ -0,0 +1,22 @@ +// http://www.datypic.com/sc/ooxml/e-m_rad-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../math-component"; +import { MathBase } from "../n-ary"; +import { MathDegree } from "./math-degree"; +import { MathRadicalProperties } from "./math-radical-properties"; + +export interface IMathRadicalOptions { + readonly child: MathComponent; + readonly degree?: MathComponent; +} + +export class MathRadical extends XmlComponent { + constructor(options: IMathRadicalOptions) { + super("m:rad"); + + this.root.push(new MathRadicalProperties(!!options.degree)); + this.root.push(new MathDegree(options.degree)); + this.root.push(new MathBase(options.child)); + } +} diff --git a/src/file/paragraph/math/script/index.ts b/src/file/paragraph/math/script/index.ts new file mode 100644 index 0000000000..a83e54975e --- /dev/null +++ b/src/file/paragraph/math/script/index.ts @@ -0,0 +1,4 @@ +export * from "./super-script"; +export * from "./sub-script"; +export * from "./sub-super-script"; +export * from "./pre-sub-super-script"; diff --git a/src/file/paragraph/math/script/pre-sub-super-script/index.ts b/src/file/paragraph/math/script/pre-sub-super-script/index.ts new file mode 100644 index 0000000000..8660a75017 --- /dev/null +++ b/src/file/paragraph/math/script/pre-sub-super-script/index.ts @@ -0,0 +1,2 @@ +export * from "./math-pre-sub-super-script-function"; +export * from "./math-pre-sub-super-script-function-properties"; diff --git a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.spec.ts b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.spec.ts new file mode 100644 index 0000000000..a6f1d5383e --- /dev/null +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties"; + +describe("MathPreSubSuperScriptProperties", () => { + describe("#constructor()", () => { + it("should create a MathPreSubSuperScriptProperties with correct root key", () => { + const mathPreSubSuperScriptProperties = new MathPreSubSuperScriptProperties(); + + const tree = new Formatter().format(mathPreSubSuperScriptProperties); + expect(tree).to.deep.equal({ + "m:sPrePr": {}, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.ts b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.ts new file mode 100644 index 0000000000..fed0cb3564 --- /dev/null +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function-properties.ts @@ -0,0 +1,8 @@ +// http://www.datypic.com/sc/ooxml/e-m_sPrePr-1.html +import { XmlComponent } from "file/xml-components"; + +export class MathPreSubSuperScriptProperties extends XmlComponent { + constructor() { + super("m:sPrePr"); + } +} diff --git a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.spec.ts b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.spec.ts new file mode 100644 index 0000000000..956a2ff445 --- /dev/null +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.spec.ts @@ -0,0 +1,60 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../../math-run"; +import { MathPreSubSuperScript } from "./math-pre-sub-super-script-function"; + +describe("MathPreSubScript", () => { + describe("#constructor()", () => { + it("should create a MathPreSubScript with correct root key", () => { + const mathPreSubScript = new MathPreSubSuperScript({ + child: new MathRun("e"), + subScript: new MathRun("2"), + superScript: new MathRun("5"), + }); + + const tree = new Formatter().format(mathPreSubScript); + expect(tree).to.deep.equal({ + "m:sPre": [ + { + "m:sPrePr": {}, + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["e"], + }, + ], + }, + ], + }, + { + "m:sub": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + { + "m:sup": [ + { + "m:r": [ + { + "m:t": ["5"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); 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 new file mode 100644 index 0000000000..a0bdc321a0 --- /dev/null +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.ts @@ -0,0 +1,23 @@ +// http://www.datypic.com/sc/ooxml/e-m_sPre-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../../math-component"; +import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-ary"; +import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties"; + +export interface IMathPreSubSuperScriptOptions { + readonly child: MathComponent; + readonly subScript: MathComponent; + readonly superScript: MathComponent; +} + +export class MathPreSubSuperScript extends XmlComponent { + constructor(options: IMathPreSubSuperScriptOptions) { + super("m:sPre"); + + this.root.push(new MathPreSubSuperScriptProperties()); + this.root.push(new MathBase(options.child)); + this.root.push(new MathSubScriptElement(options.subScript)); + this.root.push(new MathSuperScriptElement(options.superScript)); + } +} diff --git a/src/file/paragraph/math/script/sub-script/index.ts b/src/file/paragraph/math/script/sub-script/index.ts new file mode 100644 index 0000000000..0f1c27fe51 --- /dev/null +++ b/src/file/paragraph/math/script/sub-script/index.ts @@ -0,0 +1,2 @@ +export * from "./math-sub-script-function"; +export * from "./math-sub-script-function-properties"; diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.spec.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.spec.ts new file mode 100644 index 0000000000..be229e066b --- /dev/null +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { MathSubScriptProperties } from "./math-sub-script-function-properties"; + +describe("MathSubScriptProperties", () => { + describe("#constructor()", () => { + it("should create a MathSubScriptProperties with correct root key", () => { + const mathSubScriptProperties = new MathSubScriptProperties(); + + const tree = new Formatter().format(mathSubScriptProperties); + expect(tree).to.deep.equal({ + "m:sSubPr": {}, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.ts new file mode 100644 index 0000000000..bf37b1d885 --- /dev/null +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function-properties.ts @@ -0,0 +1,8 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSubPr-1.html +import { XmlComponent } from "file/xml-components"; + +export class MathSubScriptProperties extends XmlComponent { + constructor() { + super("m:sSubPr"); + } +} diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts new file mode 100644 index 0000000000..dd33598d81 --- /dev/null +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts @@ -0,0 +1,48 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../../math-run"; +import { MathSubScript } from "./math-sub-script-function"; + +describe("MathSubScript", () => { + describe("#constructor()", () => { + it("should create a MathSubScript with correct root key", () => { + const mathSubScript = new MathSubScript({ + child: new MathRun("e"), + subScript: new MathRun("2"), + }); + + const tree = new Formatter().format(mathSubScript); + expect(tree).to.deep.equal({ + "m:sSub": [ + { + "m:sSubPr": {}, + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["e"], + }, + ], + }, + ], + }, + { + "m:sub": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts new file mode 100644 index 0000000000..a5c26cd06c --- /dev/null +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts @@ -0,0 +1,21 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSub-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../../math-component"; +import { MathBase, MathSubScriptElement } from "../../n-ary"; +import { MathSubScriptProperties } from "./math-sub-script-function-properties"; + +export interface IMathSubScriptOptions { + readonly child: MathComponent; + readonly subScript: MathComponent; +} + +export class MathSubScript extends XmlComponent { + constructor(options: IMathSubScriptOptions) { + super("m:sSub"); + + this.root.push(new MathSubScriptProperties()); + this.root.push(new MathBase(options.child)); + this.root.push(new MathSubScriptElement(options.subScript)); + } +} diff --git a/src/file/paragraph/math/script/sub-super-script/index.ts b/src/file/paragraph/math/script/sub-super-script/index.ts new file mode 100644 index 0000000000..88ddeb69fa --- /dev/null +++ b/src/file/paragraph/math/script/sub-super-script/index.ts @@ -0,0 +1,2 @@ +export * from "./math-sub-super-script-function"; +export * from "./math-sub-super-script-function-properties"; diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.spec.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.spec.ts new file mode 100644 index 0000000000..b0f934823a --- /dev/null +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties"; + +describe("MathSubSuperScriptProperties", () => { + describe("#constructor()", () => { + it("should create a MathSubSuperScriptProperties with correct root key", () => { + const mathSubSuperScriptProperties = new MathSubSuperScriptProperties(); + + const tree = new Formatter().format(mathSubSuperScriptProperties); + expect(tree).to.deep.equal({ + "m:sSubSupPr": {}, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.ts new file mode 100644 index 0000000000..b3218a7d3a --- /dev/null +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function-properties.ts @@ -0,0 +1,8 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSubSupPr-1.html +import { XmlComponent } from "file/xml-components"; + +export class MathSubSuperScriptProperties extends XmlComponent { + constructor() { + super("m:sSubSupPr"); + } +} diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts new file mode 100644 index 0000000000..5e7f976db7 --- /dev/null +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts @@ -0,0 +1,60 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../../math-run"; +import { MathSubSuperScript } from "./math-sub-super-script-function"; + +describe("MathSubScript", () => { + describe("#constructor()", () => { + it("should create a MathSubScript with correct root key", () => { + const mathSubScript = new MathSubSuperScript({ + child: new MathRun("e"), + subScript: new MathRun("2"), + superScript: new MathRun("5"), + }); + + const tree = new Formatter().format(mathSubScript); + expect(tree).to.deep.equal({ + "m:sSubSup": [ + { + "m:sSubSupPr": {}, + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["e"], + }, + ], + }, + ], + }, + { + "m:sub": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + { + "m:sup": [ + { + "m:r": [ + { + "m:t": ["5"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts new file mode 100644 index 0000000000..91bdfe6781 --- /dev/null +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts @@ -0,0 +1,23 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSubSup-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../../math-component"; +import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-ary"; +import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties"; + +export interface IMathSubSuperScriptOptions { + readonly child: MathComponent; + readonly subScript: MathComponent; + readonly superScript: MathComponent; +} + +export class MathSubSuperScript extends XmlComponent { + constructor(options: IMathSubSuperScriptOptions) { + super("m:sSubSup"); + + this.root.push(new MathSubSuperScriptProperties()); + this.root.push(new MathBase(options.child)); + this.root.push(new MathSubScriptElement(options.subScript)); + this.root.push(new MathSuperScriptElement(options.superScript)); + } +} diff --git a/src/file/paragraph/math/script/super-script/index.ts b/src/file/paragraph/math/script/super-script/index.ts new file mode 100644 index 0000000000..2864fe9ac5 --- /dev/null +++ b/src/file/paragraph/math/script/super-script/index.ts @@ -0,0 +1,2 @@ +export * from "./math-super-script-function"; +export * from "./math-super-script-function-properties"; diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function-properties.spec.ts b/src/file/paragraph/math/script/super-script/math-super-script-function-properties.spec.ts new file mode 100644 index 0000000000..f95920f152 --- /dev/null +++ b/src/file/paragraph/math/script/super-script/math-super-script-function-properties.spec.ts @@ -0,0 +1,17 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { MathSuperScriptProperties } from "./math-super-script-function-properties"; + +describe("MathSuperScriptProperties", () => { + describe("#constructor()", () => { + it("should create a MathSuperScriptProperties with correct root key", () => { + const mathSuperScriptProperties = new MathSuperScriptProperties(); + + const tree = new Formatter().format(mathSuperScriptProperties); + expect(tree).to.deep.equal({ + "m:sSupPr": {}, + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function-properties.ts b/src/file/paragraph/math/script/super-script/math-super-script-function-properties.ts new file mode 100644 index 0000000000..ea5dbac20b --- /dev/null +++ b/src/file/paragraph/math/script/super-script/math-super-script-function-properties.ts @@ -0,0 +1,8 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSupPr-1.html +import { XmlComponent } from "file/xml-components"; + +export class MathSuperScriptProperties extends XmlComponent { + constructor() { + super("m:sSupPr"); + } +} diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts b/src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts new file mode 100644 index 0000000000..6e6beb5e04 --- /dev/null +++ b/src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts @@ -0,0 +1,48 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { MathRun } from "../../math-run"; +import { MathSuperScript } from "./math-super-script-function"; + +describe("MathSuperScript", () => { + describe("#constructor()", () => { + it("should create a MathSuperScript with correct root key", () => { + const mathSuperScript = new MathSuperScript({ + child: new MathRun("e"), + superScript: new MathRun("2"), + }); + + const tree = new Formatter().format(mathSuperScript); + expect(tree).to.deep.equal({ + "m:sSup": [ + { + "m:sSupPr": {}, + }, + { + "m:e": [ + { + "m:r": [ + { + "m:t": ["e"], + }, + ], + }, + ], + }, + { + "m:sup": [ + { + "m:r": [ + { + "m:t": ["2"], + }, + ], + }, + ], + }, + ], + }); + }); + }); +}); diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function.ts b/src/file/paragraph/math/script/super-script/math-super-script-function.ts new file mode 100644 index 0000000000..d48ece6985 --- /dev/null +++ b/src/file/paragraph/math/script/super-script/math-super-script-function.ts @@ -0,0 +1,21 @@ +// http://www.datypic.com/sc/ooxml/e-m_sSup-1.html +import { XmlComponent } from "file/xml-components"; + +import { MathComponent } from "../../math-component"; +import { MathBase, MathSuperScriptElement } from "../../n-ary"; +import { MathSuperScriptProperties } from "./math-super-script-function-properties"; + +export interface IMathSuperScriptOptions { + readonly child: MathComponent; + readonly superScript: MathComponent; +} + +export class MathSuperScript extends XmlComponent { + constructor(options: IMathSuperScriptOptions) { + super("m:sSup"); + + this.root.push(new MathSuperScriptProperties()); + this.root.push(new MathBase(options.child)); + this.root.push(new MathSuperScriptElement(options.superScript)); + } +} diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index 68fa7d00d4..60efb0da34 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -2,11 +2,11 @@ import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run"; import { IXmlableObject, XmlComponent } from "file/xml-components"; +import { File } from "../file"; +import { DeletedTextRun, InsertedTextRun } from "../track-revision"; import { PageBreak } from "./formatting/page-break"; import { Bookmark, HyperlinkRef } from "./links"; import { Math } from "./math"; -import { File } from "../file"; -import { InsertedTextRun, DeletedTextRun } from "../track-revision"; import { IParagraphPropertiesOptions, ParagraphProperties } from "./properties"; import { PictureRun, Run, SequentialIdentifier, SymbolRun, TextRun } from "./run"; diff --git a/src/file/settings/settings.ts b/src/file/settings/settings.ts index 2fa4a27f0a..d828d21fb5 100644 --- a/src/file/settings/settings.ts +++ b/src/file/settings/settings.ts @@ -1,7 +1,7 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { Compatibility } from "./compatibility"; -import { UpdateFields } from "./update-fields"; import { TrackRevisions } from "./track-revisions"; +import { UpdateFields } from "./update-fields"; export interface ISettingsAttributesProperties { readonly wpc?: string; @@ -46,8 +46,8 @@ export class SettingsAttributes extends XmlAttributeComponent { describe("#constructor", () => { diff --git a/src/file/track-revision/track-revision-components/deleted-text-run.ts b/src/file/track-revision/track-revision-components/deleted-text-run.ts index 2342f70104..56d384b31b 100644 --- a/src/file/track-revision/track-revision-components/deleted-text-run.ts +++ b/src/file/track-revision/track-revision-components/deleted-text-run.ts @@ -1,12 +1,11 @@ -import { IChangedAttributesProperties, ChangeAttributes } from "../track-revision"; import { XmlComponent } from "file/xml-components"; -import { IRunOptions, RunProperties, IRunPropertiesOptions, FootnoteReferenceRun } from "../../index"; +import { FootnoteReferenceRun, IRunOptions, IRunPropertiesOptions, RunProperties } from "../../index"; import { Break } from "../../paragraph/run/break"; -import { Begin, Separate, End } from "../../paragraph/run/field"; +import { Begin, End, Separate } from "../../paragraph/run/field"; import { PageNumber } from "../../paragraph/run/run"; - -import { DeletedPage, DeletedNumberOfPages, DeletedNumberOfPagesSection } from "./deleted-page-number"; +import { ChangeAttributes, IChangedAttributesProperties } from "../track-revision"; +import { DeletedNumberOfPages, DeletedNumberOfPagesSection, DeletedPage } from "./deleted-page-number"; import { DeletedText } from "./deleted-text"; interface IDeletedRunOptions extends IRunPropertiesOptions, IChangedAttributesProperties { diff --git a/src/file/track-revision/track-revision-components/inserted-text-run.ts b/src/file/track-revision/track-revision-components/inserted-text-run.ts index 49bd7f53ae..3d39e92c1c 100644 --- a/src/file/track-revision/track-revision-components/inserted-text-run.ts +++ b/src/file/track-revision/track-revision-components/inserted-text-run.ts @@ -1,6 +1,7 @@ -import { IChangedAttributesProperties, ChangeAttributes } from "../track-revision"; import { XmlComponent } from "file/xml-components"; -import { TextRun, IRunOptions } from "../../index"; + +import { IRunOptions, TextRun } from "../../index"; +import { ChangeAttributes, IChangedAttributesProperties } from "../track-revision"; interface IInsertedRunOptions extends IChangedAttributesProperties, IRunOptions {} diff --git a/tslint.json b/tslint.json index d6eb606eba..cb979f920a 100644 --- a/tslint.json +++ b/tslint.json @@ -21,6 +21,8 @@ "no-duplicate-imports": true, "unnecessary-constructor": true, "file-name-casing": [true, "kebab-case"], + "interface-name": [true, "always-prefix"], + "ordered-imports": true, // Functional Programming Rules "no-parameter-reassignment": true, "readonly-keyword": true, From daea8d286811baf336d938d2541fb9b550c21b91 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Mon, 12 Oct 2020 22:13:03 +0100 Subject: [PATCH 4/8] Make fractions take math component --- demo/55-math.ts | 40 ++++++++----------- .../math/fraction/math-denominator.spec.ts | 3 +- .../math/fraction/math-denominator.ts | 6 +-- .../math/fraction/math-fraction.spec.ts | 7 ++-- .../paragraph/math/fraction/math-fraction.ts | 9 +++-- .../math/fraction/math-numerator.spec.ts | 3 +- .../paragraph/math/fraction/math-numerator.ts | 6 +-- 7 files changed, 35 insertions(+), 39 deletions(-) diff --git a/demo/55-math.ts b/demo/55-math.ts index 92993a695a..ad7473915c 100644 --- a/demo/55-math.ts +++ b/demo/55-math.ts @@ -6,10 +6,8 @@ import { Math, MathAngledBrackets, MathCurlyBrackets, - MathDenominator, MathFraction, MathFunction, - MathNumerator, MathPreSubSuperScript, MathRadical, MathRoundBrackets, @@ -35,8 +33,8 @@ doc.addSection({ children: [ new MathRun("2+2"), new MathFraction({ - numerator: new MathNumerator("hi"), - denominator: new MathDenominator("2"), + numerator: new MathRun("hi"), + denominator: new MathRun("2"), }), ], }), @@ -142,8 +140,8 @@ doc.addSection({ children: [ new MathSubScript({ child: new MathFraction({ - numerator: new MathNumerator("1"), - denominator: new MathDenominator("2"), + numerator: new MathRun("1"), + denominator: new MathRun("2"), }), subScript: new MathRun("4"), }), @@ -158,8 +156,8 @@ doc.addSection({ new MathSubScript({ child: new MathRadical({ child: new MathFraction({ - numerator: new MathNumerator("1"), - denominator: new MathDenominator("2"), + numerator: new MathRun("1"), + denominator: new MathRun("2"), }), degree: new MathRun("4"), }), @@ -207,26 +205,26 @@ doc.addSection({ children: [ new MathRoundBrackets({ child: new MathFraction({ - numerator: new MathNumerator("1"), - denominator: new MathDenominator("2"), + numerator: new MathRun("1"), + denominator: new MathRun("2"), }), }), new MathSquareBrackets({ child: new MathFraction({ - numerator: new MathNumerator("1"), - denominator: new MathDenominator("2"), + numerator: new MathRun("1"), + denominator: new MathRun("2"), }), }), new MathCurlyBrackets({ child: new MathFraction({ - numerator: new MathNumerator("1"), - denominator: new MathDenominator("2"), + numerator: new MathRun("1"), + denominator: new MathRun("2"), }), }), new MathAngledBrackets({ child: new MathFraction({ - numerator: new MathNumerator("1"), - denominator: new MathDenominator("2"), + numerator: new MathRun("1"), + denominator: new MathRun("2"), }), }), ], @@ -238,14 +236,10 @@ doc.addSection({ new Math({ children: [ new MathFraction({ - numerator: new Math({ - children: [ - new MathRadical({ - child: new MathRun("4"), - }), - ], + numerator: new MathRadical({ + child: new MathRun("4"), }), - demoninator: new MathRun("2a"), + denominator: new MathRun("2a"), }), ], }), diff --git a/src/file/paragraph/math/fraction/math-denominator.spec.ts b/src/file/paragraph/math/fraction/math-denominator.spec.ts index cca8ae0ee1..a5f50ce1ad 100644 --- a/src/file/paragraph/math/fraction/math-denominator.spec.ts +++ b/src/file/paragraph/math/fraction/math-denominator.spec.ts @@ -2,12 +2,13 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; +import { MathRun } from "../math-run"; import { MathDenominator } from "./math-denominator"; describe("MathDenominator", () => { describe("#constructor()", () => { it("should create a MathDenominator with correct root key", () => { - const mathDenominator = new MathDenominator("2+2"); + const mathDenominator = new MathDenominator(new MathRun("2+2")); const tree = new Formatter().format(mathDenominator); expect(tree).to.deep.equal({ "m:den": [ diff --git a/src/file/paragraph/math/fraction/math-denominator.ts b/src/file/paragraph/math/fraction/math-denominator.ts index f640324c2e..db59eabc8c 100644 --- a/src/file/paragraph/math/fraction/math-denominator.ts +++ b/src/file/paragraph/math/fraction/math-denominator.ts @@ -1,11 +1,11 @@ import { XmlComponent } from "file/xml-components"; -import { MathRun } from "../math-run"; +import { MathComponent } from "../math-component"; export class MathDenominator extends XmlComponent { - constructor(text: string) { + constructor(child: MathComponent) { super("m:den"); - this.root.push(new MathRun(text)); + this.root.push(child); } } diff --git a/src/file/paragraph/math/fraction/math-fraction.spec.ts b/src/file/paragraph/math/fraction/math-fraction.spec.ts index 9a7386e85e..9ebd3c4bcd 100644 --- a/src/file/paragraph/math/fraction/math-fraction.spec.ts +++ b/src/file/paragraph/math/fraction/math-fraction.spec.ts @@ -2,16 +2,15 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; -import { MathDenominator } from "./math-denominator"; +import { MathRun } from "../math-run"; import { MathFraction } from "./math-fraction"; -import { MathNumerator } from "./math-numerator"; describe("MathFraction", () => { describe("#constructor()", () => { it("should create a MathFraction with correct root key", () => { const mathFraction = new MathFraction({ - numerator: new MathNumerator("2"), - denominator: new MathDenominator("2"), + numerator: new MathRun("2"), + denominator: new MathRun("2"), }); const tree = new Formatter().format(mathFraction); expect(tree).to.deep.equal({ diff --git a/src/file/paragraph/math/fraction/math-fraction.ts b/src/file/paragraph/math/fraction/math-fraction.ts index 574a989bba..65768a1fca 100644 --- a/src/file/paragraph/math/fraction/math-fraction.ts +++ b/src/file/paragraph/math/fraction/math-fraction.ts @@ -1,18 +1,19 @@ import { XmlComponent } from "file/xml-components"; +import { MathComponent } from "../math-component"; import { MathDenominator } from "./math-denominator"; import { MathNumerator } from "./math-numerator"; export interface IMathFractionOptions { - readonly numerator: MathNumerator; - readonly denominator: MathDenominator; + readonly numerator: MathComponent; + readonly denominator: MathComponent; } export class MathFraction extends XmlComponent { constructor(options: IMathFractionOptions) { super("m:f"); - this.root.push(options.numerator); - this.root.push(options.denominator); + this.root.push(new MathNumerator(options.numerator)); + this.root.push(new MathDenominator(options.denominator)); } } diff --git a/src/file/paragraph/math/fraction/math-numerator.spec.ts b/src/file/paragraph/math/fraction/math-numerator.spec.ts index 1cc5fc4aa4..862dc18938 100644 --- a/src/file/paragraph/math/fraction/math-numerator.spec.ts +++ b/src/file/paragraph/math/fraction/math-numerator.spec.ts @@ -2,12 +2,13 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; +import { MathRun } from "../math-run"; import { MathNumerator } from "./math-numerator"; describe("MathNumerator", () => { describe("#constructor()", () => { it("should create a MathNumerator with correct root key", () => { - const mathNumerator = new MathNumerator("2+2"); + const mathNumerator = new MathNumerator(new MathRun("2+2")); const tree = new Formatter().format(mathNumerator); expect(tree).to.deep.equal({ "m:num": [ diff --git a/src/file/paragraph/math/fraction/math-numerator.ts b/src/file/paragraph/math/fraction/math-numerator.ts index f7e68715b8..bad0ace36f 100644 --- a/src/file/paragraph/math/fraction/math-numerator.ts +++ b/src/file/paragraph/math/fraction/math-numerator.ts @@ -1,11 +1,11 @@ import { XmlComponent } from "file/xml-components"; -import { MathRun } from "../math-run"; +import { MathComponent } from "../math-component"; export class MathNumerator extends XmlComponent { - constructor(text: string) { + constructor(child: MathComponent) { super("m:num"); - this.root.push(new MathRun(text)); + this.root.push(child); } } From 102d6aa55c6341a372c5e7c73cec7b9c71a32e3b Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Mon, 12 Oct 2020 22:48:38 +0100 Subject: [PATCH 5/8] Add prepForXml test --- src/file/paragraph/paragraph.spec.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/file/paragraph/paragraph.spec.ts b/src/file/paragraph/paragraph.spec.ts index 04cc8af8e4..0b8e9acd00 100644 --- a/src/file/paragraph/paragraph.spec.ts +++ b/src/file/paragraph/paragraph.spec.ts @@ -5,8 +5,9 @@ import { stub } from "sinon"; import { Formatter } from "export/formatter"; import { EMPTY_OBJECT } from "file/xml-components"; +import { File } from "../file"; import { AlignmentType, HeadingLevel, LeaderType, PageBreak, TabStopPosition, TabStopType } from "./formatting"; -import { Bookmark } from "./links"; +import { Bookmark, HyperlinkRef } from "./links"; import { Paragraph } from "./paragraph"; describe("Paragraph", () => { @@ -759,4 +760,23 @@ describe("Paragraph", () => { }); }); }); + + describe("#prepForXml", () => { + it("should set paragraph outline level to the given value", () => { + const paragraph = new Paragraph({ + children: [new HyperlinkRef("myAnchorId")], + }); + const fileMock = ({ + HyperlinkCache: { + myAnchorId: "test", + }, + // tslint:disable-next-line: no-any + } as any) as File; + paragraph.prepForXml(fileMock); + const tree = new Formatter().format(paragraph); + expect(tree).to.deep.equal({ + "w:p": ["test"], + }); + }); + }); }); From e36e9e1cf4e3f8a86646e44862295b4e15072dce Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Tue, 13 Oct 2020 01:23:27 +0100 Subject: [PATCH 6/8] Add initial math documentation --- docs/_sidebar.md | 1 + docs/images/math-example.png | Bin 0 -> 16782 bytes docs/usage/math.md | 126 +++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 docs/images/math-example.png create mode 100644 docs/usage/math.md diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 5d2ba31551..bcdb03c55f 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -21,6 +21,7 @@ * [Table of Contents](usage/table-of-contents.md) * [Page Numbers](usage/page-numbers.md) * [Change Tracking](usage/change-tracking.md) + * [Math](usage/math.md) * Styling * [Styling with JS](usage/styling-with-js.md) * [Styling with XML](usage/styling-with-xml.md) diff --git a/docs/images/math-example.png b/docs/images/math-example.png new file mode 100644 index 0000000000000000000000000000000000000000..c92f8806f93c1639be5750c3252766494b53d83e GIT binary patch literal 16782 zcmeIZWmr{Tw?4etY!IYDK)OS^OG=P#5Rfh@N$D;X1SzFNQc^mlQyP@+mhSF+=k|Hd zbAIRl|L}f#zr5Gsx|VzGz1FNT$GFEB_n3yND$8IzBz_2iKrrNFpQ}S42xs6DM?nU^ zD0>)=LLlg-){>H{a*~pis!k3T*0$ylh-_$F!h@F@Jp=*k@h@<7DWU2T4neXQlyvV1 zo{8sEGEt$@#y-Xk3L`VnYW?w%QOia1`Op}C^bbl?ceR~j^Ro2vayA0n?+vJ^8+9c< z4owbwH-gS>H!Z@oR8$td&B!anwni(TK_3=xJsfDgfcj~}j%YoM7k z5lHeyOFp0)c=4v{YeJrY#_t(q7u@CAXc7dtM@>w*jQhRQJT*XCKCo_yRVGv%D1jNr_{#HU z^WO6HoqNxK24=s>17;b>*)IIM9#8&eMvtCocv=vO-M<-TVXWZfKmM&ot15If=Xx< z*$RtbLMD-3R|3|rf?)^EHTpL^XAWUf4bQGiK6ZpYiOz!=@^gM$41G%n28=Qgyx&+1uHo++6==8SzTht43h zMDIbl7bVkX$x*l`KyprYa`sX559ha(g8;{f!DltRI_lK-oe5>>h|^dT&yz1*+iS=w zH{XXWA`A*uhI7BcTMY94=_%lWojipmUrXGqSypkUlq`wk6XzU3-VqU`9;_Dh1al#B z)NS~TxICkGW8zZn`m129=AP<6^|5nvZv}Rh+QMs7v@*m=>m30%f~VoU5CS)Jn|3y1 znHR#9!Q>c)-&&`Z9^CZ2ccZ=k5>=9@5hwRvuShRpMn;K(@sSeq3pdTbQ&dtt2RDCr@OY*dT1v()86h4>I8bl9pAbMos|L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393ac9 --- /dev/null +++ b/docs/usage/math.md @@ -0,0 +1,126 @@ +# Math + +!> Math requires an understanding of [Sections](usage/sections.md) and [Paragraphs](usage/paragraph.md). + +## Intro + +- To add math, create a `Math` object +- Add `MathComponents` inside `Math` +- `MathComponents` can have nested `MathComponents` inside. e.g. A fraction where the numerator is a square root, and the demoninator as another fraction. More on `MathComponents` below + +## Example + +```ts +new Math({ + children: [ + new MathRun("2+2"), + new MathFraction({ + numerator: [new MathRun("hi")], + denominator: [new MathRun("2")], + }), + ], +}), +``` + +This will produce: + +

+ clippy the assistant +

+ +## Math Components + +`MathComponents` are the unit sized building blocks of an equation in `docx`. A `MathComponent` takes in more nested `MathComponents` until you reach `MathRun`, which has no children. `MathRun` is similar to a [TextRun](usage/text.md). + +### Math Run + +`MathRun` is the most basic `MathComponent`. + +#### Example + +```ts +new MathRun("2+2"); +``` + +```ts +new MathRun("hello"); +``` + +An example of it being used inside `Math`: + +```ts +new Math({ + children: [ + new MathRun("2"), + new MathRun("+"), + new MathRun("2"), + ], +}), +``` + +### Math Fraction + +`MathFractions` require a `numerator` and a `demoninator`, which are both a list of `MathComponents` + +#### Example + +```ts +new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], +}), +``` + +```ts +new MathFraction({ + numerator: [ + new MathRun("1"), + new MathRadical({ + child: [new MathRun("2")], + }), + ], + denominator: [new MathRun("2")], +}), +``` + +An example of it being used inside `Math`: + +```ts +new Math({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + new MathText("+"), + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + new MathText("= 1"), + ], +}), +``` + +### Sum + +A `MathComponent` for `Σ`. It can take a `superScript` and/or `subScript` as arguments to add `MathComponents` (usually limits) on the top and bottom + +```ts +new MathSum({ + child: [new MathRun("i")], +}), +``` + +```ts +new MathSum({ + child: [ + new MathSuperScript({ + child: new MathRun("e"), + superScript: new MathRun("2"), + }) + ], + subScript: [new MathRun("i")], + superScript: [new MathRun("10")], +}), +``` From 5be195fd9115beaad6d1100bd83d88612e096bdd Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Tue, 13 Oct 2020 02:06:27 +0100 Subject: [PATCH 7/8] Turn math component into array --- demo/55-math.ts | 193 +++++++++++------- .../brackets/math-angled-brackets.spec.ts | 2 +- .../math/brackets/math-angled-brackets.ts | 4 +- .../math/brackets/math-curly-brackets.spec.ts | 2 +- .../math/brackets/math-curly-brackets.ts | 4 +- .../math/brackets/math-round-brackets.spec.ts | 2 +- .../math/brackets/math-round-brackets.ts | 4 +- .../brackets/math-square-brackets.spec.ts | 2 +- .../math/brackets/math-square-brackets.ts | 4 +- .../math/fraction/math-denominator.spec.ts | 2 +- .../math/fraction/math-denominator.ts | 6 +- .../math/fraction/math-fraction.spec.ts | 4 +- .../paragraph/math/fraction/math-fraction.ts | 4 +- .../math/fraction/math-numerator.spec.ts | 2 +- .../paragraph/math/fraction/math-numerator.ts | 6 +- .../math/function/math-function-name.spec.ts | 2 +- .../math/function/math-function-name.ts | 6 +- .../math/function/math-function.spec.ts | 4 +- .../paragraph/math/function/math-function.ts | 6 +- .../paragraph/math/n-ary/math-base.spec.ts | 2 +- src/file/paragraph/math/n-ary/math-base.ts | 6 +- .../math/n-ary/math-sub-script.spec.ts | 2 +- .../paragraph/math/n-ary/math-sub-script.ts | 6 +- .../paragraph/math/n-ary/math-sum.spec.ts | 6 +- src/file/paragraph/math/n-ary/math-sum.ts | 8 +- .../math/n-ary/math-super-script.spec.ts | 2 +- .../paragraph/math/n-ary/math-super-script.ts | 6 +- .../math/radical/math-degree.spec.ts | 2 +- .../paragraph/math/radical/math-degree.ts | 8 +- .../math/radical/math-radical.spec.ts | 4 +- .../paragraph/math/radical/math-radical.ts | 6 +- ...math-pre-sub-super-script-function.spec.ts | 6 +- .../math-pre-sub-super-script-function.ts | 8 +- .../math-sub-script-function.spec.ts | 4 +- .../sub-script/math-sub-script-function.ts | 6 +- .../math-sub-super-script-function.spec.ts | 6 +- .../math-sub-super-script-function.ts | 8 +- .../math-super-script-function.spec.ts | 4 +- .../math-super-script-function.ts | 6 +- 39 files changed, 208 insertions(+), 157 deletions(-) diff --git a/demo/55-math.ts b/demo/55-math.ts index ad7473915c..3dc6c1a17c 100644 --- a/demo/55-math.ts +++ b/demo/55-math.ts @@ -33,8 +33,8 @@ doc.addSection({ children: [ new MathRun("2+2"), new MathFraction({ - numerator: new MathRun("hi"), - denominator: new MathRun("2"), + numerator: [new MathRun("hi")], + denominator: [new MathRun("2")], }), ], }), @@ -44,26 +44,43 @@ doc.addSection({ }), ], }), + // new Paragraph({ + // children: [ + // new MathFraction({ + // numerator: [ + // new MathRun("1"), + // new MathRadical({ + // children: [new MathRun("2")], + // }), + // ], + // denominator: [new MathRun("2")], + // }), + // ], + // }), new Paragraph({ children: [ new Math({ children: [ new MathSum({ - child: new MathRun("test"), + children: [new MathRun("test")], }), new MathSum({ - child: new MathSuperScript({ - child: new MathRun("e"), - superScript: new MathRun("2"), - }), - subScript: new MathRun("i"), + children: [ + new MathSuperScript({ + children: [new MathRun("e")], + superScript: [new MathRun("2")], + }), + ], + subScript: [new MathRun("i")], }), new MathSum({ - child: new MathRadical({ - child: new MathRun("i"), - }), - subScript: new MathRun("i"), - superScript: new MathRun("10"), + children: [ + new MathRadical({ + children: [new MathRun("i")], + }), + ], + subScript: [new MathRun("i")], + superScript: [new MathRun("10")], }), ], }), @@ -74,8 +91,8 @@ doc.addSection({ new Math({ children: [ new MathSuperScript({ - child: new MathRun("test"), - superScript: new MathRun("hello"), + children: [new MathRun("test")], + superScript: [new MathRun("hello")], }), ], }), @@ -86,8 +103,8 @@ doc.addSection({ new Math({ children: [ new MathSubScript({ - child: new MathRun("test"), - subScript: new MathRun("hello"), + children: [new MathRun("test")], + subScript: [new MathRun("hello")], }), ], }), @@ -98,11 +115,13 @@ doc.addSection({ new Math({ children: [ new MathSubScript({ - child: new MathRun("x"), - subScript: new MathSuperScript({ - child: new MathRun("y"), - superScript: new MathRun("2"), - }), + children: [new MathRun("x")], + subScript: [ + new MathSuperScript({ + children: [new MathRun("y")], + superScript: [new MathRun("2")], + }), + ], }), ], }), @@ -113,9 +132,9 @@ doc.addSection({ new Math({ children: [ new MathSubSuperScript({ - child: new MathRun("test"), - superScript: new MathRun("hello"), - subScript: new MathRun("world"), + children: [new MathRun("test")], + superScript: [new MathRun("hello")], + subScript: [new MathRun("world")], }), ], }), @@ -126,9 +145,9 @@ doc.addSection({ new Math({ children: [ new MathPreSubSuperScript({ - child: new MathRun("test"), - superScript: new MathRun("hello"), - subScript: new MathRun("world"), + children: [new MathRun("test")], + superScript: [new MathRun("hello")], + subScript: [new MathRun("world")], }), ], }), @@ -139,29 +158,35 @@ doc.addSection({ new Math({ children: [ new MathSubScript({ - child: new MathFraction({ - numerator: new MathRun("1"), - denominator: new MathRun("2"), - }), - subScript: new MathRun("4"), - }), - ], - }), - ], - }), - new Paragraph({ - children: [ - new Math({ - children: [ - new MathSubScript({ - child: new MathRadical({ - child: new MathFraction({ - numerator: new MathRun("1"), - denominator: new MathRun("2"), + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], }), - degree: new MathRun("4"), - }), - subScript: new MathRun("x"), + ], + subScript: [new MathRun("4")], + }), + ], + }), + ], + }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathSubScript({ + children: [ + new MathRadical({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], + degree: [new MathRun("4")], + }), + ], + subScript: [new MathRun("x")], }), ], }), @@ -172,7 +197,7 @@ doc.addSection({ new Math({ children: [ new MathRadical({ - child: new MathRun("4"), + children: [new MathRun("4")], }), ], }), @@ -183,16 +208,18 @@ doc.addSection({ new Math({ children: [ new MathFunction({ - name: new MathSuperScript({ - child: new MathRun("cos"), - superScript: new MathRun("-1"), - }), - child: new MathRun("100"), + name: [ + new MathSuperScript({ + children: [new MathRun("cos")], + superScript: [new MathRun("-1")], + }), + ], + children: [new MathRun("100")], }), new MathRun("×"), new MathFunction({ - name: new MathRun("sin"), - child: new MathRun("360"), + name: [new MathRun("sin")], + children: [new MathRun("360")], }), new MathRun("= x"), ], @@ -204,28 +231,36 @@ doc.addSection({ new Math({ children: [ new MathRoundBrackets({ - child: new MathFraction({ - numerator: new MathRun("1"), - denominator: new MathRun("2"), - }), + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], }), new MathSquareBrackets({ - child: new MathFraction({ - numerator: new MathRun("1"), - denominator: new MathRun("2"), - }), + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], }), new MathCurlyBrackets({ - child: new MathFraction({ - numerator: new MathRun("1"), - denominator: new MathRun("2"), - }), + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], }), new MathAngledBrackets({ - child: new MathFraction({ - numerator: new MathRun("1"), - denominator: new MathRun("2"), - }), + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], }), ], }), @@ -236,10 +271,12 @@ doc.addSection({ new Math({ children: [ new MathFraction({ - numerator: new MathRadical({ - child: new MathRun("4"), - }), - denominator: new MathRun("2a"), + numerator: [ + new MathRadical({ + children: [new MathRun("4")], + }), + ], + denominator: [new MathRun("2a")], }), ], }), diff --git a/src/file/paragraph/math/brackets/math-angled-brackets.spec.ts b/src/file/paragraph/math/brackets/math-angled-brackets.spec.ts index 735e0da272..ccd73b192b 100644 --- a/src/file/paragraph/math/brackets/math-angled-brackets.spec.ts +++ b/src/file/paragraph/math/brackets/math-angled-brackets.spec.ts @@ -9,7 +9,7 @@ describe("MathAngledBrackets", () => { describe("#constructor()", () => { it("should create a MathAngledBrackets with correct root key", () => { const mathAngledBrackets = new MathAngledBrackets({ - child: new MathRun("60"), + children: [new MathRun("60")], }); const tree = new Formatter().format(mathAngledBrackets); diff --git a/src/file/paragraph/math/brackets/math-angled-brackets.ts b/src/file/paragraph/math/brackets/math-angled-brackets.ts index fbafb7e738..48fe0d415d 100644 --- a/src/file/paragraph/math/brackets/math-angled-brackets.ts +++ b/src/file/paragraph/math/brackets/math-angled-brackets.ts @@ -6,7 +6,7 @@ import { MathBase } from "../n-ary"; import { MathBracketProperties } from "./math-bracket-properties"; export class MathAngledBrackets extends XmlComponent { - constructor(options: { readonly child: MathComponent }) { + constructor(options: { readonly children: MathComponent[] }) { super("m:d"); this.root.push( @@ -15,6 +15,6 @@ export class MathAngledBrackets extends XmlComponent { endingCharacter: "〉", }), ); - this.root.push(new MathBase(options.child)); + this.root.push(new MathBase(options.children)); } } diff --git a/src/file/paragraph/math/brackets/math-curly-brackets.spec.ts b/src/file/paragraph/math/brackets/math-curly-brackets.spec.ts index 6e44621b21..d6defd57ef 100644 --- a/src/file/paragraph/math/brackets/math-curly-brackets.spec.ts +++ b/src/file/paragraph/math/brackets/math-curly-brackets.spec.ts @@ -9,7 +9,7 @@ describe("MathCurlyBrackets", () => { describe("#constructor()", () => { it("should create a MathCurlyBrackets with correct root key", () => { const mathCurlyBrackets = new MathCurlyBrackets({ - child: new MathRun("60"), + children: [new MathRun("60")], }); const tree = new Formatter().format(mathCurlyBrackets); diff --git a/src/file/paragraph/math/brackets/math-curly-brackets.ts b/src/file/paragraph/math/brackets/math-curly-brackets.ts index 4d540ec8bc..ccce71e6a7 100644 --- a/src/file/paragraph/math/brackets/math-curly-brackets.ts +++ b/src/file/paragraph/math/brackets/math-curly-brackets.ts @@ -6,7 +6,7 @@ import { MathBase } from "../n-ary"; import { MathBracketProperties } from "./math-bracket-properties"; export class MathCurlyBrackets extends XmlComponent { - constructor(options: { readonly child: MathComponent }) { + constructor(options: { readonly children: MathComponent[] }) { super("m:d"); this.root.push( @@ -15,6 +15,6 @@ export class MathCurlyBrackets extends XmlComponent { endingCharacter: "}", }), ); - this.root.push(new MathBase(options.child)); + this.root.push(new MathBase(options.children)); } } diff --git a/src/file/paragraph/math/brackets/math-round-brackets.spec.ts b/src/file/paragraph/math/brackets/math-round-brackets.spec.ts index cb28126a20..5138e9d085 100644 --- a/src/file/paragraph/math/brackets/math-round-brackets.spec.ts +++ b/src/file/paragraph/math/brackets/math-round-brackets.spec.ts @@ -9,7 +9,7 @@ describe("MathRoundBrackets", () => { describe("#constructor()", () => { it("should create a MathRoundBrackets with correct root key", () => { const mathRoundBrackets = new MathRoundBrackets({ - child: new MathRun("60"), + children: [new MathRun("60")], }); const tree = new Formatter().format(mathRoundBrackets); diff --git a/src/file/paragraph/math/brackets/math-round-brackets.ts b/src/file/paragraph/math/brackets/math-round-brackets.ts index 2302fa30f1..6fe60318a4 100644 --- a/src/file/paragraph/math/brackets/math-round-brackets.ts +++ b/src/file/paragraph/math/brackets/math-round-brackets.ts @@ -6,10 +6,10 @@ import { MathBase } from "../n-ary"; import { MathBracketProperties } from "./math-bracket-properties"; export class MathRoundBrackets extends XmlComponent { - constructor(options: { readonly child: MathComponent }) { + constructor(options: { readonly children: MathComponent[] }) { super("m:d"); this.root.push(new MathBracketProperties()); - this.root.push(new MathBase(options.child)); + this.root.push(new MathBase(options.children)); } } diff --git a/src/file/paragraph/math/brackets/math-square-brackets.spec.ts b/src/file/paragraph/math/brackets/math-square-brackets.spec.ts index 03b8aef03d..b0e2ec9e26 100644 --- a/src/file/paragraph/math/brackets/math-square-brackets.spec.ts +++ b/src/file/paragraph/math/brackets/math-square-brackets.spec.ts @@ -9,7 +9,7 @@ describe("MathSquareBrackets", () => { describe("#constructor()", () => { it("should create a MathSquareBrackets with correct root key", () => { const mathSquareBrackets = new MathSquareBrackets({ - child: new MathRun("60"), + children: [new MathRun("60")], }); const tree = new Formatter().format(mathSquareBrackets); diff --git a/src/file/paragraph/math/brackets/math-square-brackets.ts b/src/file/paragraph/math/brackets/math-square-brackets.ts index 3c3d385357..fdfe88a004 100644 --- a/src/file/paragraph/math/brackets/math-square-brackets.ts +++ b/src/file/paragraph/math/brackets/math-square-brackets.ts @@ -6,7 +6,7 @@ import { MathBase } from "../n-ary"; import { MathBracketProperties } from "./math-bracket-properties"; export class MathSquareBrackets extends XmlComponent { - constructor(options: { readonly child: MathComponent }) { + constructor(options: { readonly children: MathComponent[] }) { super("m:d"); this.root.push( @@ -15,6 +15,6 @@ export class MathSquareBrackets extends XmlComponent { endingCharacter: "]", }), ); - this.root.push(new MathBase(options.child)); + this.root.push(new MathBase(options.children)); } } diff --git a/src/file/paragraph/math/fraction/math-denominator.spec.ts b/src/file/paragraph/math/fraction/math-denominator.spec.ts index a5f50ce1ad..f2e7459e1e 100644 --- a/src/file/paragraph/math/fraction/math-denominator.spec.ts +++ b/src/file/paragraph/math/fraction/math-denominator.spec.ts @@ -8,7 +8,7 @@ import { MathDenominator } from "./math-denominator"; describe("MathDenominator", () => { describe("#constructor()", () => { it("should create a MathDenominator with correct root key", () => { - const mathDenominator = new MathDenominator(new MathRun("2+2")); + const mathDenominator = new MathDenominator([new MathRun("2+2")]); const tree = new Formatter().format(mathDenominator); expect(tree).to.deep.equal({ "m:den": [ diff --git a/src/file/paragraph/math/fraction/math-denominator.ts b/src/file/paragraph/math/fraction/math-denominator.ts index db59eabc8c..8df68bf4b0 100644 --- a/src/file/paragraph/math/fraction/math-denominator.ts +++ b/src/file/paragraph/math/fraction/math-denominator.ts @@ -3,9 +3,11 @@ import { XmlComponent } from "file/xml-components"; import { MathComponent } from "../math-component"; export class MathDenominator extends XmlComponent { - constructor(child: MathComponent) { + constructor(children: MathComponent[]) { super("m:den"); - this.root.push(child); + for (const child of children) { + this.root.push(child); + } } } diff --git a/src/file/paragraph/math/fraction/math-fraction.spec.ts b/src/file/paragraph/math/fraction/math-fraction.spec.ts index 9ebd3c4bcd..51cac646bf 100644 --- a/src/file/paragraph/math/fraction/math-fraction.spec.ts +++ b/src/file/paragraph/math/fraction/math-fraction.spec.ts @@ -9,8 +9,8 @@ describe("MathFraction", () => { describe("#constructor()", () => { it("should create a MathFraction with correct root key", () => { const mathFraction = new MathFraction({ - numerator: new MathRun("2"), - denominator: new MathRun("2"), + numerator: [new MathRun("2")], + denominator: [new MathRun("2")], }); const tree = new Formatter().format(mathFraction); expect(tree).to.deep.equal({ diff --git a/src/file/paragraph/math/fraction/math-fraction.ts b/src/file/paragraph/math/fraction/math-fraction.ts index 65768a1fca..84a803a872 100644 --- a/src/file/paragraph/math/fraction/math-fraction.ts +++ b/src/file/paragraph/math/fraction/math-fraction.ts @@ -5,8 +5,8 @@ import { MathDenominator } from "./math-denominator"; import { MathNumerator } from "./math-numerator"; export interface IMathFractionOptions { - readonly numerator: MathComponent; - readonly denominator: MathComponent; + readonly numerator: MathComponent[]; + readonly denominator: MathComponent[]; } export class MathFraction extends XmlComponent { diff --git a/src/file/paragraph/math/fraction/math-numerator.spec.ts b/src/file/paragraph/math/fraction/math-numerator.spec.ts index 862dc18938..e3aaf35c0e 100644 --- a/src/file/paragraph/math/fraction/math-numerator.spec.ts +++ b/src/file/paragraph/math/fraction/math-numerator.spec.ts @@ -8,7 +8,7 @@ import { MathNumerator } from "./math-numerator"; describe("MathNumerator", () => { describe("#constructor()", () => { it("should create a MathNumerator with correct root key", () => { - const mathNumerator = new MathNumerator(new MathRun("2+2")); + const mathNumerator = new MathNumerator([new MathRun("2+2")]); const tree = new Formatter().format(mathNumerator); expect(tree).to.deep.equal({ "m:num": [ diff --git a/src/file/paragraph/math/fraction/math-numerator.ts b/src/file/paragraph/math/fraction/math-numerator.ts index bad0ace36f..b7a49d9a75 100644 --- a/src/file/paragraph/math/fraction/math-numerator.ts +++ b/src/file/paragraph/math/fraction/math-numerator.ts @@ -3,9 +3,11 @@ import { XmlComponent } from "file/xml-components"; import { MathComponent } from "../math-component"; export class MathNumerator extends XmlComponent { - constructor(child: MathComponent) { + constructor(children: MathComponent[]) { super("m:num"); - this.root.push(child); + for (const child of children) { + this.root.push(child); + } } } diff --git a/src/file/paragraph/math/function/math-function-name.spec.ts b/src/file/paragraph/math/function/math-function-name.spec.ts index bdb38d7596..8a37ee998e 100644 --- a/src/file/paragraph/math/function/math-function-name.spec.ts +++ b/src/file/paragraph/math/function/math-function-name.spec.ts @@ -8,7 +8,7 @@ import { MathFunctionName } from "./math-function-name"; describe("MathFunctionName", () => { describe("#constructor()", () => { it("should create a MathFunctionName with correct root key", () => { - const mathFunctionName = new MathFunctionName(new MathRun("2")); + const mathFunctionName = new MathFunctionName([new MathRun("2")]); const tree = new Formatter().format(mathFunctionName); expect(tree).to.deep.equal({ diff --git a/src/file/paragraph/math/function/math-function-name.ts b/src/file/paragraph/math/function/math-function-name.ts index 011e82133a..e58488dd28 100644 --- a/src/file/paragraph/math/function/math-function-name.ts +++ b/src/file/paragraph/math/function/math-function-name.ts @@ -3,9 +3,11 @@ import { XmlComponent } from "file/xml-components"; import { MathComponent } from "../math-component"; export class MathFunctionName extends XmlComponent { - constructor(child: MathComponent) { + constructor(children: MathComponent[]) { super("m:fName"); - this.root.push(child); + for (const child of children) { + this.root.push(child); + } } } diff --git a/src/file/paragraph/math/function/math-function.spec.ts b/src/file/paragraph/math/function/math-function.spec.ts index 4320a853c6..6ea02b6c9d 100644 --- a/src/file/paragraph/math/function/math-function.spec.ts +++ b/src/file/paragraph/math/function/math-function.spec.ts @@ -9,8 +9,8 @@ describe("MathFunction", () => { describe("#constructor()", () => { it("should create a MathFunction with correct root key", () => { const mathFunction = new MathFunction({ - name: new MathRun("sin"), - child: new MathRun("60"), + name: [new MathRun("sin")], + children: [new MathRun("60")], }); const tree = new Formatter().format(mathFunction); diff --git a/src/file/paragraph/math/function/math-function.ts b/src/file/paragraph/math/function/math-function.ts index b3de75ddb8..86b66392cc 100644 --- a/src/file/paragraph/math/function/math-function.ts +++ b/src/file/paragraph/math/function/math-function.ts @@ -7,8 +7,8 @@ import { MathFunctionName } from "./math-function-name"; import { MathFunctionProperties } from "./math-function-properties"; export interface IMathFunctionOptions { - readonly child: MathComponent; - readonly name: MathComponent; + readonly children: MathComponent[]; + readonly name: MathComponent[]; } export class MathFunction extends XmlComponent { @@ -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.child)); + this.root.push(new MathBase(options.children)); } } diff --git a/src/file/paragraph/math/n-ary/math-base.spec.ts b/src/file/paragraph/math/n-ary/math-base.spec.ts index 012147c4d9..c282537970 100644 --- a/src/file/paragraph/math/n-ary/math-base.spec.ts +++ b/src/file/paragraph/math/n-ary/math-base.spec.ts @@ -8,7 +8,7 @@ import { MathBase } from "./math-base"; describe("MathBase", () => { describe("#constructor()", () => { it("should create a MathBase with correct root key", () => { - const mathBase = new MathBase(new MathRun("2+2")); + const mathBase = new MathBase([new MathRun("2+2")]); const tree = new Formatter().format(mathBase); expect(tree).to.deep.equal({ diff --git a/src/file/paragraph/math/n-ary/math-base.ts b/src/file/paragraph/math/n-ary/math-base.ts index 7c06a67c23..6c2320439f 100644 --- a/src/file/paragraph/math/n-ary/math-base.ts +++ b/src/file/paragraph/math/n-ary/math-base.ts @@ -4,9 +4,11 @@ import { XmlComponent } from "file/xml-components"; import { MathComponent } from "../math-component"; export class MathBase extends XmlComponent { - constructor(run: MathComponent) { + constructor(children: MathComponent[]) { super("m:e"); - this.root.push(run); + for (const child of children) { + this.root.push(child); + } } } diff --git a/src/file/paragraph/math/n-ary/math-sub-script.spec.ts b/src/file/paragraph/math/n-ary/math-sub-script.spec.ts index 5a4009811e..d342946b74 100644 --- a/src/file/paragraph/math/n-ary/math-sub-script.spec.ts +++ b/src/file/paragraph/math/n-ary/math-sub-script.spec.ts @@ -8,7 +8,7 @@ import { MathSubScriptElement } from "./math-sub-script"; describe("MathSubScriptElement", () => { describe("#constructor()", () => { it("should create a MathSubScriptElement with correct root key", () => { - const mathSubScriptElement = new MathSubScriptElement(new MathRun("2+2")); + const mathSubScriptElement = new MathSubScriptElement([new MathRun("2+2")]); const tree = new Formatter().format(mathSubScriptElement); expect(tree).to.deep.equal({ diff --git a/src/file/paragraph/math/n-ary/math-sub-script.ts b/src/file/paragraph/math/n-ary/math-sub-script.ts index aaa8530e74..48268312cf 100644 --- a/src/file/paragraph/math/n-ary/math-sub-script.ts +++ b/src/file/paragraph/math/n-ary/math-sub-script.ts @@ -4,9 +4,11 @@ import { XmlComponent } from "file/xml-components"; import { MathComponent } from "../math-component"; export class MathSubScriptElement extends XmlComponent { - constructor(child: MathComponent) { + constructor(children: MathComponent[]) { super("m:sub"); - this.root.push(child); + for (const child of children) { + this.root.push(child); + } } } diff --git a/src/file/paragraph/math/n-ary/math-sum.spec.ts b/src/file/paragraph/math/n-ary/math-sum.spec.ts index 9f0d213aa4..1e76815147 100644 --- a/src/file/paragraph/math/n-ary/math-sum.spec.ts +++ b/src/file/paragraph/math/n-ary/math-sum.spec.ts @@ -9,9 +9,9 @@ describe("MathSum", () => { describe("#constructor()", () => { it("should create a MathSum with correct root key", () => { const mathSum = new MathSum({ - child: new MathRun("1"), - subScript: new MathRun("2"), - superScript: new MathRun("3"), + children: [new MathRun("1")], + subScript: [new MathRun("2")], + superScript: [new MathRun("3")], }); const tree = new Formatter().format(mathSum); diff --git a/src/file/paragraph/math/n-ary/math-sum.ts b/src/file/paragraph/math/n-ary/math-sum.ts index a16603982d..af14730bbf 100644 --- a/src/file/paragraph/math/n-ary/math-sum.ts +++ b/src/file/paragraph/math/n-ary/math-sum.ts @@ -8,9 +8,9 @@ import { MathSubScriptElement } from "./math-sub-script"; import { MathSuperScriptElement } from "./math-super-script"; export interface IMathSumOptions { - readonly child: MathComponent; - readonly subScript?: MathComponent; - readonly superScript?: MathComponent; + readonly children: MathComponent[]; + readonly subScript?: MathComponent[]; + readonly superScript?: MathComponent[]; } export class MathSum extends XmlComponent { @@ -27,6 +27,6 @@ export class MathSum extends XmlComponent { this.root.push(new MathSuperScriptElement(options.superScript)); } - this.root.push(new MathBase(options.child)); + this.root.push(new MathBase(options.children)); } } diff --git a/src/file/paragraph/math/n-ary/math-super-script.spec.ts b/src/file/paragraph/math/n-ary/math-super-script.spec.ts index 85a5195c0f..10e037eba3 100644 --- a/src/file/paragraph/math/n-ary/math-super-script.spec.ts +++ b/src/file/paragraph/math/n-ary/math-super-script.spec.ts @@ -8,7 +8,7 @@ import { MathSuperScriptElement } from "./math-super-script"; describe("MathSuperScriptElement", () => { describe("#constructor()", () => { it("should create a MathSuperScriptElement with correct root key", () => { - const mathSuperScriptElement = new MathSuperScriptElement(new MathRun("2+2")); + const mathSuperScriptElement = new MathSuperScriptElement([new MathRun("2+2")]); const tree = new Formatter().format(mathSuperScriptElement); expect(tree).to.deep.equal({ diff --git a/src/file/paragraph/math/n-ary/math-super-script.ts b/src/file/paragraph/math/n-ary/math-super-script.ts index 1d29bda52b..8d8386addc 100644 --- a/src/file/paragraph/math/n-ary/math-super-script.ts +++ b/src/file/paragraph/math/n-ary/math-super-script.ts @@ -4,9 +4,11 @@ import { XmlComponent } from "file/xml-components"; import { MathComponent } from "../math-component"; export class MathSuperScriptElement extends XmlComponent { - constructor(child: MathComponent) { + constructor(children: MathComponent[]) { super("m:sup"); - this.root.push(child); + for (const child of children) { + this.root.push(child); + } } } diff --git a/src/file/paragraph/math/radical/math-degree.spec.ts b/src/file/paragraph/math/radical/math-degree.spec.ts index 6a1c28656b..3d1f17dfa8 100644 --- a/src/file/paragraph/math/radical/math-degree.spec.ts +++ b/src/file/paragraph/math/radical/math-degree.spec.ts @@ -17,7 +17,7 @@ describe("MathDegree", () => { }); it("should create a MathDegree with correct root key with child", () => { - const mathDegree = new MathDegree(new MathRun("2")); + const mathDegree = new MathDegree([new MathRun("2")]); const tree = new Formatter().format(mathDegree); expect(tree).to.deep.equal({ diff --git a/src/file/paragraph/math/radical/math-degree.ts b/src/file/paragraph/math/radical/math-degree.ts index 402ee8ffda..79923bbde8 100644 --- a/src/file/paragraph/math/radical/math-degree.ts +++ b/src/file/paragraph/math/radical/math-degree.ts @@ -3,11 +3,13 @@ import { XmlComponent } from "file/xml-components"; import { MathComponent } from "../math-component"; export class MathDegree extends XmlComponent { - constructor(child?: MathComponent) { + constructor(children?: MathComponent[]) { super("m:deg"); - if (!!child) { - this.root.push(child); + if (!!children) { + for (const child of children) { + this.root.push(child); + } } } } diff --git a/src/file/paragraph/math/radical/math-radical.spec.ts b/src/file/paragraph/math/radical/math-radical.spec.ts index 7d7d7c4225..e388edece4 100644 --- a/src/file/paragraph/math/radical/math-radical.spec.ts +++ b/src/file/paragraph/math/radical/math-radical.spec.ts @@ -9,8 +9,8 @@ describe("MathRadical", () => { describe("#constructor()", () => { it("should create a MathRadical with correct root key", () => { const mathRadical = new MathRadical({ - child: new MathRun("e"), - degree: new MathRun("2"), + children: [new MathRun("e")], + degree: [new MathRun("2")], }); const tree = new Formatter().format(mathRadical); diff --git a/src/file/paragraph/math/radical/math-radical.ts b/src/file/paragraph/math/radical/math-radical.ts index 76fc2dc7ca..1469867a5f 100644 --- a/src/file/paragraph/math/radical/math-radical.ts +++ b/src/file/paragraph/math/radical/math-radical.ts @@ -7,8 +7,8 @@ import { MathDegree } from "./math-degree"; import { MathRadicalProperties } from "./math-radical-properties"; export interface IMathRadicalOptions { - readonly child: MathComponent; - readonly degree?: MathComponent; + readonly children: MathComponent[]; + readonly degree?: MathComponent[]; } export class MathRadical extends XmlComponent { @@ -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.child)); + 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.spec.ts b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.spec.ts index 956a2ff445..20d00a639d 100644 --- a/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.spec.ts +++ b/src/file/paragraph/math/script/pre-sub-super-script/math-pre-sub-super-script-function.spec.ts @@ -9,9 +9,9 @@ describe("MathPreSubScript", () => { describe("#constructor()", () => { it("should create a MathPreSubScript with correct root key", () => { const mathPreSubScript = new MathPreSubSuperScript({ - child: new MathRun("e"), - subScript: new MathRun("2"), - superScript: new MathRun("5"), + children: [new MathRun("e")], + subScript: [new MathRun("2")], + superScript: [new MathRun("5")], }); const tree = new Formatter().format(mathPreSubScript); 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 a0bdc321a0..3a58675b0f 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 @@ -6,9 +6,9 @@ import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n- import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties"; export interface IMathPreSubSuperScriptOptions { - readonly child: MathComponent; - readonly subScript: MathComponent; - readonly superScript: MathComponent; + readonly children: MathComponent[]; + readonly subScript: MathComponent[]; + readonly superScript: MathComponent[]; } export class MathPreSubSuperScript extends XmlComponent { @@ -16,7 +16,7 @@ export class MathPreSubSuperScript extends XmlComponent { super("m:sPre"); this.root.push(new MathPreSubSuperScriptProperties()); - this.root.push(new MathBase(options.child)); + this.root.push(new MathBase(options.children)); this.root.push(new MathSubScriptElement(options.subScript)); this.root.push(new MathSuperScriptElement(options.superScript)); } diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts index dd33598d81..a3ea8d680c 100644 --- a/src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function.spec.ts @@ -9,8 +9,8 @@ describe("MathSubScript", () => { describe("#constructor()", () => { it("should create a MathSubScript with correct root key", () => { const mathSubScript = new MathSubScript({ - child: new MathRun("e"), - subScript: new MathRun("2"), + children: [new MathRun("e")], + subScript: [new MathRun("2")], }); const tree = new Formatter().format(mathSubScript); diff --git a/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts b/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts index a5c26cd06c..319d4d1f1a 100644 --- a/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts +++ b/src/file/paragraph/math/script/sub-script/math-sub-script-function.ts @@ -6,8 +6,8 @@ import { MathBase, MathSubScriptElement } from "../../n-ary"; import { MathSubScriptProperties } from "./math-sub-script-function-properties"; export interface IMathSubScriptOptions { - readonly child: MathComponent; - readonly subScript: MathComponent; + readonly children: MathComponent[]; + readonly subScript: MathComponent[]; } export class MathSubScript extends XmlComponent { @@ -15,7 +15,7 @@ export class MathSubScript extends XmlComponent { super("m:sSub"); this.root.push(new MathSubScriptProperties()); - this.root.push(new MathBase(options.child)); + this.root.push(new MathBase(options.children)); this.root.push(new MathSubScriptElement(options.subScript)); } } diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts index 5e7f976db7..68a86fb26b 100644 --- a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.spec.ts @@ -9,9 +9,9 @@ describe("MathSubScript", () => { describe("#constructor()", () => { it("should create a MathSubScript with correct root key", () => { const mathSubScript = new MathSubSuperScript({ - child: new MathRun("e"), - subScript: new MathRun("2"), - superScript: new MathRun("5"), + children: [new MathRun("e")], + subScript: [new MathRun("2")], + superScript: [new MathRun("5")], }); const tree = new Formatter().format(mathSubScript); diff --git a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts index 91bdfe6781..c382c9ff4c 100644 --- a/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts +++ b/src/file/paragraph/math/script/sub-super-script/math-sub-super-script-function.ts @@ -6,9 +6,9 @@ import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n- import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties"; export interface IMathSubSuperScriptOptions { - readonly child: MathComponent; - readonly subScript: MathComponent; - readonly superScript: MathComponent; + readonly children: MathComponent[]; + readonly subScript: MathComponent[]; + readonly superScript: MathComponent[]; } export class MathSubSuperScript extends XmlComponent { @@ -16,7 +16,7 @@ export class MathSubSuperScript extends XmlComponent { super("m:sSubSup"); this.root.push(new MathSubSuperScriptProperties()); - this.root.push(new MathBase(options.child)); + this.root.push(new MathBase(options.children)); this.root.push(new MathSubScriptElement(options.subScript)); this.root.push(new MathSuperScriptElement(options.superScript)); } diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts b/src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts index 6e6beb5e04..ae3740360b 100644 --- a/src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts +++ b/src/file/paragraph/math/script/super-script/math-super-script-function.spec.ts @@ -9,8 +9,8 @@ describe("MathSuperScript", () => { describe("#constructor()", () => { it("should create a MathSuperScript with correct root key", () => { const mathSuperScript = new MathSuperScript({ - child: new MathRun("e"), - superScript: new MathRun("2"), + children: [new MathRun("e")], + superScript: [new MathRun("2")], }); const tree = new Formatter().format(mathSuperScript); diff --git a/src/file/paragraph/math/script/super-script/math-super-script-function.ts b/src/file/paragraph/math/script/super-script/math-super-script-function.ts index d48ece6985..eeffdf124a 100644 --- a/src/file/paragraph/math/script/super-script/math-super-script-function.ts +++ b/src/file/paragraph/math/script/super-script/math-super-script-function.ts @@ -6,8 +6,8 @@ import { MathBase, MathSuperScriptElement } from "../../n-ary"; import { MathSuperScriptProperties } from "./math-super-script-function-properties"; export interface IMathSuperScriptOptions { - readonly child: MathComponent; - readonly superScript: MathComponent; + readonly children: MathComponent[]; + readonly superScript: MathComponent[]; } export class MathSuperScript extends XmlComponent { @@ -15,7 +15,7 @@ export class MathSuperScript extends XmlComponent { super("m:sSup"); this.root.push(new MathSuperScriptProperties()); - this.root.push(new MathBase(options.child)); + this.root.push(new MathBase(options.children)); this.root.push(new MathSuperScriptElement(options.superScript)); } } From 19d9619785a7c9c40d2a75e22361d3c70620e6fd Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Tue, 13 Oct 2020 03:00:14 +0100 Subject: [PATCH 8/8] Add more math documentation --- demo/55-math.ts | 30 +++++---- docs/usage/math.md | 155 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 164 insertions(+), 21 deletions(-) diff --git a/demo/55-math.ts b/demo/55-math.ts index 3dc6c1a17c..2a240986d0 100644 --- a/demo/55-math.ts +++ b/demo/55-math.ts @@ -44,19 +44,23 @@ doc.addSection({ }), ], }), - // new Paragraph({ - // children: [ - // new MathFraction({ - // numerator: [ - // new MathRun("1"), - // new MathRadical({ - // children: [new MathRun("2")], - // }), - // ], - // denominator: [new MathRun("2")], - // }), - // ], - // }), + new Paragraph({ + children: [ + new Math({ + children: [ + new MathFraction({ + numerator: [ + new MathRun("1"), + new MathRadical({ + children: [new MathRun("2")], + }), + ], + denominator: [new MathRun("2")], + }), + ], + }), + ], + }), new Paragraph({ children: [ new Math({ diff --git a/docs/usage/math.md b/docs/usage/math.md index e38f393ac9..1e8ab4f894 100644 --- a/docs/usage/math.md +++ b/docs/usage/math.md @@ -4,9 +4,10 @@ ## Intro -- To add math, create a `Math` object -- Add `MathComponents` inside `Math` -- `MathComponents` can have nested `MathComponents` inside. e.g. A fraction where the numerator is a square root, and the demoninator as another fraction. More on `MathComponents` below +1. To add math, create a `Math` object +2. Add `MathComponents` inside `Math` +3. `MathComponents` can have nested `MathComponents` inside. e.g. A fraction where the numerator is a square root, and the demoninator as another fraction. More on `MathComponents` below +4. Make sure to add the `Math` object inside a `Paragraph` ## Example @@ -76,7 +77,7 @@ new MathFraction({ numerator: [ new MathRun("1"), new MathRadical({ - child: [new MathRun("2")], + children: [new MathRun("2")], }), ], denominator: [new MathRun("2")], @@ -108,19 +109,157 @@ A `MathComponent` for `Σ`. It can take a `superScript` and/or `subScript` as ar ```ts new MathSum({ - child: [new MathRun("i")], + children: [new MathRun("i")], }), ``` ```ts new MathSum({ - child: [ + children: [ new MathSuperScript({ - child: new MathRun("e"), - superScript: new MathRun("2"), + children: [new MathRun("e")], + superScript: [new MathRun("2")], }) ], subScript: [new MathRun("i")], superScript: [new MathRun("10")], }), ``` + +### Radicals + +A `MathComponent` for the `√` symbol. Examples include, square root, cube root etc. There is an optional `degree` parameter to specify the number of times the radicand is multiplied by itself. For example, `3` for cube root. + +```ts +new MathRadical({ + children: [new MathRun("2")], +}), +``` + +Cube root example: + +```ts +new MathRadical({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + new MathRun('+ 1'), + ], + degree: [new MathRun("3")], +}), +``` + +### Super Script + +`MathSuperScripts` are the little numbers written to the top right of numbers or variables. It means the exponent or power if written by itself with the number or variable. + +```ts +new MathSuperScript({ + children: [new MathRun("x")], + superScript: [new MathRun("2")], +}), +``` + +An example with cosine: + +```ts +new MathSuperScript({ + children: [new MathRun("cos")], + superScript: [new MathRun("-1")], +}), +``` + +### Sub Script + +`MathSubScripts` are similar to `MathSuperScripts`, except the little number is written below. + +```ts +new MathSubScript({ + children: [new MathRun("F")], + subScript: [new MathRun("n-1")], +}), +``` + +### Sub-Super Script + +`MathSubSuperScripts` are a combination of both `MathSuperScript` and `MathSubScript`. + +```ts +new MathSubSuperScript({ + children: [new MathRun("test")], + superScript: [new MathRun("hello")], + subScript: [new MathRun("world")], +}), +``` + +### Function + +`MathFunctions` are a way of describing what happens to an input variable, in order to get the output result. It takes a `name` parameter to specify the name of the function. + +```ts +new MathFunction({ + name: [ + new MathSuperScript({ + children: [new MathRun("cos")], + superScript: [new MathRun("-1")], + }), + ], + children: [new MathRun("100")], +}), +``` + +### Brackets + +#### Square brackets + +```ts +new MathSquareBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], +}), +``` + +#### Round brackets + +```ts +new MathRoundBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], +}), +``` + +#### Curly brackets + +```ts +new MathCurlyBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], +}), +``` + +#### Angled brackets + +```ts +new MathAngledBrackets({ + children: [ + new MathFraction({ + numerator: [new MathRun("1")], + denominator: [new MathRun("2")], + }), + ], +}), +```