Declarative styles
This commit is contained in:
@ -1,36 +1,48 @@
|
||||
import { BaseXmlComponent, XmlComponent } from "file/xml-components";
|
||||
import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
import { DocumentDefaults } from "./defaults";
|
||||
import { CharacterStyle, ParagraphStyle } from "./style";
|
||||
import { ICharacterStyleOptions } from "./style/character-style";
|
||||
import { IParagraphStyleOptions } from "./style/paragraph-style";
|
||||
export * from "./border";
|
||||
|
||||
export class Styles extends XmlComponent {
|
||||
constructor(initialStyles?: BaseXmlComponent) {
|
||||
super("w:styles");
|
||||
if (initialStyles) {
|
||||
this.root.push(initialStyles);
|
||||
}
|
||||
}
|
||||
interface IStylesOptions {
|
||||
readonly initialStyles?: BaseXmlComponent;
|
||||
readonly paragraphStyles?: IParagraphStyleOptions[];
|
||||
readonly characterStyles?: ICharacterStyleOptions[];
|
||||
readonly importedStyles?: Array<XmlComponent | ParagraphStyle | CharacterStyle | ImportedXmlComponent>;
|
||||
}
|
||||
|
||||
public push(style: XmlComponent): Styles {
|
||||
this.root.push(style);
|
||||
return this;
|
||||
export class Styles extends XmlComponent {
|
||||
constructor(options: IStylesOptions) {
|
||||
super("w:styles");
|
||||
|
||||
if (options.initialStyles) {
|
||||
this.root.push(options.initialStyles);
|
||||
}
|
||||
|
||||
if (options.paragraphStyles) {
|
||||
for (const style of options.paragraphStyles) {
|
||||
this.root.push(new ParagraphStyle(style));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public createDocumentDefaults(): DocumentDefaults {
|
||||
const defaults = new DocumentDefaults();
|
||||
this.push(defaults);
|
||||
this.root.push(defaults);
|
||||
return defaults;
|
||||
}
|
||||
|
||||
public createParagraphStyle(styleId: string, name?: string): ParagraphStyle {
|
||||
const paragraphStyle = new ParagraphStyle(styleId, name);
|
||||
this.push(paragraphStyle);
|
||||
return paragraphStyle;
|
||||
}
|
||||
|
||||
public createCharacterStyle(styleId: string, name?: string): CharacterStyle {
|
||||
const characterStyle = new CharacterStyle(styleId, name);
|
||||
this.push(characterStyle);
|
||||
return characterStyle;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user