Improve fluency (dsl like)
addRunProperty / addParagraphProperty should also return this
This commit is contained in:
@ -47,12 +47,14 @@ export class ParagraphStyle extends Style {
|
|||||||
this.root.push(this.runProperties);
|
this.root.push(this.runProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public addParagraphProperty(property: XmlComponent): void {
|
public addParagraphProperty(property: XmlComponent): ParagraphStyle {
|
||||||
this.paragraphProperties.push(property);
|
this.paragraphProperties.push(property);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addRunProperty(property: XmlComponent): void {
|
public addRunProperty(property: XmlComponent): ParagraphStyle {
|
||||||
this.runProperties.push(property);
|
this.runProperties.push(property);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public basedOn(parentId: string): ParagraphStyle {
|
public basedOn(parentId: string): ParagraphStyle {
|
||||||
@ -73,126 +75,103 @@ export class ParagraphStyle extends Style {
|
|||||||
// ---------- Run formatting ---------------------- //
|
// ---------- Run formatting ---------------------- //
|
||||||
|
|
||||||
public size(twips: number): ParagraphStyle {
|
public size(twips: number): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.Size(twips));
|
return this
|
||||||
this.addRunProperty(new formatting.SizeComplexScript(twips));
|
.addRunProperty(new formatting.Size(twips))
|
||||||
return this;
|
.addRunProperty(new formatting.SizeComplexScript(twips));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bold(): ParagraphStyle {
|
public bold(): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.Bold());
|
return this.addRunProperty(new formatting.Bold());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public italics(): ParagraphStyle {
|
public italics(): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.Italics());
|
return this.addRunProperty(new formatting.Italics());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public smallCaps(): ParagraphStyle {
|
public smallCaps(): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.SmallCaps());
|
return this.addRunProperty(new formatting.SmallCaps());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public allCaps(): ParagraphStyle {
|
public allCaps(): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.Caps());
|
return this.addRunProperty(new formatting.Caps());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public strike(): ParagraphStyle {
|
public strike(): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.Strike());
|
return this.addRunProperty(new formatting.Strike());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public doubleStrike(): ParagraphStyle {
|
public doubleStrike(): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.DoubleStrike());
|
return this.addRunProperty(new formatting.DoubleStrike());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public subScript(): ParagraphStyle {
|
public subScript(): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.SubScript());
|
return this.addRunProperty(new formatting.SubScript());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public superScript(): ParagraphStyle {
|
public superScript(): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.SuperScript());
|
return this.addRunProperty(new formatting.SuperScript());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public underline(underlineType?: string, color?: string): ParagraphStyle {
|
public underline(underlineType?: string, color?: string): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.Underline(underlineType, color));
|
return this.addRunProperty(new formatting.Underline(underlineType, color));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public color(color: string): ParagraphStyle {
|
public color(color: string): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.Color(color));
|
return this.addRunProperty(new formatting.Color(color));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public font(fontName: string): ParagraphStyle {
|
public font(fontName: string): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.RunFonts(fontName));
|
return this.addRunProperty(new formatting.RunFonts(fontName));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public characterSpacing(value: number): ParagraphStyle {
|
public characterSpacing(value: number): ParagraphStyle {
|
||||||
this.addRunProperty(new formatting.CharacterSpacing(value));
|
return this.addRunProperty(new formatting.CharacterSpacing(value));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------- Paragraph formatting ------------------------ //
|
// --------------------- Paragraph formatting ------------------------ //
|
||||||
|
|
||||||
public center(): ParagraphStyle {
|
public center(): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.Alignment("center"));
|
return this.addParagraphProperty(new paragraph.Alignment("center"));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public left(): ParagraphStyle {
|
public left(): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.Alignment("left"));
|
return this.addParagraphProperty(new paragraph.Alignment("left"));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public right(): ParagraphStyle {
|
public right(): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.Alignment("right"));
|
return this.addParagraphProperty(new paragraph.Alignment("right"));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public justified(): ParagraphStyle {
|
public justified(): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.Alignment("both"));
|
return this.addParagraphProperty(new paragraph.Alignment("both"));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public thematicBreak(): ParagraphStyle {
|
public thematicBreak(): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.ThematicBreak());
|
return this.addParagraphProperty(new paragraph.ThematicBreak());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public maxRightTabStop(): ParagraphStyle {
|
public maxRightTabStop(): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.MaxRightTabStop());
|
return this.addParagraphProperty(new paragraph.MaxRightTabStop());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public leftTabStop(position: number): ParagraphStyle {
|
public leftTabStop(position: number): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.LeftTabStop(position));
|
return this.addParagraphProperty(new paragraph.LeftTabStop(position));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public indent(attrs: object): ParagraphStyle {
|
public indent(attrs: object): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.Indent(attrs));
|
return this.addParagraphProperty(new paragraph.Indent(attrs));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public spacing(params: paragraph.ISpacingProperties): ParagraphStyle {
|
public spacing(params: paragraph.ISpacingProperties): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.Spacing(params));
|
return this.addParagraphProperty(new paragraph.Spacing(params));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public keepNext(): ParagraphStyle {
|
public keepNext(): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.KeepNext());
|
return this.addParagraphProperty(new paragraph.KeepNext());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public keepLines(): ParagraphStyle {
|
public keepLines(): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.KeepLines());
|
return this.addParagraphProperty(new paragraph.KeepLines());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,24 +251,23 @@ export class CharacterStyle extends Style {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addRunProperty(property: XmlComponent): void {
|
public addRunProperty(property: XmlComponent): CharacterStyle {
|
||||||
this.runProperties.push(property);
|
this.runProperties.push(property);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public color(color: string): CharacterStyle {
|
public color(color: string): CharacterStyle {
|
||||||
this.addRunProperty(new formatting.Color(color));
|
return this.addRunProperty(new formatting.Color(color));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public underline(underlineType?: string, color?: string): CharacterStyle {
|
public underline(underlineType?: string, color?: string): CharacterStyle {
|
||||||
this.addRunProperty(new formatting.Underline(underlineType, color));
|
return this.addRunProperty(new formatting.Underline(underlineType, color));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public size(twips: number): CharacterStyle {
|
public size(twips: number): CharacterStyle {
|
||||||
this.addRunProperty(new formatting.Size(twips));
|
return this
|
||||||
this.addRunProperty(new formatting.SizeComplexScript(twips));
|
.addRunProperty(new formatting.Size(twips))
|
||||||
return this;
|
.addRunProperty(new formatting.SizeComplexScript(twips));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user