2017-04-01 12:18:23 +01:00
|
|
|
import { IData } from "../../media/data";
|
2017-03-08 18:23:00 +01:00
|
|
|
import { Num } from "../../numbering/num";
|
2017-03-13 23:35:24 +00:00
|
|
|
import { Run } from "../run";
|
2017-03-13 23:41:14 +00:00
|
|
|
import { PictureRun } from "../run/picture-run";
|
2017-03-08 21:36:09 +00:00
|
|
|
import { TextRun } from "../run/text-run";
|
2017-03-12 21:35:30 +01:00
|
|
|
import { XmlComponent } from "../xml-components";
|
2017-03-09 09:18:17 +01:00
|
|
|
|
2017-03-12 21:35:30 +01:00
|
|
|
import { Alignment } from "./alignment";
|
2017-03-08 21:36:09 +00:00
|
|
|
import { ThematicBreak } from "./border";
|
2017-03-09 09:18:17 +01:00
|
|
|
import { Indent } from "./indent";
|
2017-04-14 21:13:11 +02:00
|
|
|
import { KeepLines, KeepNext } from "./keep";
|
2017-03-08 21:36:09 +00:00
|
|
|
import { PageBreak } from "./page-break";
|
|
|
|
import { ParagraphProperties } from "./properties";
|
2017-03-09 12:12:33 +01:00
|
|
|
import { ISpacingProperties, Spacing } from "./spacing";
|
2017-03-08 21:36:09 +00:00
|
|
|
import { Style } from "./style";
|
|
|
|
import { LeftTabStop, MaxRightTabStop } from "./tab-stop";
|
|
|
|
import { NumberProperties } from "./unordered-list";
|
2016-03-29 04:10:33 +01:00
|
|
|
|
2017-07-29 01:15:33 +01:00
|
|
|
export * from "./formatting";
|
|
|
|
|
2016-04-09 20:16:35 +01:00
|
|
|
export class Paragraph extends XmlComponent {
|
2016-03-29 04:10:33 +01:00
|
|
|
private properties: ParagraphProperties;
|
2016-04-21 23:04:15 +01:00
|
|
|
|
2016-03-28 03:55:33 +01:00
|
|
|
constructor(text?: string) {
|
2016-04-09 20:16:35 +01:00
|
|
|
super("w:p");
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties = new ParagraphProperties();
|
2016-04-09 20:16:35 +01:00
|
|
|
this.root.push(this.properties);
|
2016-04-21 23:04:15 +01:00
|
|
|
if (text !== undefined) {
|
|
|
|
this.root.push(new TextRun(text));
|
|
|
|
}
|
2016-03-27 02:28:47 +01:00
|
|
|
}
|
2016-03-29 04:10:33 +01:00
|
|
|
|
2017-03-13 23:35:24 +00:00
|
|
|
public addRun(run: Run): Paragraph {
|
2016-04-09 20:16:35 +01:00
|
|
|
this.root.push(run);
|
2016-03-29 04:10:33 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:44:25 +01:00
|
|
|
public createTextRun(text: string): TextRun {
|
2017-03-10 14:35:37 +01:00
|
|
|
const run = new TextRun(text);
|
2017-03-13 23:35:24 +00:00
|
|
|
this.addRun(run);
|
2017-03-10 14:35:37 +01:00
|
|
|
return run;
|
|
|
|
}
|
|
|
|
|
2017-04-01 12:18:23 +01:00
|
|
|
public createPictureRun(imageData: IData): PictureRun {
|
|
|
|
const run = new PictureRun(imageData);
|
2017-03-13 23:41:14 +00:00
|
|
|
this.addRun(run);
|
|
|
|
return run;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public heading1(): Paragraph {
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties.push(new Style("Heading1"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public heading2(): Paragraph {
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties.push(new Style("Heading2"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public heading3(): Paragraph {
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties.push(new Style("Heading3"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public heading4(): Paragraph {
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties.push(new Style("Heading4"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public heading5(): Paragraph {
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties.push(new Style("Heading5"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public title(): Paragraph {
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties.push(new Style("Title"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public center(): Paragraph {
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties.push(new Alignment("center"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public left(): Paragraph {
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties.push(new Alignment("left"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public right(): Paragraph {
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties.push(new Alignment("right"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public justified(): Paragraph {
|
2016-03-29 04:10:33 +01:00
|
|
|
this.properties.push(new Alignment("both"));
|
|
|
|
return this;
|
|
|
|
}
|
2016-03-29 05:01:33 +01:00
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public thematicBreak(): Paragraph {
|
2017-09-15 08:37:57 -06:00
|
|
|
this.properties.push(new ThematicBreak());
|
2016-03-29 05:01:33 +01:00
|
|
|
return this;
|
|
|
|
}
|
2016-03-29 23:36:57 +01:00
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public pageBreak(): Paragraph {
|
2017-09-15 08:25:43 -06:00
|
|
|
this.root.push(new PageBreak());
|
2016-03-30 00:28:05 +01:00
|
|
|
return this;
|
|
|
|
}
|
2016-03-30 02:55:11 +01:00
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public maxRightTabStop(): Paragraph {
|
2016-05-18 17:06:21 +01:00
|
|
|
this.properties.push(new MaxRightTabStop());
|
|
|
|
return this;
|
|
|
|
}
|
2016-05-26 15:08:34 +01:00
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public leftTabStop(position: number): Paragraph {
|
2016-05-26 15:08:34 +01:00
|
|
|
this.properties.push(new LeftTabStop(position));
|
2016-03-30 02:55:11 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public bullet(): Paragraph {
|
2016-03-30 02:55:11 +01:00
|
|
|
this.properties.push(new Style("ListParagraph"));
|
2017-03-07 19:14:57 +01:00
|
|
|
this.properties.push(new NumberProperties(1, 0));
|
2016-03-30 02:55:11 +01:00
|
|
|
return this;
|
|
|
|
}
|
2017-03-08 18:23:00 +01:00
|
|
|
|
|
|
|
public setNumbering(numbering: Num, indentLevel: number): Paragraph {
|
|
|
|
this.properties.push(new Style("ListParagraph"));
|
|
|
|
this.properties.push(new NumberProperties(numbering.id, indentLevel));
|
|
|
|
return this;
|
|
|
|
}
|
2017-03-09 09:18:17 +01:00
|
|
|
|
2017-03-09 09:46:12 +01:00
|
|
|
public style(styleId: string): Paragraph {
|
|
|
|
this.properties.push(new Style(styleId));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-09 09:18:17 +01:00
|
|
|
public indent(start: number, hanging?: number): Paragraph {
|
|
|
|
this.properties.push(new Indent(start, hanging));
|
|
|
|
return this;
|
|
|
|
}
|
2017-03-09 12:12:33 +01:00
|
|
|
|
|
|
|
public spacing(params: ISpacingProperties): Paragraph {
|
|
|
|
this.properties.push(new Spacing(params));
|
|
|
|
return this;
|
2017-04-15 17:54:47 +01:00
|
|
|
}
|
2017-04-14 21:13:11 +02:00
|
|
|
|
|
|
|
public keepNext(): Paragraph {
|
|
|
|
this.properties.push(new KeepNext());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public keepLines(): Paragraph {
|
|
|
|
this.properties.push(new KeepLines());
|
|
|
|
return this;
|
|
|
|
}
|
2017-03-08 18:23:00 +01:00
|
|
|
}
|