Merge branch 'master' of github.com:dolanmiu/docx into Numbering

# Conflicts:
#	src/file/paragraph/run/run.ts
This commit is contained in:
Forman
2019-08-13 10:40:49 +03:00
156 changed files with 3416 additions and 2960 deletions

View File

@ -1,22 +1,23 @@
// http://officeopenxml.com/WPalignment.php
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export enum AlignmentOptions {
export enum AlignmentType {
START = "start",
END = "end",
CENTER = "center",
BOTH = "both",
JUSTIFIED = "both",
DISTRIBUTE = "distribute",
LEFT = "left",
RIGHT = "right",
}
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentOptions }> {
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentType }> {
protected readonly xmlKeys = { val: "w:val" };
}
export class Alignment extends XmlComponent {
constructor(type: AlignmentOptions) {
constructor(type: AlignmentType) {
super("w:jc");
this.root.push(new AlignmentAttributes({ val: type }));
}

View File

@ -0,0 +1,17 @@
import { XmlAttributeComponent } from "file/xml-components";
export interface IBorderAttributesProperties {
readonly color: string;
readonly space: number;
readonly val: string;
readonly sz: number;
}
export class BorderAttributes extends XmlAttributeComponent<IBorderAttributesProperties> {
protected readonly xmlKeys = {
val: "w:val",
color: "w:color",
space: "w:space",
sz: "w:sz",
};
}

View File

@ -35,8 +35,8 @@ describe("ThematicBreak", () => {
"w:bottom": {
_attr: {
"w:color": "auto",
"w:space": "1",
"w:sz": "6",
"w:space": 1,
"w:sz": 6,
"w:val": "single",
},
},

View File

@ -1,63 +1,70 @@
// http://officeopenxml.com/WPborders.php
import { Attributes, XmlComponent } from "file/xml-components";
import { XmlComponent } from "file/xml-components";
import { BorderAttributes } from "./border-attributes";
interface IBorderPropertyOptions {
readonly color: string;
readonly space: number;
readonly value: string;
readonly size: number;
}
export interface IBorderOptions {
readonly top?: IBorderPropertyOptions;
readonly bottom?: IBorderPropertyOptions;
readonly left?: IBorderPropertyOptions;
readonly right?: IBorderPropertyOptions;
}
class BorderProperty extends XmlComponent {
public setProperties(color: string, space: string, value: string, size: string): XmlComponent {
const attrs = new Attributes({
color: color,
space: space,
val: value,
sz: size,
constructor(rootKey: string, options: IBorderPropertyOptions = { color: "auto", space: 1, value: "single", size: 6 }) {
super(rootKey);
const attrs = new BorderAttributes({
color: options.color,
space: options.space,
val: options.value,
sz: options.size,
});
this.root.push(attrs);
return this;
}
}
export class Border extends XmlComponent {
constructor() {
constructor(options: IBorderOptions) {
super("w:pBdr");
}
public addTopBorder(color: string = "auto", space: string = "1", value: string = "single", size: string = "6"): XmlComponent {
const top = new BorderProperty("w:top");
top.setProperties(color, space, value, size);
this.root.push(top);
if (options.top !== undefined) {
const borderProperty = new BorderProperty("w:top", options.top);
this.root.push(borderProperty);
}
return this;
}
if (options.bottom !== undefined) {
const borderProperty = new BorderProperty("w:bottom", options.bottom);
this.root.push(borderProperty);
}
public addBottomBorder(color: string = "auto", space: string = "1", value: string = "single", size: string = "6"): XmlComponent {
const bottom = new BorderProperty("w:bottom");
bottom.setProperties(color, space, value, size);
this.root.push(bottom);
if (options.left !== undefined) {
const borderProperty = new BorderProperty("w:left", options.left);
this.root.push(borderProperty);
}
return this;
}
public addLeftBorder(color: string = "auto", space: string = "1", value: string = "single", size: string = "6"): XmlComponent {
const left = new BorderProperty("w:left");
left.setProperties(color, space, value, size);
this.root.push(left);
return this;
}
public addRightBorder(color: string = "auto", space: string = "1", value: string = "single", size: string = "6"): XmlComponent {
const right = new BorderProperty("w:right");
right.setProperties(color, space, value, size);
this.root.push(right);
return this;
if (options.right !== undefined) {
const borderProperty = new BorderProperty("w:right", options.right);
this.root.push(borderProperty);
}
}
}
export class ThematicBreak extends XmlComponent {
constructor() {
super("w:pBdr");
const bottom = new BorderProperty("w:bottom");
bottom.setProperties("auto", "1", "single", "6");
const bottom = new BorderProperty("w:bottom", {
color: "auto",
space: 1,
value: "single",
size: 6,
});
this.root.push(bottom);
}
}

View File

@ -15,7 +15,7 @@ class Break extends XmlComponent {
export class PageBreak extends Run {
constructor() {
super();
super({});
this.root.push(new Break());
}
}

View File

@ -1,5 +1,15 @@
import { Attributes, XmlComponent } from "file/xml-components";
export enum HeadingLevel {
HEADING_1 = "Heading1",
HEADING_2 = "Heading2",
HEADING_3 = "Heading3",
HEADING_4 = "Heading4",
HEADING_5 = "Heading5",
HEADING_6 = "Heading6",
TITLE = "Title",
}
export class Style extends XmlComponent {
public readonly styleId: string;

View File

@ -1,12 +1,8 @@
// tslint:disable:object-literal-key-quotes
import { assert, expect } from "chai";
import { Formatter } from "export/formatter";
import { assert } from "chai";
import { ImageParagraph } from "./image";
import { EMPTY_OBJECT } from "file/xml-components";
describe("Image", () => {
let image: ImageParagraph;
@ -40,190 +36,4 @@ describe("Image", () => {
assert.isTrue(true);
});
});
describe("#scale()", () => {
it("should set the scale of the object properly", () => {
image.scale(2);
const tree = new Formatter().format(image);
expect(tree).to.deep.equal({
"w:p": [
{
"w:r": [
{
"w:drawing": [
{
"wp:inline": [
{
_attr: {
distB: 0,
distL: 0,
distR: 0,
distT: 0,
},
},
{
"wp:extent": {
_attr: {
cx: 20,
cy: 20,
},
},
},
{
"wp:effectExtent": {
_attr: {
b: 0,
l: 0,
r: 0,
t: 0,
},
},
},
{
"wp:docPr": {
_attr: {
descr: "",
id: 0,
name: "",
},
},
},
{
"wp:cNvGraphicFramePr": [
{
"a:graphicFrameLocks": {
_attr: {
noChangeAspect: 1,
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
},
},
},
],
},
{
"a:graphic": [
{
_attr: {
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
},
},
{
"a:graphicData": [
{
_attr: {
uri: "http://schemas.openxmlformats.org/drawingml/2006/picture",
},
},
{
"pic:pic": [
{
_attr: {
"xmlns:pic":
"http://schemas.openxmlformats.org/drawingml/2006/picture",
},
},
{
"pic:nvPicPr": [
{
"pic:cNvPr": {
_attr: {
desc: "",
id: 0,
name: "",
},
},
},
{
"pic:cNvPicPr": [
{
"a:picLocks": {
_attr: {
noChangeArrowheads: 1,
noChangeAspect: 1,
},
},
},
],
},
],
},
{
"pic:blipFill": [
{
"a:blip": {
_attr: {
cstate: "none",
"r:embed": "rId{test.png}",
},
},
},
{
"a:srcRect": EMPTY_OBJECT,
},
{
"a:stretch": [
{
"a:fillRect": EMPTY_OBJECT,
},
],
},
],
},
{
"pic:spPr": [
{
_attr: {
bwMode: "auto",
},
},
{
"a:xfrm": [
{
"a:ext": {
_attr: {
cx: 10,
cy: 10,
},
},
},
{
"a:off": {
_attr: {
x: 0,
y: 0,
},
},
},
],
},
{
"a:prstGeom": [
{
_attr: {
prst: "rect",
},
},
{
"a:avLst": EMPTY_OBJECT,
},
],
},
],
},
],
},
],
},
],
},
],
},
],
},
],
},
],
});
});
});
});

View File

@ -7,15 +7,11 @@ export class ImageParagraph extends Paragraph {
private readonly pictureRun: PictureRun;
constructor(imageData: IMediaData, drawingOptions?: IDrawingOptions) {
super();
super({});
this.pictureRun = new PictureRun(imageData, drawingOptions);
this.root.push(this.pictureRun);
}
public scale(factorX: number, factorY?: number): void {
this.pictureRun.scale(factorX, factorY);
}
public get Run(): PictureRun {
return this.pictureRun;
}

View File

@ -20,7 +20,10 @@ export class Hyperlink extends XmlComponent {
const attributes = new HyperlinkAttributes(props);
this.root.push(attributes);
this.textRun = new TextRun(text).style("Hyperlink");
this.textRun = new TextRun({
text: text,
style: "Hyperlink",
});
this.root.push(this.textRun);
}

View File

@ -9,12 +9,12 @@ describe("ParagraphOutlineLevel", () => {
describe("#constructor()", () => {
it("should create an outlineLevel with given value", () => {
outlineLevel = new OutlineLevel("0");
outlineLevel = new OutlineLevel(0);
const tree = new Formatter().format(outlineLevel);
expect(tree).to.deep.equal({
"w:outlineLvl": {
_attr: {
"w:val": "0",
"w:val": 0,
},
},
});

View File

@ -2,11 +2,9 @@
import { Attributes, XmlComponent } from "file/xml-components";
export class OutlineLevel extends XmlComponent {
public readonly level: string;
constructor(level: string) {
constructor(public readonly level: number) {
super("w:outlineLvl");
this.level = level;
this.root.push(
new Attributes({
val: level,

View File

@ -1,22 +1,16 @@
import { assert, expect } from "chai";
import { Formatter } from "export/formatter";
import * as file from "file";
import { Numbering } from "../numbering";
import { LeaderType } from "./formatting";
import { EMPTY_OBJECT } from "file/xml-components";
import { Numbering } from "../numbering";
import { AlignmentType, HeadingLevel, LeaderType } from "./formatting";
import { Paragraph } from "./paragraph";
describe("Paragraph", () => {
let paragraph: file.Paragraph;
beforeEach(() => {
paragraph = new file.Paragraph();
});
describe("#constructor()", () => {
it("should create valid JSON", () => {
const paragraph = new Paragraph("");
const stringifiedJson = JSON.stringify(paragraph);
try {
@ -28,28 +22,18 @@ describe("Paragraph", () => {
});
it("should create have valid properties", () => {
const paragraph = new Paragraph("");
const stringifiedJson = JSON.stringify(paragraph);
const newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.root[0].rootKey, "w:pPr");
});
});
describe("#createTextRun", () => {
it("should add a new run to the paragraph and return it", () => {
const run = paragraph.createTextRun("this is a test run");
expect(run).to.be.instanceof(file.TextRun);
const tree = new Formatter().format(paragraph)["w:p"];
expect(tree)
.to.be.an("array")
.which.includes({
"w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "this is a test run"] }],
});
});
});
describe("#heading1()", () => {
it("should add heading style to JSON", () => {
paragraph.heading1();
const paragraph = new Paragraph({
heading: HeadingLevel.HEADING_1,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -63,7 +47,9 @@ describe("Paragraph", () => {
describe("#heading2()", () => {
it("should add heading style to JSON", () => {
paragraph.heading2();
const paragraph = new Paragraph({
heading: HeadingLevel.HEADING_2,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -77,7 +63,9 @@ describe("Paragraph", () => {
describe("#heading3()", () => {
it("should add heading style to JSON", () => {
paragraph.heading3();
const paragraph = new Paragraph({
heading: HeadingLevel.HEADING_3,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -91,7 +79,9 @@ describe("Paragraph", () => {
describe("#heading4()", () => {
it("should add heading style to JSON", () => {
paragraph.heading4();
const paragraph = new Paragraph({
heading: HeadingLevel.HEADING_4,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -105,7 +95,9 @@ describe("Paragraph", () => {
describe("#heading5()", () => {
it("should add heading style to JSON", () => {
paragraph.heading5();
const paragraph = new Paragraph({
heading: HeadingLevel.HEADING_5,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -119,7 +111,9 @@ describe("Paragraph", () => {
describe("#heading6()", () => {
it("should add heading style to JSON", () => {
paragraph.heading6();
const paragraph = new Paragraph({
heading: HeadingLevel.HEADING_6,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -133,7 +127,9 @@ describe("Paragraph", () => {
describe("#title()", () => {
it("should add title style to JSON", () => {
paragraph.title();
const paragraph = new Paragraph({
heading: HeadingLevel.TITLE,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -147,7 +143,9 @@ describe("Paragraph", () => {
describe("#center()", () => {
it("should add center alignment to JSON", () => {
paragraph.center();
const paragraph = new Paragraph({
alignment: AlignmentType.CENTER,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -161,7 +159,9 @@ describe("Paragraph", () => {
describe("#left()", () => {
it("should add left alignment to JSON", () => {
paragraph.left();
const paragraph = new Paragraph({
alignment: AlignmentType.LEFT,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -175,7 +175,9 @@ describe("Paragraph", () => {
describe("#right()", () => {
it("should add right alignment to JSON", () => {
paragraph.right();
const paragraph = new Paragraph({
alignment: AlignmentType.RIGHT,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -189,7 +191,9 @@ describe("Paragraph", () => {
describe("#start()", () => {
it("should add start alignment to JSON", () => {
paragraph.start();
const paragraph = new Paragraph({
alignment: AlignmentType.START,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -203,7 +207,9 @@ describe("Paragraph", () => {
describe("#end()", () => {
it("should add end alignment to JSON", () => {
paragraph.end();
const paragraph = new Paragraph({
alignment: AlignmentType.END,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -217,7 +223,9 @@ describe("Paragraph", () => {
describe("#distribute()", () => {
it("should add distribute alignment to JSON", () => {
paragraph.distribute();
const paragraph = new Paragraph({
alignment: AlignmentType.DISTRIBUTE,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -231,7 +239,9 @@ describe("Paragraph", () => {
describe("#justified()", () => {
it("should add justified alignment to JSON", () => {
paragraph.justified();
const paragraph = new Paragraph({
alignment: AlignmentType.JUSTIFIED,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -245,7 +255,11 @@ describe("Paragraph", () => {
describe("#maxRightTabStop()", () => {
it("should add maxRightTabStop to JSON", () => {
paragraph.maxRightTabStop();
const paragraph = new Paragraph({
tabStop: {
maxRight: {},
},
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -272,7 +286,14 @@ describe("Paragraph", () => {
describe("#leftTabStop()", () => {
it("should add leftTabStop to JSON", () => {
paragraph.leftTabStop(100, LeaderType.HYPHEN);
const paragraph = new Paragraph({
tabStop: {
left: {
position: 100,
leader: LeaderType.HYPHEN,
},
},
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -300,7 +321,14 @@ describe("Paragraph", () => {
describe("#rightTabStop()", () => {
it("should add rightTabStop to JSON", () => {
paragraph.rightTabStop(100, LeaderType.DOT);
const paragraph = new Paragraph({
tabStop: {
right: {
position: 100,
leader: LeaderType.DOT,
},
},
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -328,7 +356,14 @@ describe("Paragraph", () => {
describe("#centerTabStop()", () => {
it("should add centerTabStop to JSON", () => {
paragraph.centerTabStop(100, LeaderType.MIDDLE_DOT);
const paragraph = new Paragraph({
tabStop: {
center: {
position: 100,
leader: LeaderType.MIDDLE_DOT,
},
},
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -356,7 +391,9 @@ describe("Paragraph", () => {
describe("#contextualSpacing()", () => {
it("should add contextualSpacing to JSON, and set 1 if true", () => {
paragraph.contextualSpacing(true);
const paragraph = new Paragraph({
contextualSpacing: true,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -366,23 +403,13 @@ describe("Paragraph", () => {
],
});
});
it("should add contextualSpacing to JSON, and set 0 if false", () => {
paragraph.contextualSpacing(false);
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
{
"w:pPr": [{ "w:contextualSpacing": { _attr: { "w:val": 0 } } }],
},
],
});
});
});
describe("#thematicBreak()", () => {
it("should add thematic break to JSON", () => {
paragraph.thematicBreak();
const paragraph = new Paragraph({
thematicBreak: true,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -395,8 +422,8 @@ describe("Paragraph", () => {
_attr: {
"w:val": "single",
"w:color": "auto",
"w:space": "1",
"w:sz": "6",
"w:space": 1,
"w:sz": 6,
},
},
},
@ -411,9 +438,22 @@ describe("Paragraph", () => {
describe("#paragraphBorders()", () => {
it("should add a left and right border to a paragraph", () => {
paragraph.createBorder();
paragraph.Borders.addLeftBorder();
paragraph.Borders.addRightBorder();
const paragraph = new Paragraph({
border: {
left: {
color: "auto",
space: 1,
value: "single",
size: 6,
},
right: {
color: "auto",
space: 1,
value: "single",
size: 6,
},
},
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -425,8 +465,8 @@ describe("Paragraph", () => {
"w:left": {
_attr: {
"w:color": "auto",
"w:space": "1",
"w:sz": "6",
"w:space": 1,
"w:sz": 6,
"w:val": "single",
},
},
@ -435,8 +475,8 @@ describe("Paragraph", () => {
"w:right": {
_attr: {
"w:color": "auto",
"w:space": "1",
"w:sz": "6",
"w:space": 1,
"w:sz": 6,
"w:val": "single",
},
},
@ -452,6 +492,7 @@ describe("Paragraph", () => {
describe("#pageBreak()", () => {
it("should add page break to JSON", () => {
const paragraph = new Paragraph({});
paragraph.pageBreak();
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
@ -466,7 +507,9 @@ describe("Paragraph", () => {
describe("#pageBreakBefore()", () => {
it("should add page break before to JSON", () => {
paragraph.pageBreakBefore();
const paragraph = new Paragraph({
pageBreakBefore: true,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -484,7 +527,11 @@ describe("Paragraph", () => {
describe("#bullet()", () => {
it("should default to 0 indent level if no bullet was specified", () => {
paragraph.bullet();
const paragraph = new Paragraph({
bullet: {
level: 0,
},
});
const tree = new Formatter().format(paragraph);
expect(tree)
.to.have.property("w:p")
@ -500,7 +547,11 @@ describe("Paragraph", () => {
});
it("should add list paragraph style to JSON", () => {
paragraph.bullet(0);
const paragraph = new Paragraph({
bullet: {
level: 0,
},
});
const tree = new Formatter().format(paragraph);
expect(tree)
.to.have.property("w:p")
@ -516,7 +567,11 @@ describe("Paragraph", () => {
});
it("it should add numbered properties", () => {
paragraph.bullet(1);
const paragraph = new Paragraph({
bullet: {
level: 1,
},
});
const tree = new Formatter().format(paragraph);
expect(tree)
.to.have.property("w:p")
@ -539,7 +594,12 @@ describe("Paragraph", () => {
numberedAbstract.createLevel(0, "lowerLetter", "%1)", "start");
const letterNumbering = numbering.createConcreteNumbering(numberedAbstract);
paragraph.setNumbering(letterNumbering, 0);
const paragraph = new Paragraph({
numbering: {
num: letterNumbering,
level: 0,
},
});
const tree = new Formatter().format(paragraph);
expect(tree)
.to.have.property("w:p")
@ -560,7 +620,12 @@ describe("Paragraph", () => {
numberedAbstract.createLevel(0, "lowerLetter", "%1)", "start");
const letterNumbering = numbering.createConcreteNumbering(numberedAbstract);
paragraph.setNumbering(letterNumbering, 0);
const paragraph = new Paragraph({
numbering: {
num: letterNumbering,
level: 0,
},
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -582,7 +647,9 @@ describe("Paragraph", () => {
describe("#style", () => {
it("should set the paragraph style to the given styleId", () => {
paragraph.style("myFancyStyle");
const paragraph = new Paragraph({
style: "myFancyStyle",
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -596,7 +663,9 @@ describe("Paragraph", () => {
describe("#indent", () => {
it("should set the paragraph indent to the given values", () => {
paragraph.indent({ left: 720 });
const paragraph = new Paragraph({
indent: { left: 720 },
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -610,7 +679,9 @@ describe("Paragraph", () => {
describe("#spacing", () => {
it("should set the paragraph spacing to the given values", () => {
paragraph.spacing({ before: 90, line: 50 });
const paragraph = new Paragraph({
spacing: { before: 90, line: 50 },
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
@ -624,7 +695,9 @@ describe("Paragraph", () => {
describe("#keepLines", () => {
it("should set the paragraph keepLines sub-component", () => {
paragraph.keepLines();
const paragraph = new Paragraph({
keepLines: true,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [{ "w:pPr": [{ "w:keepLines": EMPTY_OBJECT }] }],
@ -634,7 +707,9 @@ describe("Paragraph", () => {
describe("#keepNext", () => {
it("should set the paragraph keepNext sub-component", () => {
paragraph.keepNext();
const paragraph = new Paragraph({
keepNext: true,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [{ "w:pPr": [{ "w:keepNext": EMPTY_OBJECT }] }],
@ -644,7 +719,9 @@ describe("Paragraph", () => {
describe("#bidirectional", () => {
it("set paragraph right to left layout", () => {
paragraph.bidirectional();
const paragraph = new Paragraph({
bidirectional: true,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [{ "w:pPr": [{ "w:bidi": EMPTY_OBJECT }] }],
@ -654,12 +731,14 @@ describe("Paragraph", () => {
describe("#outlineLevel", () => {
it("should set paragraph outline level to the given value", () => {
paragraph.outlineLevel("0");
const paragraph = new Paragraph({
outlineLevel: 0,
});
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
{
"w:pPr": [{ "w:outlineLvl": { _attr: { "w:val": "0" } } }],
"w:pPr": [{ "w:outlineLvl": { _attr: { "w:val": 0 } } }],
},
],
});

View File

@ -4,43 +4,172 @@ import { Image } from "file/media";
import { Num } from "file/numbering/num";
import { XmlComponent } from "file/xml-components";
import { Alignment, AlignmentOptions } from "./formatting/alignment";
import { Alignment, AlignmentType } from "./formatting/alignment";
import { Bidirectional } from "./formatting/bidirectional";
import { Border, ThematicBreak } from "./formatting/border";
import { IBorderOptions, ThematicBreak } from "./formatting/border";
import { IIndentAttributesProperties, Indent } from "./formatting/indent";
import { KeepLines, KeepNext } from "./formatting/keep";
import { PageBreak, PageBreakBefore } from "./formatting/page-break";
import { ContextualSpacing, ISpacingProperties, Spacing } from "./formatting/spacing";
import { Style } from "./formatting/style";
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 { ParagraphProperties } from "./properties";
import { PictureRun, Run, SequentialIdentifier, TextRun } from "./run";
interface ITabStopOptions {
readonly position: number;
readonly leader?: LeaderType;
}
export interface IParagraphOptions {
readonly text?: string;
readonly border?: IBorderOptions;
readonly spacing?: ISpacingProperties;
readonly outlineLevel?: number;
readonly alignment?: AlignmentType;
readonly heading?: HeadingLevel;
readonly bidirectional?: boolean;
readonly thematicBreak?: boolean;
readonly pageBreakBefore?: boolean;
readonly contextualSpacing?: boolean;
readonly indent?: IIndentAttributesProperties;
readonly keepLines?: boolean;
readonly keepNext?: boolean;
readonly tabStop?: {
readonly left?: ITabStopOptions;
readonly right?: ITabStopOptions;
readonly maxRight?: {
readonly leader?: LeaderType;
};
readonly center?: ITabStopOptions;
};
readonly style?: string;
readonly bullet?: {
readonly level: number;
};
readonly numbering?: {
readonly num: Num;
readonly level: number;
readonly custom?: boolean;
};
readonly children?: Array<TextRun | PictureRun | Hyperlink>;
}
export class Paragraph extends XmlComponent {
private readonly properties: ParagraphProperties;
constructor(text?: string) {
constructor(options: string | PictureRun | IParagraphOptions) {
super("w:p");
this.properties = new ParagraphProperties();
this.root.push(this.properties);
if (text !== undefined) {
this.root.push(new TextRun(text));
if (typeof options === "string") {
this.properties = new ParagraphProperties({});
this.root.push(this.properties);
this.root.push(new TextRun(options));
return;
}
}
public get paragraphProperties(): ParagraphProperties {
return this.properties;
}
if (options instanceof PictureRun) {
this.properties = new ParagraphProperties({});
this.root.push(this.properties);
this.root.push(options);
return;
}
public get Borders(): Border {
return this.properties.paragraphBorder;
}
this.properties = new ParagraphProperties({
border: options.border,
});
public createBorder(): Paragraph {
this.properties.createBorder();
return this;
this.root.push(this.properties);
if (options.text) {
this.root.push(new TextRun(options.text));
}
if (options.spacing) {
this.properties.push(new Spacing(options.spacing));
}
if (options.outlineLevel !== undefined) {
this.properties.push(new OutlineLevel(options.outlineLevel));
}
if (options.alignment) {
this.properties.push(new Alignment(options.alignment));
}
if (options.heading) {
this.properties.push(new Style(options.heading));
}
if (options.bidirectional) {
this.properties.push(new Bidirectional());
}
if (options.thematicBreak) {
this.properties.push(new ThematicBreak());
}
if (options.pageBreakBefore) {
this.properties.push(new PageBreakBefore());
}
if (options.contextualSpacing) {
this.properties.push(new ContextualSpacing(options.contextualSpacing));
}
if (options.indent) {
this.properties.push(new Indent(options.indent));
}
if (options.keepLines) {
this.properties.push(new KeepLines());
}
if (options.keepNext) {
this.properties.push(new KeepNext());
}
if (options.tabStop) {
if (options.tabStop.left) {
this.properties.push(new LeftTabStop(options.tabStop.left.position, options.tabStop.left.leader));
}
if (options.tabStop.right) {
this.properties.push(new RightTabStop(options.tabStop.right.position, options.tabStop.right.leader));
}
if (options.tabStop.maxRight) {
this.properties.push(new MaxRightTabStop(options.tabStop.maxRight.leader));
}
if (options.tabStop.center) {
this.properties.push(new CenterTabStop(options.tabStop.center.position, options.tabStop.center.leader));
}
}
if (options.style) {
this.properties.push(new Style(options.style));
}
if (options.bullet) {
this.properties.push(new Style("ListParagraph"));
this.properties.push(new NumberProperties(1, options.bullet.level));
}
if (options.numbering) {
if (!options.numbering.custom) {
this.properties.push(new Style("ListParagraph"));
}
this.properties.push(new NumberProperties(options.numbering.num.id, options.numbering.level));
}
if (options.children) {
for (const child of options.children) {
this.root.push(child);
}
}
}
public addRun(run: Run): Paragraph {
@ -61,12 +190,6 @@ export class Paragraph extends XmlComponent {
return this;
}
public createTextRun(text: string): TextRun {
const run = new TextRun(text);
this.addRun(run);
return run;
}
public addImage(image: Image): PictureRun {
const run = image.Run;
this.addRun(run);
@ -74,158 +197,11 @@ export class Paragraph extends XmlComponent {
return run;
}
public heading1(): Paragraph {
this.properties.push(new Style("Heading1"));
return this;
}
public heading2(): Paragraph {
this.properties.push(new Style("Heading2"));
return this;
}
public heading3(): Paragraph {
this.properties.push(new Style("Heading3"));
return this;
}
public heading4(): Paragraph {
this.properties.push(new Style("Heading4"));
return this;
}
public heading5(): Paragraph {
this.properties.push(new Style("Heading5"));
return this;
}
public heading6(): Paragraph {
this.properties.push(new Style("Heading6"));
return this;
}
public title(): Paragraph {
this.properties.push(new Style("Title"));
return this;
}
public center(): Paragraph {
this.properties.push(new Alignment(AlignmentOptions.CENTER));
return this;
}
public left(): Paragraph {
this.properties.push(new Alignment(AlignmentOptions.LEFT));
return this;
}
public right(): Paragraph {
this.properties.push(new Alignment(AlignmentOptions.RIGHT));
return this;
}
public start(): Paragraph {
this.properties.push(new Alignment(AlignmentOptions.START));
return this;
}
public end(): Paragraph {
this.properties.push(new Alignment(AlignmentOptions.END));
return this;
}
public distribute(): Paragraph {
this.properties.push(new Alignment(AlignmentOptions.DISTRIBUTE));
return this;
}
public justified(): Paragraph {
this.properties.push(new Alignment(AlignmentOptions.BOTH));
return this;
}
public thematicBreak(): Paragraph {
this.properties.push(new ThematicBreak());
return this;
}
public pageBreak(): Paragraph {
this.root.push(new PageBreak());
return this;
}
public pageBreakBefore(): Paragraph {
this.properties.push(new PageBreakBefore());
return this;
}
public maxRightTabStop(leader?: LeaderType): Paragraph {
this.properties.push(new MaxRightTabStop(leader));
return this;
}
public leftTabStop(position: number, leader?: LeaderType): Paragraph {
this.properties.push(new LeftTabStop(position, leader));
return this;
}
public rightTabStop(position: number, leader?: LeaderType): Paragraph {
this.properties.push(new RightTabStop(position, leader));
return this;
}
public centerTabStop(position: number, leader?: LeaderType): Paragraph {
this.properties.push(new CenterTabStop(position, leader));
return this;
}
public bullet(indentLevel: number = 0): Paragraph {
this.properties.push(new Style("ListParagraph"));
this.properties.push(new NumberProperties(1, indentLevel));
return this;
}
public setNumbering(numbering: Num, indentLevel: number): Paragraph {
this.properties.push(new Style("ListParagraph"));
this.properties.push(new NumberProperties(numbering.id, indentLevel));
return this;
}
public setCustomNumbering(numberId: number, indentLevel: number): Paragraph {
this.properties.push(new NumberProperties(numberId, indentLevel));
return this;
}
public style(styleId: string): Paragraph {
this.properties.push(new Style(styleId));
return this;
}
public indent(attrs: IIndentAttributesProperties): Paragraph {
this.properties.push(new Indent(attrs));
return this;
}
public spacing(params: ISpacingProperties): Paragraph {
this.properties.push(new Spacing(params));
return this;
}
public contextualSpacing(value: boolean): Paragraph {
this.properties.push(new ContextualSpacing(value));
return this;
}
public keepNext(): Paragraph {
this.properties.push(new KeepNext());
return this;
}
public keepLines(): Paragraph {
this.properties.push(new KeepLines());
return this;
}
public referenceFootnote(id: number): Paragraph {
this.root.push(new FootnoteReferenceRun(id));
return this;
@ -236,18 +212,8 @@ export class Paragraph extends XmlComponent {
return this;
}
public bidirectional(): Paragraph {
this.properties.push(new Bidirectional());
return this;
}
public addSequentialIdentifier(identifier: string): Paragraph {
this.root.push(new SequentialIdentifier(identifier));
return this;
}
public outlineLevel(level: string): Paragraph {
this.properties.push(new OutlineLevel(level));
return this;
}
}

View File

@ -1,17 +1,19 @@
// http://officeopenxml.com/WPparagraphProperties.php
import { IgnoreIfEmptyXmlComponent, XmlComponent } from "file/xml-components";
import { Border } from "./formatting/border";
import { Border, IBorderOptions } from "./formatting/border";
interface IParagraphPropertiesOptions {
readonly border?: IBorderOptions;
}
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
public readonly paragraphBorder: Border;
constructor() {
constructor(options: IParagraphPropertiesOptions) {
super("w:pPr");
this.paragraphBorder = new Border();
}
public createBorder(): void {
this.push(this.paragraphBorder);
if (options.border) {
this.push(new Border(options.border));
}
}
public push(item: XmlComponent): void {

View File

@ -113,7 +113,7 @@ export class Imprint extends XmlComponent {
}
}
export class Shadow extends XmlComponent {
/* export class Shadow extends XmlComponent {
constructor() {
super("w:shadow");
this.root.push(
@ -122,7 +122,7 @@ export class Shadow extends XmlComponent {
}),
);
}
}
} */
export class SmallCaps extends XmlComponent {
constructor() {
@ -178,3 +178,51 @@ export class RightToLeft extends XmlComponent {
);
}
}
export class Highlight extends XmlComponent {
constructor(color: string) {
super("w:highlight");
this.root.push(
new Attributes({
val: color,
}),
);
}
}
export class HighlightComplexScript extends XmlComponent {
constructor(color: string) {
super("w:highlightCs");
this.root.push(
new Attributes({
val: color,
}),
);
}
}
export class Shading extends XmlComponent {
constructor(value: string, fill: string, color: string) {
super("w:shd");
this.root.push(
new Attributes({
val: value,
fill: fill,
color: color,
}),
);
}
}
export class ShadowComplexScript extends XmlComponent {
constructor(value: string, fill: string, color: string) {
super("w:shdCs");
this.root.push(
new Attributes({
val: value,
fill: fill,
color: color,
}),
);
}
}

View File

@ -4,21 +4,15 @@ import { IMediaData } from "../../media/data";
import { Run } from "../run";
export class PictureRun extends Run {
private readonly drawing: Drawing;
constructor(imageData: IMediaData, drawingOptions?: IDrawingOptions) {
super();
super({});
if (imageData === undefined) {
throw new Error("imageData cannot be undefined");
}
this.drawing = new Drawing(imageData, drawingOptions);
const drawing = new Drawing(imageData, drawingOptions);
this.root.push(this.drawing);
}
public scale(factorX: number = 1, factorY: number = factorX): void {
this.drawing.scale(factorX, factorY);
this.root.push(drawing);
}
}

View File

@ -1,19 +1,17 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { ShadingType } from "file/table";
import { Run } from "./";
import { UnderlineType } from "./underline";
describe("Run", () => {
let run: Run;
beforeEach(() => {
run = new Run();
});
describe("#bold()", () => {
it("it should add bold to the properties", () => {
run.bold();
const run = new Run({
bold: true,
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [
@ -36,7 +34,9 @@ describe("Run", () => {
describe("#italics()", () => {
it("it should add italics to the properties", () => {
run.italics();
const run = new Run({
italics: true,
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [
@ -59,7 +59,9 @@ describe("Run", () => {
describe("#underline()", () => {
it("should default to 'single' and no color", () => {
run.underline();
const run = new Run({
underline: {},
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:u": { _attr: { "w:val": "single" } } }] }],
@ -67,7 +69,12 @@ describe("Run", () => {
});
it("should set the style type and color if given", () => {
run.underline("double", "990011");
const run = new Run({
underline: {
type: UnderlineType.DOUBLE,
color: "990011",
},
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:u": { _attr: { "w:val": "double", "w:color": "990011" } } }] }],
@ -77,7 +84,9 @@ describe("Run", () => {
describe("#smallCaps()", () => {
it("it should add smallCaps to the properties", () => {
run.smallCaps();
const run = new Run({
smallCaps: true,
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:smallCaps": {} }] }],
@ -87,7 +96,9 @@ describe("Run", () => {
describe("#caps()", () => {
it("it should add caps to the properties", () => {
run.allCaps();
const run = new Run({
allCaps: true,
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:caps": {} }] }],
@ -97,7 +108,9 @@ describe("Run", () => {
describe("#strike()", () => {
it("it should add strike to the properties", () => {
run.strike();
const run = new Run({
strike: true,
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:strike": { _attr: { "w:val": true } } }] }],
@ -107,7 +120,9 @@ describe("Run", () => {
describe("#doubleStrike()", () => {
it("it should add caps to the properties", () => {
run.doubleStrike();
const run = new Run({
doubleStrike: true,
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:dstrike": { _attr: { "w:val": true } } }] }],
@ -115,8 +130,65 @@ describe("Run", () => {
});
});
describe("#highlight()", () => {
it("it should add highlight to the properties", () => {
const run = new Run({
highlight: "005599",
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [
{
"w:rPr": [
{ "w:highlight": { _attr: { "w:val": "005599" } } },
{
"w:highlightCs": {
_attr: {
"w:val": "005599",
},
},
},
],
},
],
});
});
});
describe("#shadow()", () => {
it("it should add shadow to the properties", () => {
const run = new Run({
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [
{
"w:rPr": [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{
"w:shdCs": {
_attr: {
"w:val": "pct10",
"w:fill": "00FFFF",
"w:color": "FF0000",
},
},
},
],
},
],
});
});
});
describe("#break()", () => {
it("it should add break to the run", () => {
const run = new Run({});
run.break();
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
@ -127,6 +199,7 @@ describe("Run", () => {
describe("#tab()", () => {
it("it should add break to the run", () => {
const run = new Run({});
run.tab();
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
@ -136,12 +209,12 @@ describe("Run", () => {
});
describe("#font()", () => {
it("should allow chaining calls", () => {
expect(run.font("Times")).to.equal(run);
});
it("should set the font as named", () => {
run.font("Times");
const run = new Run({
font: {
name: "Times",
},
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [
@ -157,7 +230,9 @@ describe("Run", () => {
describe("#color", () => {
it("should set the run to the color given", () => {
run.color("001122");
const run = new Run({
color: "001122",
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:color": { _attr: { "w:val": "001122" } } }] }],
@ -167,7 +242,9 @@ describe("Run", () => {
describe("#size", () => {
it("should set the run to the given size", () => {
run.size(24);
const run = new Run({
size: 24,
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [
@ -181,7 +258,9 @@ describe("Run", () => {
describe("#rtl", () => {
it("should set the run to the RTL mode", () => {
run.rightToLeft();
const run = new Run({
rightToLeft: true,
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:rtl": { _attr: { "w:val": true } } }] }],
@ -191,6 +270,7 @@ describe("Run", () => {
describe("#numberOfTotalPages", () => {
it("should set the run to the RTL mode", () => {
const run = new Run({});
run.numberOfTotalPages();
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
@ -221,6 +301,7 @@ describe("Run", () => {
describe("#pageNumber", () => {
it("should set the run to the RTL mode", () => {
const run = new Run({});
run.pageNumber();
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
@ -236,7 +317,9 @@ describe("Run", () => {
describe("#style", () => {
it("should set the style to the given styleId", () => {
run.style("myRunStyle");
const run = new Run({
style: "myRunStyle",
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "myRunStyle" } } }] }],

View File

@ -1,4 +1,7 @@
// http://officeopenxml.com/WPtext.php
import { ShadingType } from "file/table";
import { XmlComponent } from "file/xml-components";
import { Break } from "./break";
import { Caps, SmallCaps } from "./caps";
import { Begin, End, Separate } from "./field";
@ -7,9 +10,13 @@ import {
BoldComplexScript,
Color,
DoubleStrike,
Highlight,
HighlightComplexScript,
Italics,
ItalicsComplexScript,
RightToLeft,
Shading,
ShadowComplexScript,
Size,
SizeComplexScript,
Strike,
@ -20,50 +27,113 @@ import { RunFonts } from "./run-fonts";
import { SubScript, SuperScript } from "./script";
import { Style } from "./style";
import { Tab } from "./tab";
import { Underline } from "./underline";
import { Underline, UnderlineType } from "./underline";
import { XmlComponent } from "file/xml-components";
export interface IRunOptions {
readonly bold?: true;
readonly italics?: true;
readonly underline?: {
readonly color?: string;
readonly type?: UnderlineType;
};
readonly color?: string;
readonly size?: number;
readonly rightToLeft?: boolean;
readonly smallCaps?: boolean;
readonly allCaps?: boolean;
readonly strike?: boolean;
readonly doubleStrike?: boolean;
readonly subScript?: boolean;
readonly superScript?: boolean;
readonly style?: string;
readonly font?: {
readonly name: string;
readonly hint?: string;
};
readonly highlight?: string;
readonly shading?: {
readonly type: ShadingType;
readonly fill: string;
readonly color: string;
};
}
export class Run extends XmlComponent {
protected readonly properties: RunProperties;
constructor() {
constructor(options: IRunOptions) {
super("w:r");
this.properties = new RunProperties();
this.root.push(this.properties);
}
public bold(): Run {
this.properties.push(new Bold());
this.properties.push(new BoldComplexScript());
return this;
}
if (options.bold) {
this.properties.push(new Bold());
this.properties.push(new BoldComplexScript());
}
public italics(): Run {
this.properties.push(new Italics());
this.properties.push(new ItalicsComplexScript());
return this;
}
if (options.italics) {
this.properties.push(new Italics());
this.properties.push(new ItalicsComplexScript());
}
public underline(underlineType?: string, color?: string): Run {
this.properties.push(new Underline(underlineType, color));
return this;
}
if (options.underline) {
this.properties.push(new Underline(options.underline.type, options.underline.color));
}
public color(color: string): Run {
this.properties.push(new Color(color));
return this;
}
if (options.color) {
this.properties.push(new Color(options.color));
}
public size(size: number): Run {
this.properties.push(new Size(size));
this.properties.push(new SizeComplexScript(size));
return this;
}
if (options.size) {
this.properties.push(new Size(options.size));
this.properties.push(new SizeComplexScript(options.size));
}
public rightToLeft(): Run {
this.properties.push(new RightToLeft());
return this;
if (options.rightToLeft) {
this.properties.push(new RightToLeft());
}
if (options.smallCaps) {
this.properties.push(new SmallCaps());
}
if (options.allCaps) {
this.properties.push(new Caps());
}
if (options.strike) {
this.properties.push(new Strike());
}
if (options.doubleStrike) {
this.properties.push(new DoubleStrike());
}
if (options.subScript) {
this.properties.push(new SubScript());
}
if (options.superScript) {
this.properties.push(new SuperScript());
}
if (options.style) {
this.properties.push(new Style(options.style));
}
if (options.font) {
this.properties.push(new RunFonts(options.font.name, options.font.hint));
}
if (options.highlight) {
this.properties.push(new Highlight(options.highlight));
this.properties.push(new HighlightComplexScript(options.highlight));
}
if (options.shading) {
this.properties.push(new Shading(options.shading.type, options.shading.fill, options.shading.color));
this.properties.push(new ShadowComplexScript(options.shading.type, options.shading.fill, options.shading.color));
}
}
public break(): Run {
@ -99,44 +169,4 @@ export class Run extends XmlComponent {
this.root.push(new End());
return this;
}
public smallCaps(): Run {
this.properties.push(new SmallCaps());
return this;
}
public allCaps(): Run {
this.properties.push(new Caps());
return this;
}
public strike(): Run {
this.properties.push(new Strike());
return this;
}
public doubleStrike(): Run {
this.properties.push(new DoubleStrike());
return this;
}
public subScript(): Run {
this.properties.push(new SubScript());
return this;
}
public superScript(): Run {
this.properties.push(new SuperScript());
return this;
}
public font(fontName: string, hint?: string | undefined): Run {
this.properties.push(new RunFonts(fontName, hint));
return this;
}
public style(styleId: string): Run {
this.properties.push(new Style(styleId));
return this;
}
}

View File

@ -4,7 +4,7 @@ import { SequentialIdentifierInstruction } from "./sequential-identifier-instruc
export class SequentialIdentifier extends Run {
constructor(identifier: string) {
super();
super({});
this.root.push(new Begin(true));
this.root.push(new SequentialIdentifierInstruction(identifier));
this.root.push(new Separate());

View File

@ -1,9 +1,19 @@
import { Run } from "../run";
import { IRunOptions, Run } from "./run";
import { Text } from "./run-components/text";
export interface ITextRunOptions extends IRunOptions {
readonly text: string;
}
export class TextRun extends Run {
constructor(text: string) {
super();
this.root.push(new Text(text));
constructor(options: ITextRunOptions | string) {
if (typeof options === "string") {
super({});
this.root.push(new Text(options));
return;
}
super(options);
this.root.push(new Text(options.text));
}
}

View File

@ -1,5 +1,25 @@
import { Attributes, XmlComponent } from "file/xml-components";
export enum UnderlineType {
SINGLE = "single",
WORDS = "words",
DOUBLE = "double",
THICK = "thick",
DOTTED = "dotted",
DOTTEDHEAVY = "dottedHeavy",
DASH = "dash",
DASHEDHEAVY = "dashedHeavy",
DASHLONG = "dashLong",
DASHLONGHEAVY = "dashLongHeavy",
DOTDASH = "dotDash",
DASHDOTHEAVY = "dashDotHeavy",
DOTDOTDASH = "dotDotDash",
DASHDOTDOTHEAVY = "dashDotDotHeavy",
WAVE = "wave",
WAVYHEAVY = "wavyHeavy",
WAVYDOUBLE = "wavyDouble",
}
export abstract class BaseUnderline extends XmlComponent {
constructor(underlineType: string, color?: string) {
super("w:u");