move file options.defaultStyles to options.styles.default

This commit is contained in:
Tom Hunkapiller
2020-11-30 10:25:58 -06:00
parent f3ba62fd88
commit 30ab92652c
5 changed files with 84 additions and 85 deletions

View File

@ -17,55 +17,55 @@ import {
} from "../build"; } from "../build";
const doc = new Document({ const doc = new Document({
defaultStyles: { styles: {
heading1: { default: {
run: { heading1: {
font: "Calibri", run: {
size: 52, font: "Calibri",
bold: true, size: 52,
color: "000000", bold: true,
underline: {
type: UnderlineType.SINGLE,
color: "000000", color: "000000",
underline: {
type: UnderlineType.SINGLE,
color: "000000",
},
},
paragraph: {
alignment: AlignmentType.CENTER,
spacing: { line: 340 },
}, },
}, },
paragraph: { heading2: {
alignment: AlignmentType.CENTER, run: {
spacing: { line: 340 }, 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: [ paragraphStyles: [
{ {
id: "normalPara", id: "normalPara",

View File

@ -7,43 +7,43 @@ const doc = new Document({
creator: "Clippy", creator: "Clippy",
title: "Sample Document", title: "Sample Document",
description: "A brief example of using docx", 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: { 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: [ paragraphStyles: [
{ {
id: "aside", id: "aside",

View File

@ -1,4 +1,3 @@
import { IDefaultStylesOptions } from "file/styles/factory";
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
import { IDocumentBackgroundOptions } from "../document"; import { IDocumentBackgroundOptions } from "../document";
@ -29,7 +28,6 @@ export interface IPropertiesOptions {
readonly revision?: string; readonly revision?: string;
readonly externalStyles?: string; readonly externalStyles?: string;
readonly styles?: IStylesOptions; readonly styles?: IStylesOptions;
readonly defaultStyles?: IDefaultStylesOptions;
readonly numbering?: INumberingOptions; readonly numbering?: INumberingOptions;
readonly footnotes?: Paragraph[]; readonly footnotes?: Paragraph[];
readonly hyperlinks?: { readonly hyperlinks?: {

View File

@ -106,14 +106,14 @@ export class File {
this.styles = stylesFactory.newInstance(options.externalStyles); this.styles = stylesFactory.newInstance(options.externalStyles);
} else if (options.styles) { } else if (options.styles) {
const stylesFactory = new DefaultStylesFactory(); const stylesFactory = new DefaultStylesFactory();
const defaultStyles = stylesFactory.newInstance(options.defaultStyles); const defaultStyles = stylesFactory.newInstance(options.styles.default);
this.styles = new Styles({ this.styles = new Styles({
...defaultStyles, ...defaultStyles,
...options.styles, ...options.styles,
}); });
} else { } else {
const stylesFactory = new DefaultStylesFactory(); const stylesFactory = new DefaultStylesFactory();
this.styles = new Styles(stylesFactory.newInstance(options.defaultStyles)); this.styles = new Styles(stylesFactory.newInstance());
} }
this.addDefaultRelationships(); this.addDefaultRelationships();

View File

@ -1,11 +1,12 @@
import { IDefaultStylesOptions } from "file/styles/factory";
import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components"; import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components";
import { StyleForCharacter, StyleForParagraph } from "./style"; import { StyleForCharacter, StyleForParagraph } from "./style";
import { ICharacterStyleOptions } from "./style/character-style"; import { ICharacterStyleOptions } from "./style/character-style";
import { IParagraphStyleOptions } from "./style/paragraph-style"; import { IParagraphStyleOptions } from "./style/paragraph-style";
export * from "./border"; export * from "./border";
export interface IStylesOptions { export interface IStylesOptions {
readonly default?: IDefaultStylesOptions;
readonly initialStyles?: BaseXmlComponent; readonly initialStyles?: BaseXmlComponent;
readonly paragraphStyles?: IParagraphStyleOptions[]; readonly paragraphStyles?: IParagraphStyleOptions[];
readonly characterStyles?: ICharacterStyleOptions[]; readonly characterStyles?: ICharacterStyleOptions[];