2017-12-30 20:25:16 +00:00
|
|
|
import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
2017-12-20 00:01:23 +00:00
|
|
|
import * as paragraph from "../paragraph/formatting";
|
|
|
|
import { ParagraphProperties } from "../paragraph/properties";
|
|
|
|
import * as formatting from "../paragraph/run/formatting";
|
|
|
|
import { RunProperties } from "../paragraph/run/properties";
|
2016-05-19 22:42:23 +01:00
|
|
|
|
2017-03-08 17:13:27 +01:00
|
|
|
interface ILevelAttributesProperties {
|
2016-05-26 15:08:34 +01:00
|
|
|
ilvl?: number;
|
|
|
|
tentative?: number;
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
|
2017-03-10 10:42:24 +01:00
|
|
|
class LevelAttributes extends XmlAttributeComponent<ILevelAttributesProperties> {
|
|
|
|
protected xmlKeys = {
|
|
|
|
ilvl: "w:ilvl",
|
|
|
|
tentative: "w15:tentative",
|
|
|
|
};
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class Start extends XmlComponent {
|
|
|
|
constructor(value: number) {
|
|
|
|
super("w:start");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(
|
|
|
|
new Attributes({
|
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NumberFormat extends XmlComponent {
|
|
|
|
constructor(value: string) {
|
|
|
|
super("w:numFmt");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(
|
|
|
|
new Attributes({
|
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LevelText extends XmlComponent {
|
|
|
|
constructor(value: string) {
|
|
|
|
super("w:lvlText");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(
|
|
|
|
new Attributes({
|
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LevelJc extends XmlComponent {
|
|
|
|
constructor(value: string) {
|
|
|
|
super("w:lvlJc");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(
|
|
|
|
new Attributes({
|
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-07 14:31:08 +01:00
|
|
|
export class LevelBase extends XmlComponent {
|
2016-05-19 22:42:23 +01:00
|
|
|
private paragraphProperties: ParagraphProperties;
|
|
|
|
private runProperties: RunProperties;
|
|
|
|
|
2017-04-12 15:53:35 +02:00
|
|
|
constructor(level: number, start?: number, numberFormat?: string, levelText?: string, lvlJc?: string) {
|
2016-05-19 22:42:23 +01:00
|
|
|
super("w:lvl");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(
|
|
|
|
new LevelAttributes({
|
|
|
|
ilvl: level,
|
|
|
|
tentative: 1,
|
|
|
|
}),
|
|
|
|
);
|
2016-05-19 22:42:23 +01:00
|
|
|
|
2017-04-12 15:53:35 +02:00
|
|
|
if (start !== undefined) {
|
|
|
|
this.root.push(new Start(start));
|
|
|
|
}
|
|
|
|
if (numberFormat !== undefined) {
|
|
|
|
this.root.push(new NumberFormat(numberFormat));
|
|
|
|
}
|
|
|
|
if (levelText !== undefined) {
|
|
|
|
this.root.push(new LevelText(levelText));
|
|
|
|
}
|
|
|
|
if (lvlJc !== undefined) {
|
|
|
|
this.root.push(new LevelJc(lvlJc));
|
|
|
|
}
|
2016-05-19 22:42:23 +01:00
|
|
|
|
|
|
|
this.paragraphProperties = new ParagraphProperties();
|
|
|
|
this.runProperties = new RunProperties();
|
|
|
|
|
|
|
|
this.root.push(this.paragraphProperties);
|
|
|
|
this.root.push(this.runProperties);
|
|
|
|
}
|
|
|
|
|
2017-03-08 18:03:39 +01:00
|
|
|
public addParagraphProperty(property: XmlComponent): Level {
|
2016-05-19 22:42:23 +01:00
|
|
|
this.paragraphProperties.push(property);
|
2017-03-08 18:03:39 +01:00
|
|
|
return this;
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
|
2017-03-08 18:03:39 +01:00
|
|
|
public addRunProperty(property: XmlComponent): Level {
|
2016-05-19 22:42:23 +01:00
|
|
|
this.runProperties.push(property);
|
2017-03-08 18:03:39 +01:00
|
|
|
return this;
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
2017-03-13 12:23:18 +01:00
|
|
|
|
2017-03-13 12:30:36 +01:00
|
|
|
// ---------- Run formatting ---------------------- //
|
|
|
|
|
|
|
|
public size(twips: number): Level {
|
|
|
|
this.addRunProperty(new formatting.Size(twips));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bold(): Level {
|
|
|
|
this.addRunProperty(new formatting.Bold());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public italics(): Level {
|
|
|
|
this.addRunProperty(new formatting.Italics());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public smallCaps(): Level {
|
|
|
|
this.addRunProperty(new formatting.SmallCaps());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public allCaps(): Level {
|
|
|
|
this.addRunProperty(new formatting.Caps());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public strike(): Level {
|
|
|
|
this.addRunProperty(new formatting.Strike());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public doubleStrike(): Level {
|
|
|
|
this.addRunProperty(new formatting.DoubleStrike());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public subScript(): Level {
|
|
|
|
this.addRunProperty(new formatting.SubScript());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public superScript(): Level {
|
|
|
|
this.addRunProperty(new formatting.SuperScript());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public underline(underlineType?: string, color?: string): Level {
|
|
|
|
this.addRunProperty(new formatting.Underline(underlineType, color));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public color(color: string): Level {
|
|
|
|
this.addRunProperty(new formatting.Color(color));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public font(fontName: string): Level {
|
|
|
|
this.addRunProperty(new formatting.RunFonts(fontName));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-13 12:23:18 +01:00
|
|
|
// --------------------- Paragraph formatting ------------------------ //
|
|
|
|
|
|
|
|
public center(): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.Alignment("center"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public left(): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.Alignment("left"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public right(): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.Alignment("right"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public justified(): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.Alignment("both"));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public thematicBreak(): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.ThematicBreak());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public maxRightTabStop(): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.MaxRightTabStop());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public leftTabStop(position: number): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.LeftTabStop(position));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-09-16 12:31:31 -06:00
|
|
|
public indent(attrs: object): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.Indent(attrs));
|
2017-03-13 12:23:18 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public spacing(params: paragraph.ISpacingProperties): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.Spacing(params));
|
|
|
|
return this;
|
2017-04-15 17:54:47 +01:00
|
|
|
}
|
2017-04-14 21:13:11 +02:00
|
|
|
|
|
|
|
public keepNext(): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.KeepNext());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public keepLines(): Level {
|
|
|
|
this.addParagraphProperty(new paragraph.KeepLines());
|
|
|
|
return this;
|
|
|
|
}
|
2017-03-08 17:13:27 +01:00
|
|
|
}
|
2017-04-12 15:53:35 +02:00
|
|
|
|
|
|
|
export class Level extends LevelBase {
|
|
|
|
// This is the level that sits under abstractNum. We make a
|
|
|
|
// handful of properties required
|
|
|
|
constructor(level: number, numberFormat: string, levelText: string, lvlJc: string) {
|
|
|
|
super(level, 1, numberFormat, levelText, lvlJc);
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 15:54:14 +02:00
|
|
|
|
|
|
|
export class LevelForOverride extends LevelBase {}
|