2019-10-04 01:20:41 +01:00
|
|
|
import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components";
|
|
|
|
|
2018-10-26 01:04:07 +01:00
|
|
|
import { DocumentDefaults } from "./defaults";
|
2018-11-13 11:04:03 -02:00
|
|
|
import { CharacterStyle, ParagraphStyle } 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 01:20:41 +01:00
|
|
|
interface IStylesOptions {
|
|
|
|
readonly initialStyles?: BaseXmlComponent;
|
|
|
|
readonly paragraphStyles?: IParagraphStyleOptions[];
|
|
|
|
readonly characterStyles?: ICharacterStyleOptions[];
|
|
|
|
readonly importedStyles?: Array<XmlComponent | ParagraphStyle | CharacterStyle | ImportedXmlComponent>;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.paragraphStyles) {
|
|
|
|
for (const style of options.paragraphStyles) {
|
|
|
|
this.root.push(new ParagraphStyle(style));
|
|
|
|
}
|
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) {
|
|
|
|
this.root.push(new CharacterStyle(style));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.importedStyles) {
|
|
|
|
for (const style of options.importedStyles) {
|
|
|
|
this.root.push(style);
|
|
|
|
}
|
|
|
|
}
|
2018-10-26 01:04:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public createDocumentDefaults(): DocumentDefaults {
|
|
|
|
const defaults = new DocumentDefaults();
|
2019-10-04 01:20:41 +01:00
|
|
|
this.root.push(defaults);
|
2018-10-26 01:04:07 +01:00
|
|
|
return defaults;
|
|
|
|
}
|
|
|
|
}
|