2019-10-04 01:20:41 +01:00
|
|
|
import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components";
|
|
|
|
|
2020-11-06 00:27:57 +00:00
|
|
|
import { StyleForCharacter, StyleForParagraph } from "./style";
|
2019-10-04 01:20:41 +01:00
|
|
|
import { ICharacterStyleOptions } from "./style/character-style";
|
|
|
|
import { IParagraphStyleOptions } from "./style/paragraph-style";
|
2018-10-26 01:04:07 +01:00
|
|
|
export * from "./border";
|
|
|
|
|
2019-10-04 02:37:22 +01:00
|
|
|
export interface IStylesOptions {
|
2019-10-04 01:20:41 +01:00
|
|
|
readonly initialStyles?: BaseXmlComponent;
|
|
|
|
readonly paragraphStyles?: IParagraphStyleOptions[];
|
|
|
|
readonly characterStyles?: ICharacterStyleOptions[];
|
2020-11-06 00:27:57 +00:00
|
|
|
readonly importedStyles?: (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[];
|
2019-10-04 01:20:41 +01:00
|
|
|
}
|
|
|
|
|
2018-10-26 01:04:07 +01:00
|
|
|
export class Styles extends XmlComponent {
|
2019-10-04 01:20:41 +01:00
|
|
|
constructor(options: IStylesOptions) {
|
2018-10-26 01:04:07 +01:00
|
|
|
super("w:styles");
|
2019-10-04 01:20:41 +01:00
|
|
|
|
|
|
|
if (options.initialStyles) {
|
|
|
|
this.root.push(options.initialStyles);
|
|
|
|
}
|
|
|
|
|
2019-10-04 02:37:22 +01:00
|
|
|
if (options.importedStyles) {
|
|
|
|
for (const style of options.importedStyles) {
|
|
|
|
this.root.push(style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
if (options.paragraphStyles) {
|
|
|
|
for (const style of options.paragraphStyles) {
|
2020-11-06 00:27:57 +00:00
|
|
|
this.root.push(new StyleForParagraph(style));
|
2019-10-04 01:20:41 +01:00
|
|
|
}
|
2018-10-26 01:04:07 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
if (options.characterStyles) {
|
|
|
|
for (const style of options.characterStyles) {
|
2020-11-06 00:27:57 +00:00
|
|
|
this.root.push(new StyleForCharacter(style));
|
2019-10-04 01:20:41 +01:00
|
|
|
}
|
|
|
|
}
|
2018-10-26 01:04:07 +01:00
|
|
|
}
|
|
|
|
}
|