From 30ab92652c6b32a93587e6cac0d020bb37b158e6 Mon Sep 17 00:00:00 2001 From: Tom Hunkapiller Date: Mon, 30 Nov 2020 10:25:58 -0600 Subject: [PATCH] move file options.defaultStyles to options.styles.default --- demo/11-declaritive-styles-2.ts | 88 +++++++++++++------------- demo/2-declaritive-styles.ts | 72 ++++++++++----------- src/file/core-properties/properties.ts | 2 - src/file/file.ts | 4 +- src/file/styles/styles.ts | 3 +- 5 files changed, 84 insertions(+), 85 deletions(-) diff --git a/demo/11-declaritive-styles-2.ts b/demo/11-declaritive-styles-2.ts index 10bc93c17e..5fe9e16ae6 100644 --- a/demo/11-declaritive-styles-2.ts +++ b/demo/11-declaritive-styles-2.ts @@ -17,55 +17,55 @@ import { } from "../build"; const doc = new Document({ - defaultStyles: { - heading1: { - run: { - font: "Calibri", - size: 52, - bold: true, - color: "000000", - underline: { - type: UnderlineType.SINGLE, + styles: { + default: { + heading1: { + run: { + font: "Calibri", + size: 52, + bold: true, color: "000000", + underline: { + type: UnderlineType.SINGLE, + color: "000000", + }, + }, + paragraph: { + alignment: AlignmentType.CENTER, + spacing: { line: 340 }, }, }, - paragraph: { - alignment: AlignmentType.CENTER, - spacing: { line: 340 }, + heading2: { + run: { + font: "Calibri", + size: 26, + bold: true, + }, + paragraph: { + spacing: { line: 340 }, + }, + }, + heading3: { + run: { + font: "Calibri", + size: 26, + bold: true, + }, + paragraph: { + spacing: { line: 276 }, + }, + }, + heading4: { + run: { + font: "Calibri", + size: 26, + bold: true, + }, + paragraph: { + alignment: AlignmentType.JUSTIFIED, + }, }, }, - heading2: { - run: { - font: "Calibri", - size: 26, - bold: true, - }, - paragraph: { - spacing: { line: 340 }, - }, - }, - heading3: { - run: { - font: "Calibri", - size: 26, - bold: true, - }, - paragraph: { - spacing: { line: 276 }, - }, - }, - heading4: { - run: { - font: "Calibri", - size: 26, - bold: true, - }, - paragraph: { - alignment: AlignmentType.JUSTIFIED, - }, - }, - }, - styles: { paragraphStyles: [ { id: "normalPara", diff --git a/demo/2-declaritive-styles.ts b/demo/2-declaritive-styles.ts index f01877a8d5..6f3add1f19 100644 --- a/demo/2-declaritive-styles.ts +++ b/demo/2-declaritive-styles.ts @@ -7,43 +7,43 @@ const doc = new Document({ creator: "Clippy", title: "Sample Document", description: "A brief example of using docx", - defaultStyles: { - heading1: { - run: { - size: 28, - bold: true, - italics: true, - color: "red", - }, - paragraph: { - spacing: { - after: 120, - }, - }, - }, - heading2: { - run: { - size: 26, - bold: true, - underline: { - type: UnderlineType.DOUBLE, - color: "FF0000", - }, - }, - paragraph: { - spacing: { - before: 240, - after: 120, - }, - }, - }, - listParagraph: { - run: { - color: '#FF0000' - } - } - }, styles: { + default: { + heading1: { + run: { + size: 28, + bold: true, + italics: true, + color: "red", + }, + paragraph: { + spacing: { + after: 120, + }, + }, + }, + heading2: { + run: { + size: 26, + bold: true, + underline: { + type: UnderlineType.DOUBLE, + color: "FF0000", + }, + }, + paragraph: { + spacing: { + before: 240, + after: 120, + }, + }, + }, + listParagraph: { + run: { + color: '#FF0000' + } + } + }, paragraphStyles: [ { id: "aside", diff --git a/src/file/core-properties/properties.ts b/src/file/core-properties/properties.ts index a36828aca6..ae9f227ad5 100644 --- a/src/file/core-properties/properties.ts +++ b/src/file/core-properties/properties.ts @@ -1,4 +1,3 @@ -import { IDefaultStylesOptions } from "file/styles/factory"; import { XmlComponent } from "file/xml-components"; import { IDocumentBackgroundOptions } from "../document"; @@ -29,7 +28,6 @@ export interface IPropertiesOptions { readonly revision?: string; readonly externalStyles?: string; readonly styles?: IStylesOptions; - readonly defaultStyles?: IDefaultStylesOptions; readonly numbering?: INumberingOptions; readonly footnotes?: Paragraph[]; readonly hyperlinks?: { diff --git a/src/file/file.ts b/src/file/file.ts index 2c351f3df3..90986d16d7 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -106,14 +106,14 @@ export class File { this.styles = stylesFactory.newInstance(options.externalStyles); } else if (options.styles) { const stylesFactory = new DefaultStylesFactory(); - const defaultStyles = stylesFactory.newInstance(options.defaultStyles); + const defaultStyles = stylesFactory.newInstance(options.styles.default); this.styles = new Styles({ ...defaultStyles, ...options.styles, }); } else { const stylesFactory = new DefaultStylesFactory(); - this.styles = new Styles(stylesFactory.newInstance(options.defaultStyles)); + this.styles = new Styles(stylesFactory.newInstance()); } this.addDefaultRelationships(); diff --git a/src/file/styles/styles.ts b/src/file/styles/styles.ts index 1fbc4b5e50..1906b45ba0 100644 --- a/src/file/styles/styles.ts +++ b/src/file/styles/styles.ts @@ -1,11 +1,12 @@ +import { IDefaultStylesOptions } from "file/styles/factory"; import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components"; - import { StyleForCharacter, StyleForParagraph } from "./style"; import { ICharacterStyleOptions } from "./style/character-style"; import { IParagraphStyleOptions } from "./style/paragraph-style"; export * from "./border"; export interface IStylesOptions { + readonly default?: IDefaultStylesOptions; readonly initialStyles?: BaseXmlComponent; readonly paragraphStyles?: IParagraphStyleOptions[]; readonly characterStyles?: ICharacterStyleOptions[];