diff --git a/ts/styles/defaults/index.ts b/ts/styles/defaults/index.ts index 7b74e1d311..65737fcc52 100644 --- a/ts/styles/defaults/index.ts +++ b/ts/styles/defaults/index.ts @@ -1,6 +1,6 @@ -import {XmlComponent} from "../../docx/xml-components"; -import {ParagraphPropertiesDefaults} from "./paragraph-properties"; -import {RunPropertiesDefaults} from "./run-properties"; +import { XmlComponent } from "../../docx/xml-components"; +import { ParagraphPropertiesDefaults } from "./paragraph-properties"; +import { RunPropertiesDefaults } from "./run-properties"; export class DocumentDefaults extends XmlComponent { @@ -15,10 +15,10 @@ export class DocumentDefaults extends XmlComponent { this.root.push(this.paragraphPropertiesDefaults); } - clearVariables(): void { + public clearVariables(): void { this.runPropertiesDefaults.clearVariables(); this.paragraphPropertiesDefaults.clearVariables(); delete this.runPropertiesDefaults; delete this.paragraphPropertiesDefaults; } -} \ No newline at end of file +} diff --git a/ts/styles/defaults/paragraph-properties.ts b/ts/styles/defaults/paragraph-properties.ts index 43d1d4c4cf..bac85aa796 100644 --- a/ts/styles/defaults/paragraph-properties.ts +++ b/ts/styles/defaults/paragraph-properties.ts @@ -1,5 +1,5 @@ -import {XmlComponent} from "../../docx/xml-components"; -import {ParagraphProperties} from "../../docx/paragraph/properties"; +import { ParagraphProperties } from "../../docx/paragraph/properties"; +import { XmlComponent } from "../../docx/xml-components"; export class ParagraphPropertiesDefaults extends XmlComponent { @@ -7,4 +7,4 @@ export class ParagraphPropertiesDefaults extends XmlComponent { super("w:pPrDefault"); this.root.push(new ParagraphProperties()); } -} \ No newline at end of file +} diff --git a/ts/styles/defaults/run-properties.ts b/ts/styles/defaults/run-properties.ts index e3c14a20a1..388d7a2e88 100644 --- a/ts/styles/defaults/run-properties.ts +++ b/ts/styles/defaults/run-properties.ts @@ -1,5 +1,5 @@ -import {XmlComponent} from "../../docx/xml-components"; -import {RunProperties} from "../../docx/run/properties"; +import { RunProperties } from "../../docx/run/properties"; +import { XmlComponent } from "../../docx/xml-components"; export class RunPropertiesDefaults extends XmlComponent { @@ -7,4 +7,4 @@ export class RunPropertiesDefaults extends XmlComponent { super("w:rPrDefault"); this.root.push(new RunProperties()); } -} \ No newline at end of file +} diff --git a/ts/styles/factory.ts b/ts/styles/factory.ts index 9907157dd3..d44e4c3b09 100644 --- a/ts/styles/factory.ts +++ b/ts/styles/factory.ts @@ -1,56 +1,60 @@ -import {Styles} from "./"; -import {DocumentDefaults} from "./defaults"; -import {ParagraphPropertiesDefaults} from "./defaults/paragraph-properties"; -import {RunPropertiesDefaults} from "./defaults/run-properties"; -import {Heading1Style, Heading2Style, TitleStyle, Heading3Style, Heading4Style, Heading5Style, Heading6Style, ListParagraph} from "./style"; -// import {StyleAttributes} from "./style/attributes"; -import {ParagraphProperties} from "../docx/paragraph/properties"; -import {RunProperties} from "../docx/run/properties"; -import {Color, Size, Italics} from "../docx/run/formatting"; +import { ParagraphProperties } from "../docx/paragraph/properties"; +import { Color, Italics, Size } from "../docx/run/formatting"; +import { RunProperties } from "../docx/run/properties"; + +import { Styles } from "./"; +import { DocumentDefaults } from "./defaults"; +import { ParagraphPropertiesDefaults } from "./defaults/paragraph-properties"; +import { RunPropertiesDefaults } from "./defaults/run-properties"; +import { + Heading1Style, Heading2Style, Heading3Style, Heading4Style, Heading5Style, Heading6Style, + ListParagraph, TitleStyle, +} from "./style"; +// import { StyleAttributes } from "./style/attributes"; export class DefaultStylesFactory { - newInstance(): Styles { - let styles = new Styles(); + public newInstance(): Styles { + const styles = new Styles(); styles.push(new DocumentDefaults()); - let titleStyle = new TitleStyle(); + const titleStyle = new TitleStyle(); titleStyle.addRunProperty(new Size(56)); styles.push(titleStyle); - let heading1Style = new Heading1Style(); + const heading1Style = new Heading1Style(); heading1Style.addRunProperty(new Color("2E74B5")); heading1Style.addRunProperty(new Size(32)); styles.push(heading1Style); - let heading2Style = new Heading2Style(); + const heading2Style = new Heading2Style(); heading2Style.addRunProperty(new Color("2E74B5")); heading2Style.addRunProperty(new Size(26)); styles.push(heading2Style); - let heading3Style = new Heading3Style(); + const heading3Style = new Heading3Style(); heading3Style.addRunProperty(new Color("1F4D78")); heading3Style.addRunProperty(new Size(24)); styles.push(heading3Style); - let heading4Style = new Heading4Style(); + const heading4Style = new Heading4Style(); heading4Style.addRunProperty(new Color("2E74B5")); heading4Style.addRunProperty(new Italics()); styles.push(heading4Style); - let heading5Style = new Heading5Style(); + const heading5Style = new Heading5Style(); heading5Style.addRunProperty(new Color("2E74B5")); styles.push(heading5Style); - let heading6Style = new Heading6Style(); + const heading6Style = new Heading6Style(); heading6Style.addRunProperty(new Color("1F4D78")); styles.push(heading6Style); - let listParagraph = new ListParagraph(); + const listParagraph = new ListParagraph(); // listParagraph.addParagraphProperty(); styles.push(listParagraph); // console.log(JSON.stringify(styles, null, " ")); return styles; } -} \ No newline at end of file +} diff --git a/ts/styles/index.ts b/ts/styles/index.ts index ebf66dd56b..ee9f2bc784 100644 --- a/ts/styles/index.ts +++ b/ts/styles/index.ts @@ -1,9 +1,9 @@ -import {XmlComponent} from "../docx/xml-components"; -import {DocumentAttributes} from "../docx/document/document-attributes"; -import {DocumentDefaults} from "./defaults"; -import {LatentStyles} from "./latent-styles"; -import {LatentStyleException} from "./latent-styles/exceptions"; -import {LatentStyleExceptionAttributes} from "./latent-styles/exceptions/attributes"; +import { DocumentAttributes } from "../docx/document/document-attributes"; +import { XmlComponent } from "../docx/xml-components"; +import { DocumentDefaults } from "./defaults"; +import { LatentStyles } from "./latent-styles"; +import { LatentStyleException } from "./latent-styles/exceptions"; +import { LatentStyleExceptionAttributes } from "./latent-styles/exceptions/attributes"; export class Styles extends XmlComponent { @@ -15,7 +15,7 @@ export class Styles extends XmlComponent { w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", w14: "http://schemas.microsoft.com/office/word/2010/wordml", w15: "http://schemas.microsoft.com/office/word/2012/wordml", - Ignorable: "w14 w15" + Ignorable: "w14 w15", })); // let latentStyles = new LatentStyles(); // latentStyles.push(new LatentStyleException(new LatentStyleExceptionAttributes({ @@ -24,13 +24,14 @@ export class Styles extends XmlComponent { // this.root.push(latentStyles); } - push(style: XmlComponent): void { + public push(style: XmlComponent): Styles { this.root.push(style); + return this; } - clearVariables() { - this.root.forEach(element => { + public clearVariables(): void { + this.root.forEach((element) => { element.clearVariables(); }); } -} \ No newline at end of file +} diff --git a/ts/styles/latent-styles/exceptions/attributes.ts b/ts/styles/latent-styles/exceptions/attributes.ts index 4c2eaa2786..359852bceb 100644 --- a/ts/styles/latent-styles/exceptions/attributes.ts +++ b/ts/styles/latent-styles/exceptions/attributes.ts @@ -1,6 +1,6 @@ import {XmlComponent} from "../../../docx/xml-components"; -interface LatentStyleExceptionAttributesProperties { +interface ILatentStyleExceptionAttributesProperties { name?: string; uiPriority?: string; qFormat?: string; @@ -9,23 +9,23 @@ interface LatentStyleExceptionAttributesProperties { } export class LatentStyleExceptionAttributes extends XmlComponent { - private _attr: Object; + private _attr: ILatentStyleExceptionAttributesProperties; - xmlKeys = { + private xmlKeys = { name: "w:name", uiPriority: "w:uiPriority", qFormat: "w:qFormat", semiHidden: "w:semiHidden", - unhideWhenUsed: "w:unhideWhenUsed" + unhideWhenUsed: "w:unhideWhenUsed", }; - constructor(properties?: LatentStyleExceptionAttributesProperties) { + constructor(properties?: ILatentStyleExceptionAttributesProperties) { super("_attr"); this._attr = properties; if (!properties) { this._attr = {}; } - this._attr["xmlKeys"] = this.xmlKeys; + //this._attr.xmlKeys = this.xmlKeys; } -} \ No newline at end of file +} diff --git a/ts/styles/latent-styles/exceptions/index.ts b/ts/styles/latent-styles/exceptions/index.ts index 685440b3ee..227ed93318 100644 --- a/ts/styles/latent-styles/exceptions/index.ts +++ b/ts/styles/latent-styles/exceptions/index.ts @@ -1,5 +1,5 @@ -import {XmlComponent} from "../../../docx/xml-components"; -import {LatentStyleExceptionAttributes} from "./attributes"; +import { XmlComponent } from "../../../docx/xml-components"; +import { LatentStyleExceptionAttributes } from "./attributes"; export class LatentStyleException extends XmlComponent { @@ -7,4 +7,4 @@ export class LatentStyleException extends XmlComponent { super("w:lsdException"); this.root.push(attributes); } -} \ No newline at end of file +} diff --git a/ts/styles/latent-styles/index.ts b/ts/styles/latent-styles/index.ts index fe75c11e37..583ab1e0e0 100644 --- a/ts/styles/latent-styles/index.ts +++ b/ts/styles/latent-styles/index.ts @@ -1,5 +1,5 @@ -import {XmlComponent} from "../../docx/xml-components"; -import {LatentStyleException} from "./exceptions"; +import { XmlComponent } from "../../docx/xml-components"; +import { LatentStyleException } from "./exceptions"; export class LatentStyles extends XmlComponent { @@ -7,7 +7,7 @@ export class LatentStyles extends XmlComponent { super("w:latentStyles"); } - push(latentException: LatentStyleException): void { + public push(latentException: LatentStyleException): void { this.root.push(latentException); } -} \ No newline at end of file +} diff --git a/ts/styles/style/attributes.ts b/ts/styles/style/attributes.ts index a227979cb4..c6ec627404 100644 --- a/ts/styles/style/attributes.ts +++ b/ts/styles/style/attributes.ts @@ -1,7 +1,6 @@ -import {XmlComponent} from "../../docx/xml-components"; -import {XmlAttributeComponent} from "../../docx/xml-components"; +import { XmlAttributeComponent, XmlComponent } from "../../docx/xml-components"; -interface StyleAttributesProperties { +interface IStyleAttributesProperties { type?: string; styleId?: string; default?: string; @@ -10,15 +9,15 @@ interface StyleAttributesProperties { } export class StyleAttributes extends XmlAttributeComponent { - private _attr: Object; + private _attr: IStyleAttributesProperties; - constructor(properties: StyleAttributesProperties) { + constructor(properties: IStyleAttributesProperties) { super({ type: "w:type", styleId: "w:styleId", default: "w:default", customStyle: "w:customStyle", - val: "w:val" + val: "w:val", }, properties); } -} \ No newline at end of file +} diff --git a/ts/styles/style/components.ts b/ts/styles/style/components.ts index f7853169d1..17751bb32a 100644 --- a/ts/styles/style/components.ts +++ b/ts/styles/style/components.ts @@ -1,12 +1,12 @@ -import {XmlComponent} from "../../docx/xml-components"; -import {StyleAttributes} from "./attributes"; +import { XmlComponent } from "../../docx/xml-components"; +import { StyleAttributes } from "./attributes"; export class Name extends XmlComponent { constructor(value: string) { super("w:name"); this.root.push(new StyleAttributes({ - val: value + val: value, })); } } @@ -16,7 +16,7 @@ export class BasedOn extends XmlComponent { constructor(value: string) { super("w:basedOn"); this.root.push(new StyleAttributes({ - val: value + val: value, })); } } @@ -27,7 +27,7 @@ export class Next extends XmlComponent { super("w:next"); this.root.push(new StyleAttributes({ styleId: "1", - val: value + val: value, })); } } @@ -37,7 +37,7 @@ export class Link extends XmlComponent { constructor(value: string) { super("w:link"); this.root.push(new StyleAttributes({ - val: value + val: value, })); } } @@ -47,7 +47,7 @@ export class UiPriority extends XmlComponent { constructor(value: string) { super("w:uiPriority"); this.root.push(new StyleAttributes({ - val: value + val: value, })); } } @@ -73,4 +73,4 @@ export class RsId extends XmlComponent { export class SemiHidden extends XmlComponent { -} \ No newline at end of file +} diff --git a/ts/styles/style/index.ts b/ts/styles/style/index.ts index 412667ea81..6d916a1507 100644 --- a/ts/styles/style/index.ts +++ b/ts/styles/style/index.ts @@ -1,8 +1,9 @@ -import {XmlComponent} from "../../docx/xml-components"; -import {StyleAttributes} from "./attributes"; -import {ParagraphProperties} from "../../docx/paragraph/properties"; -import {RunProperties} from "../../docx/run/properties"; -import {Name, BasedOn, Next, QuickFormat} from "./components"; +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"; export class Style extends XmlComponent { @@ -11,7 +12,7 @@ export class Style extends XmlComponent { this.root.push(attributes); } - push(styleSegment: XmlComponent): void { + public push(styleSegment: XmlComponent): void { this.root.push(styleSegment); } } @@ -23,9 +24,9 @@ export class ParagraphStyle extends Style { constructor(styleId: string) { - let attributes = new StyleAttributes({ + const attributes = new StyleAttributes({ type: "paragraph", - styleId: styleId + styleId: styleId, }); super(attributes); this.paragraphProperties = new ParagraphProperties(); @@ -34,18 +35,18 @@ export class ParagraphStyle extends Style { this.root.push(this.runProperties); } - clearVariables(): void { + public clearVariables(): void { this.paragraphProperties.clearVariables(); this.runProperties.clearVariables(); delete this.paragraphProperties; delete this.runProperties; } - addParagraphProperty(property: XmlComponent): void { + public addParagraphProperty(property: XmlComponent): void { this.paragraphProperties.push(property); } - addRunProperty(property: XmlComponent): void { + public addRunProperty(property: XmlComponent): void { this.runProperties.push(property); } } @@ -118,4 +119,4 @@ export class ListParagraph extends ParagraphStyle { this.root.push(new BasedOn("Normal")); this.root.push(new QuickFormat()); } -} \ No newline at end of file +} diff --git a/ts/tests/stylesTest.ts b/ts/tests/stylesTest.ts index bc3015c009..06fc29e645 100644 --- a/ts/tests/stylesTest.ts +++ b/ts/tests/stylesTest.ts @@ -1,5 +1,5 @@ -import { Styles } from "../styles"; import { assert } from "chai"; +import { Styles } from "../styles"; describe("Styles", () => { let styles: Styles; @@ -11,11 +11,8 @@ describe("Styles", () => { describe("#constructor()", () => { it("should create styles with correct rootKey", () => { - let styles = new Styles(); - let stringifiedJson = JSON.stringify(styles); - let newJson = JSON.parse(stringifiedJson); - + const newJson = JSON.parse(JSON.stringify(styles)); assert.equal(newJson.rootKey, "w:styles"); }); }); -}); \ No newline at end of file +});