Files
docx-js/ts/styles/style/index.ts

123 lines
2.9 KiB
TypeScript
Raw Normal View History

2017-03-09 09:45:01 +01:00
import { ParagraphProperties } from "../../docx/paragraph/properties";
import { RunProperties } from "../../docx/run/properties";
import { XmlComponent } from "../../docx/xml-components";
import { StyleAttributes } from "./attributes";
import { BasedOn, Name, Next, QuickFormat } from "./components";
2016-04-09 04:27:49 +01:00
2016-04-09 20:16:35 +01:00
export class Style extends XmlComponent {
2016-05-08 17:01:20 +01:00
2016-04-09 04:27:49 +01:00
constructor(attributes: StyleAttributes) {
2016-04-09 20:16:35 +01:00
super("w:style");
this.root.push(attributes);
2016-04-09 04:27:49 +01:00
}
2016-05-08 17:01:20 +01:00
2017-03-09 09:45:01 +01:00
public push(styleSegment: XmlComponent): void {
2016-04-09 20:16:35 +01:00
this.root.push(styleSegment);
2016-04-09 04:27:49 +01:00
}
2016-05-07 20:17:18 +01:00
}
2016-05-08 17:01:20 +01:00
export class ParagraphStyle extends Style {
2016-05-10 00:32:00 +01:00
private paragraphProperties: ParagraphProperties;
private runProperties: RunProperties;
constructor(styleId: string) {
2017-03-09 09:45:01 +01:00
const attributes = new StyleAttributes({
2016-05-08 17:01:20 +01:00
type: "paragraph",
2017-03-09 09:45:01 +01:00
styleId: styleId,
2016-05-08 17:01:20 +01:00
});
super(attributes);
2016-05-10 00:32:00 +01:00
this.paragraphProperties = new ParagraphProperties();
this.runProperties = new RunProperties();
this.root.push(this.paragraphProperties);
this.root.push(this.runProperties);
}
2017-03-09 09:45:01 +01:00
public clearVariables(): void {
2016-05-10 00:32:00 +01:00
this.paragraphProperties.clearVariables();
this.runProperties.clearVariables();
delete this.paragraphProperties;
delete this.runProperties;
}
2017-03-09 09:45:01 +01:00
public addParagraphProperty(property: XmlComponent): void {
2016-05-10 00:32:00 +01:00
this.paragraphProperties.push(property);
}
2017-03-09 09:45:01 +01:00
public addRunProperty(property: XmlComponent): void {
2016-05-10 00:32:00 +01:00
this.runProperties.push(property);
2016-05-08 17:01:20 +01:00
}
}
export class HeadingStyle extends ParagraphStyle {
2016-05-10 00:32:00 +01:00
constructor(styleId: string, name: string) {
super(styleId);
2016-05-08 17:01:20 +01:00
this.root.push(new Name(name));
this.root.push(new BasedOn("Normal"));
this.root.push(new Next("Normal"));
this.root.push(new QuickFormat());
}
}
2016-05-10 00:32:00 +01:00
export class TitleStyle extends HeadingStyle {
constructor() {
super("Title", "Title");
}
}
2016-05-08 17:01:20 +01:00
export class Heading1Style extends HeadingStyle {
2016-05-10 00:32:00 +01:00
constructor() {
super("Heading1", "Heading 1");
2016-05-08 17:01:20 +01:00
}
}
export class Heading2Style extends HeadingStyle {
2016-05-10 00:32:00 +01:00
constructor() {
super("Heading2", "Heading 2");
2016-05-08 17:01:20 +01:00
}
}
export class Heading3Style extends HeadingStyle {
2016-05-10 00:32:00 +01:00
constructor() {
super("Heading3", "Heading 3");
2016-05-08 17:01:20 +01:00
}
}
export class Heading4Style extends HeadingStyle {
2016-05-10 00:32:00 +01:00
constructor() {
super("Heading4", "Heading 4");
2016-05-08 17:01:20 +01:00
}
}
export class Heading5Style extends HeadingStyle {
2016-05-10 00:32:00 +01:00
constructor() {
super("Heading5", "Heading 5");
2016-05-08 17:01:20 +01:00
}
}
export class Heading6Style extends HeadingStyle {
2016-05-10 00:32:00 +01:00
constructor() {
super("Heading6", "Heading 6");
2016-05-08 17:01:20 +01:00
}
}
export class ListParagraph extends ParagraphStyle {
2016-05-26 15:08:34 +01:00
constructor() {
super("ListParagraph");
this.root.push(new Name("List Paragraph"));
this.root.push(new BasedOn("Normal"));
this.root.push(new QuickFormat());
}
2017-03-09 09:45:01 +01:00
}