diff --git a/src/file/styles/style/character-style.spec.ts b/src/file/styles/style/character-style.spec.ts index 2fddce1c1b..c7adf4ff97 100644 --- a/src/file/styles/style/character-style.spec.ts +++ b/src/file/styles/style/character-style.spec.ts @@ -6,12 +6,12 @@ import { UnderlineType } from "file/paragraph/run/underline"; import { ShadingType } from "file/table"; import { EMPTY_OBJECT } from "file/xml-components"; -import { CharacterStyle } from "./character-style"; +import { StyleForCharacter } from "./character-style"; describe("CharacterStyle", () => { describe("#constructor", () => { it("should set the style type to character and use the given style id", () => { - const style = new CharacterStyle({ id: "myStyleId" }); + const style = new StyleForCharacter({ id: "myStyleId" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -31,7 +31,7 @@ describe("CharacterStyle", () => { }); it("should set the name of the style, if given", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", name: "Style Name", }); @@ -55,7 +55,7 @@ describe("CharacterStyle", () => { }); it("should add smallCaps", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { smallCaps: true, @@ -83,7 +83,7 @@ describe("CharacterStyle", () => { }); it("should add allCaps", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { allCaps: true, @@ -111,7 +111,7 @@ describe("CharacterStyle", () => { }); it("should add strike", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { strike: true, @@ -139,7 +139,7 @@ describe("CharacterStyle", () => { }); it("should add double strike", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { doubleStrike: true, @@ -167,7 +167,7 @@ describe("CharacterStyle", () => { }); it("should add sub script", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { subScript: true, @@ -203,7 +203,7 @@ describe("CharacterStyle", () => { }); it("should add font by name", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { font: "test font", @@ -242,7 +242,7 @@ describe("CharacterStyle", () => { }); it("should add font for ascii and eastAsia", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { font: { @@ -282,7 +282,7 @@ describe("CharacterStyle", () => { }); it("should add character spacing", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { characterSpacing: 100, @@ -312,7 +312,7 @@ describe("CharacterStyle", () => { describe("formatting methods: style attributes", () => { it("#basedOn", () => { - const style = new CharacterStyle({ id: "myStyleId", basedOn: "otherId" }); + const style = new StyleForCharacter({ id: "myStyleId", basedOn: "otherId" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -357,7 +357,7 @@ describe("CharacterStyle", () => { ]; sizeTests.forEach(({ size, sizeComplexScript, expected }) => { it(`#size ${size} cs ${sizeComplexScript}`, () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { size, sizeComplexScript }, }); @@ -385,7 +385,7 @@ describe("CharacterStyle", () => { describe("#underline", () => { it("should set underline to 'single' if no arguments are given", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { underline: {}, @@ -413,7 +413,7 @@ describe("CharacterStyle", () => { }); it("should set the style if given", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { underline: { @@ -443,7 +443,7 @@ describe("CharacterStyle", () => { }); it("should set the style and color if given", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { underline: { @@ -476,7 +476,7 @@ describe("CharacterStyle", () => { describe("#emphasisMark", () => { it("should set emphasisMark to 'dot' if no arguments are given", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { emphasisMark: {}, @@ -504,7 +504,7 @@ describe("CharacterStyle", () => { }); it("should set the style if given", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { emphasisMark: { @@ -535,7 +535,7 @@ describe("CharacterStyle", () => { }); it("#superScript", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { superScript: true, @@ -571,7 +571,7 @@ describe("CharacterStyle", () => { }); it("#color", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { color: "123456", @@ -616,7 +616,7 @@ describe("CharacterStyle", () => { ]; boldTests.forEach(({ bold, boldComplexScript, expected }) => { it(`#bold ${bold} cs ${boldComplexScript}`, () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { bold, boldComplexScript }, }); @@ -660,7 +660,7 @@ describe("CharacterStyle", () => { ]; italicsTests.forEach(({ italics, italicsComplexScript, expected }) => { it(`#italics ${italics} cs ${italicsComplexScript}`, () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { italics, italicsComplexScript }, }); @@ -687,7 +687,7 @@ describe("CharacterStyle", () => { }); it("#link", () => { - const style = new CharacterStyle({ id: "myStyleId", link: "MyLink" }); + const style = new StyleForCharacter({ id: "myStyleId", link: "MyLink" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -708,7 +708,7 @@ describe("CharacterStyle", () => { }); it("#semiHidden", () => { - const style = new CharacterStyle({ id: "myStyleId", semiHidden: true }); + const style = new StyleForCharacter({ id: "myStyleId", semiHidden: true }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -749,7 +749,7 @@ describe("CharacterStyle", () => { ]; highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => { it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { highlight, highlightComplexScript }, }); @@ -838,7 +838,7 @@ describe("CharacterStyle", () => { ]; shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => { it("#shadow correctly", () => { - const style = new CharacterStyle({ + const style = new StyleForCharacter({ id: "myStyleId", run: { shadow, shading, shadingComplexScript }, }); diff --git a/src/file/styles/style/character-style.ts b/src/file/styles/style/character-style.ts index 0191a0460e..63252bddd5 100644 --- a/src/file/styles/style/character-style.ts +++ b/src/file/styles/style/character-style.ts @@ -15,7 +15,7 @@ export interface ICharacterStyleOptions extends IBaseCharacterStyleOptions { readonly name?: string; } -export class CharacterStyle extends Style { +export class StyleForCharacter extends Style { private readonly runProperties: RunProperties; constructor(options: ICharacterStyleOptions) { diff --git a/src/file/styles/style/default-styles.ts b/src/file/styles/style/default-styles.ts index 8974435a95..b1de98e076 100644 --- a/src/file/styles/style/default-styles.ts +++ b/src/file/styles/style/default-styles.ts @@ -1,9 +1,9 @@ import { UnderlineType } from "file/paragraph/run/underline"; -import { CharacterStyle, IBaseCharacterStyleOptions } from "./character-style"; -import { IBaseParagraphStyleOptions, IParagraphStyleOptions, ParagraphStyle } from "./paragraph-style"; +import { IBaseCharacterStyleOptions, StyleForCharacter } from "./character-style"; +import { IBaseParagraphStyleOptions, IParagraphStyleOptions, StyleForParagraph } from "./paragraph-style"; -export class HeadingStyle extends ParagraphStyle { +export class HeadingStyle extends StyleForParagraph { constructor(options: IParagraphStyleOptions) { super({ ...options, @@ -84,7 +84,7 @@ export class Heading6Style extends HeadingStyle { } } -export class ListParagraph extends ParagraphStyle { +export class ListParagraph extends StyleForParagraph { constructor(options: IBaseParagraphStyleOptions) { super({ ...options, @@ -96,7 +96,7 @@ export class ListParagraph extends ParagraphStyle { } } -export class FootnoteText extends ParagraphStyle { +export class FootnoteText extends StyleForParagraph { constructor(options: IBaseParagraphStyleOptions) { super({ ...options, @@ -121,7 +121,7 @@ export class FootnoteText extends ParagraphStyle { } } -export class FootnoteReferenceStyle extends CharacterStyle { +export class FootnoteReferenceStyle extends StyleForCharacter { constructor(options: IBaseCharacterStyleOptions) { super({ ...options, @@ -136,7 +136,7 @@ export class FootnoteReferenceStyle extends CharacterStyle { } } -export class FootnoteTextChar extends CharacterStyle { +export class FootnoteTextChar extends StyleForCharacter { constructor(options: IBaseCharacterStyleOptions) { super({ ...options, @@ -152,7 +152,7 @@ export class FootnoteTextChar extends CharacterStyle { } } -export class HyperlinkStyle extends CharacterStyle { +export class HyperlinkStyle extends StyleForCharacter { constructor(options: IBaseCharacterStyleOptions) { super({ ...options, diff --git a/src/file/styles/style/paragraph-style.spec.ts b/src/file/styles/style/paragraph-style.spec.ts index 92b798f862..8683234793 100644 --- a/src/file/styles/style/paragraph-style.spec.ts +++ b/src/file/styles/style/paragraph-style.spec.ts @@ -6,12 +6,12 @@ import { UnderlineType } from "file/paragraph/run/underline"; import { ShadingType } from "file/table"; import { EMPTY_OBJECT } from "file/xml-components"; -import { ParagraphStyle } from "./paragraph-style"; +import { StyleForParagraph } from "./paragraph-style"; describe("ParagraphStyle", () => { describe("#constructor", () => { it("should set the style type to paragraph and use the given style id", () => { - const style = new ParagraphStyle({ id: "myStyleId" }); + const style = new StyleForParagraph({ id: "myStyleId" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, @@ -19,7 +19,7 @@ describe("ParagraphStyle", () => { }); it("should set the name of the style, if given", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", name: "Style Name", }); @@ -35,7 +35,7 @@ describe("ParagraphStyle", () => { describe("formatting methods: style attributes", () => { it("#basedOn", () => { - const style = new ParagraphStyle({ id: "myStyleId", basedOn: "otherId" }); + const style = new StyleForParagraph({ id: "myStyleId", basedOn: "otherId" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -46,7 +46,7 @@ describe("ParagraphStyle", () => { }); it("#quickFormat", () => { - const style = new ParagraphStyle({ id: "myStyleId", quickFormat: true }); + const style = new StyleForParagraph({ id: "myStyleId", quickFormat: true }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -62,7 +62,7 @@ describe("ParagraphStyle", () => { }); it("#next", () => { - const style = new ParagraphStyle({ id: "myStyleId", next: "otherId" }); + const style = new StyleForParagraph({ id: "myStyleId", next: "otherId" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -75,7 +75,7 @@ describe("ParagraphStyle", () => { describe("formatting methods: paragraph properties", () => { it("#indent", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { indent: { left: 720 }, @@ -93,7 +93,7 @@ describe("ParagraphStyle", () => { }); it("#spacing", () => { - const style = new ParagraphStyle({ id: "myStyleId", paragraph: { spacing: { before: 50, after: 150 } } }); + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { spacing: { before: 50, after: 150 } } }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -106,7 +106,7 @@ describe("ParagraphStyle", () => { }); it("#center", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { alignment: AlignmentType.CENTER, @@ -124,7 +124,7 @@ describe("ParagraphStyle", () => { }); it("#character spacing", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { characterSpacing: 24, @@ -142,7 +142,7 @@ describe("ParagraphStyle", () => { }); it("#left", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { alignment: AlignmentType.LEFT, @@ -160,7 +160,7 @@ describe("ParagraphStyle", () => { }); it("#right", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { alignment: AlignmentType.RIGHT, @@ -178,7 +178,7 @@ describe("ParagraphStyle", () => { }); it("#justified", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { alignment: AlignmentType.JUSTIFIED, @@ -196,7 +196,7 @@ describe("ParagraphStyle", () => { }); it("#thematicBreak", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { thematicBreak: true, @@ -229,7 +229,7 @@ describe("ParagraphStyle", () => { }); it("#contextualSpacing", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { contextualSpacing: true, @@ -255,7 +255,7 @@ describe("ParagraphStyle", () => { }); it("#leftTabStop", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { leftTabStop: 1200, @@ -277,7 +277,7 @@ describe("ParagraphStyle", () => { }); it("#maxRightTabStop", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { rightTabStop: TabStopPosition.MAX, @@ -299,7 +299,7 @@ describe("ParagraphStyle", () => { }); it("#keepLines", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { keepLines: true, @@ -320,7 +320,7 @@ describe("ParagraphStyle", () => { }); it("#keepNext", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { keepNext: true, @@ -341,7 +341,7 @@ describe("ParagraphStyle", () => { }); it("#outlineLevel", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", paragraph: { outlineLevel: 1, @@ -381,7 +381,7 @@ describe("ParagraphStyle", () => { ]; sizeTests.forEach(({ size, sizeComplexScript, expected }) => { it(`#size ${size} cs ${sizeComplexScript}`, () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { size, sizeComplexScript }, }); @@ -393,7 +393,7 @@ describe("ParagraphStyle", () => { }); it("#smallCaps", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { smallCaps: true, @@ -411,7 +411,7 @@ describe("ParagraphStyle", () => { }); it("#allCaps", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { allCaps: true, @@ -429,7 +429,7 @@ describe("ParagraphStyle", () => { }); it("#strike", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { strike: true, @@ -447,7 +447,7 @@ describe("ParagraphStyle", () => { }); it("#doubleStrike", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { doubleStrike: true, @@ -465,7 +465,7 @@ describe("ParagraphStyle", () => { }); it("#subScript", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { subScript: true, @@ -483,7 +483,7 @@ describe("ParagraphStyle", () => { }); it("#superScript", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { superScript: true, @@ -501,7 +501,7 @@ describe("ParagraphStyle", () => { }); it("#font by name", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { font: "Times", @@ -530,7 +530,7 @@ describe("ParagraphStyle", () => { }); it("#font for ascii and eastAsia", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { font: { @@ -577,7 +577,7 @@ describe("ParagraphStyle", () => { ]; boldTests.forEach(({ bold, boldComplexScript, expected }) => { it(`#bold ${bold} cs ${boldComplexScript}`, () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { bold, boldComplexScript }, }); @@ -606,7 +606,7 @@ describe("ParagraphStyle", () => { ]; italicsTests.forEach(({ italics, italicsComplexScript, expected }) => { it(`#italics ${italics} cs ${italicsComplexScript}`, () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { italics, italicsComplexScript }, }); @@ -640,7 +640,7 @@ describe("ParagraphStyle", () => { ]; highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => { it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { highlight, highlightComplexScript }, }); @@ -714,7 +714,7 @@ describe("ParagraphStyle", () => { ]; shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => { it("#shadow correctly", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { shadow, shading, shadingComplexScript }, }); @@ -727,7 +727,7 @@ describe("ParagraphStyle", () => { describe("#underline", () => { it("should set underline to 'single' if no arguments are given", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { underline: {}, @@ -745,7 +745,7 @@ describe("ParagraphStyle", () => { }); it("should set the style if given", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { underline: { @@ -765,7 +765,7 @@ describe("ParagraphStyle", () => { }); it("should set the style and color if given", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { underline: { @@ -788,7 +788,7 @@ describe("ParagraphStyle", () => { describe("#emphasisMark", () => { it("should set emphasisMark to 'dot' if no arguments are given", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { emphasisMark: {}, @@ -806,7 +806,7 @@ describe("ParagraphStyle", () => { }); it("should set the style if given", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { emphasisMark: { @@ -827,7 +827,7 @@ describe("ParagraphStyle", () => { }); it("#color", () => { - const style = new ParagraphStyle({ + const style = new StyleForParagraph({ id: "myStyleId", run: { color: "123456", @@ -845,7 +845,7 @@ describe("ParagraphStyle", () => { }); it("#link", () => { - const style = new ParagraphStyle({ id: "myStyleId", link: "MyLink" }); + const style = new StyleForParagraph({ id: "myStyleId", link: "MyLink" }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -861,7 +861,7 @@ describe("ParagraphStyle", () => { }); it("#semiHidden", () => { - const style = new ParagraphStyle({ id: "myStyleId", semiHidden: true }); + const style = new StyleForParagraph({ id: "myStyleId", semiHidden: true }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -877,7 +877,7 @@ describe("ParagraphStyle", () => { }); it("#uiPriority", () => { - const style = new ParagraphStyle({ id: "myStyleId", uiPriority: 99 }); + const style = new StyleForParagraph({ id: "myStyleId", uiPriority: 99 }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ @@ -894,7 +894,7 @@ describe("ParagraphStyle", () => { }); it("#unhideWhenUsed", () => { - const style = new ParagraphStyle({ id: "myStyleId", unhideWhenUsed: true }); + const style = new StyleForParagraph({ id: "myStyleId", unhideWhenUsed: true }); const tree = new Formatter().format(style); expect(tree).to.deep.equal({ "w:style": [ diff --git a/src/file/styles/style/paragraph-style.ts b/src/file/styles/style/paragraph-style.ts index 635e7b7e2f..25c035e514 100644 --- a/src/file/styles/style/paragraph-style.ts +++ b/src/file/styles/style/paragraph-style.ts @@ -21,7 +21,7 @@ export interface IParagraphStyleOptions extends IBaseParagraphStyleOptions { readonly name?: string; } -export class ParagraphStyle extends Style { +export class StyleForParagraph extends Style { private readonly paragraphProperties: ParagraphProperties; private readonly runProperties: RunProperties; diff --git a/src/file/styles/styles.ts b/src/file/styles/styles.ts index 45efe9f784..1fbc4b5e50 100644 --- a/src/file/styles/styles.ts +++ b/src/file/styles/styles.ts @@ -1,6 +1,6 @@ import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components"; -import { CharacterStyle, ParagraphStyle } from "./style"; +import { StyleForCharacter, StyleForParagraph } from "./style"; import { ICharacterStyleOptions } from "./style/character-style"; import { IParagraphStyleOptions } from "./style/paragraph-style"; export * from "./border"; @@ -9,7 +9,7 @@ export interface IStylesOptions { readonly initialStyles?: BaseXmlComponent; readonly paragraphStyles?: IParagraphStyleOptions[]; readonly characterStyles?: ICharacterStyleOptions[]; - readonly importedStyles?: (XmlComponent | ParagraphStyle | CharacterStyle | ImportedXmlComponent)[]; + readonly importedStyles?: (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[]; } export class Styles extends XmlComponent { @@ -28,13 +28,13 @@ export class Styles extends XmlComponent { if (options.paragraphStyles) { for (const style of options.paragraphStyles) { - this.root.push(new ParagraphStyle(style)); + this.root.push(new StyleForParagraph(style)); } } if (options.characterStyles) { for (const style of options.characterStyles) { - this.root.push(new CharacterStyle(style)); + this.root.push(new StyleForCharacter(style)); } } }