From 36e1c5fe6a72d8b4d41e07923201f70970a1137d Mon Sep 17 00:00:00 2001 From: wangfengming Date: Wed, 15 Jul 2020 14:10:37 +0800 Subject: [PATCH] :feat: refined defaults --- src/file/styles/defaults/document-defaults.ts | 25 +++++++++++++++++ src/file/styles/defaults/index.ts | 28 ++----------------- src/file/styles/defaults/run-properties.ts | 13 --------- 3 files changed, 28 insertions(+), 38 deletions(-) create mode 100644 src/file/styles/defaults/document-defaults.ts diff --git a/src/file/styles/defaults/document-defaults.ts b/src/file/styles/defaults/document-defaults.ts new file mode 100644 index 0000000000..1f97bb2b07 --- /dev/null +++ b/src/file/styles/defaults/document-defaults.ts @@ -0,0 +1,25 @@ +import { IParagraphStylePropertiesOptions } from "file/paragraph/properties"; +import { IRunStylePropertiesOptions } from "file/paragraph/run/properties"; +import { XmlComponent } from "file/xml-components"; +import { ParagraphPropertiesDefaults } from "./paragraph-properties"; +import { RunPropertiesDefaults } from "./run-properties"; + +export interface IDocumentDefaultsOptions { + readonly paragraph?: IParagraphStylePropertiesOptions; + readonly run?: IRunStylePropertiesOptions; +} + +export class DocumentDefaults extends XmlComponent { + private readonly runPropertiesDefaults: RunPropertiesDefaults; + private readonly paragraphPropertiesDefaults: ParagraphPropertiesDefaults; + + constructor(options?: IDocumentDefaultsOptions) { + super("w:docDefaults"); + + this.runPropertiesDefaults = new RunPropertiesDefaults(options && options.run); + this.paragraphPropertiesDefaults = new ParagraphPropertiesDefaults(options && options.paragraph); + + this.root.push(this.runPropertiesDefaults); + this.root.push(this.paragraphPropertiesDefaults); + } +} diff --git a/src/file/styles/defaults/index.ts b/src/file/styles/defaults/index.ts index 1f97bb2b07..986aa6194d 100644 --- a/src/file/styles/defaults/index.ts +++ b/src/file/styles/defaults/index.ts @@ -1,25 +1,3 @@ -import { IParagraphStylePropertiesOptions } from "file/paragraph/properties"; -import { IRunStylePropertiesOptions } from "file/paragraph/run/properties"; -import { XmlComponent } from "file/xml-components"; -import { ParagraphPropertiesDefaults } from "./paragraph-properties"; -import { RunPropertiesDefaults } from "./run-properties"; - -export interface IDocumentDefaultsOptions { - readonly paragraph?: IParagraphStylePropertiesOptions; - readonly run?: IRunStylePropertiesOptions; -} - -export class DocumentDefaults extends XmlComponent { - private readonly runPropertiesDefaults: RunPropertiesDefaults; - private readonly paragraphPropertiesDefaults: ParagraphPropertiesDefaults; - - constructor(options?: IDocumentDefaultsOptions) { - super("w:docDefaults"); - - this.runPropertiesDefaults = new RunPropertiesDefaults(options && options.run); - this.paragraphPropertiesDefaults = new ParagraphPropertiesDefaults(options && options.paragraph); - - this.root.push(this.runPropertiesDefaults); - this.root.push(this.paragraphPropertiesDefaults); - } -} +export * from "./paragraph-properties"; +export * from "./run-properties"; +export * from "./document-defaults"; diff --git a/src/file/styles/defaults/run-properties.ts b/src/file/styles/defaults/run-properties.ts index 7852306faa..f4e594ab99 100644 --- a/src/file/styles/defaults/run-properties.ts +++ b/src/file/styles/defaults/run-properties.ts @@ -1,6 +1,4 @@ -import { Size, SizeComplexScript } from "file/paragraph/run/formatting"; import { IRunStylePropertiesOptions, RunProperties } from "file/paragraph/run/properties"; -import { IFontAttributesProperties, RunFonts } from "file/paragraph/run/run-fonts"; import { XmlComponent } from "file/xml-components"; export class RunPropertiesDefaults extends XmlComponent { @@ -11,15 +9,4 @@ export class RunPropertiesDefaults extends XmlComponent { this.properties = new RunProperties(options); this.root.push(this.properties); } - - public size(size: number): RunPropertiesDefaults { - this.properties.push(new Size(size)); - this.properties.push(new SizeComplexScript(size)); - return this; - } - - public font(font: string | IFontAttributesProperties): RunPropertiesDefaults { - this.properties.push(new RunFonts(font)); - return this; - } }