2018-06-09 23:49:01 +01:00
|
|
|
import { XmlComponent } from "file/xml-components";
|
2018-01-31 00:31:54 +00:00
|
|
|
import { Header } from "./header/header";
|
2018-08-03 00:01:42 +01:00
|
|
|
import { Media } from "./media";
|
|
|
|
import { Image, Paragraph } from "./paragraph";
|
2018-01-31 00:31:54 +00:00
|
|
|
import { Relationships } from "./relationships";
|
|
|
|
import { Table } from "./table";
|
|
|
|
|
|
|
|
export class HeaderWrapper {
|
|
|
|
private readonly header: Header;
|
|
|
|
private readonly relationships: Relationships;
|
|
|
|
|
2018-06-21 12:03:34 +02:00
|
|
|
constructor(private readonly media: Media, referenceId: number) {
|
|
|
|
this.header = new Header(referenceId);
|
2018-01-31 00:31:54 +00:00
|
|
|
this.relationships = new Relationships();
|
|
|
|
}
|
|
|
|
|
|
|
|
public addParagraph(paragraph: Paragraph): void {
|
|
|
|
this.header.addParagraph(paragraph);
|
|
|
|
}
|
|
|
|
|
|
|
|
public createParagraph(text?: string): Paragraph {
|
|
|
|
const para = new Paragraph(text);
|
|
|
|
this.addParagraph(para);
|
|
|
|
return para;
|
|
|
|
}
|
|
|
|
|
|
|
|
public addTable(table: Table): void {
|
|
|
|
this.header.addTable(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
public createTable(rows: number, cols: number): Table {
|
|
|
|
return this.header.createTable(rows, cols);
|
|
|
|
}
|
|
|
|
|
2018-06-09 23:49:01 +01:00
|
|
|
public addChildElement(childElement: XmlComponent | string): void {
|
2018-05-28 09:15:44 +02:00
|
|
|
this.header.addChildElement(childElement);
|
|
|
|
}
|
|
|
|
|
2018-01-31 00:31:54 +00:00
|
|
|
public createImage(image: string): void {
|
|
|
|
const mediaData = this.media.addMedia(image, this.relationships.RelationshipCount);
|
|
|
|
this.relationships.createRelationship(
|
|
|
|
mediaData.referenceId,
|
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
|
|
|
`media/${mediaData.fileName}`,
|
|
|
|
);
|
2018-08-03 00:01:42 +01:00
|
|
|
this.insertImage(new Image(mediaData));
|
|
|
|
}
|
|
|
|
|
|
|
|
public insertImage(image: Image): HeaderWrapper {
|
|
|
|
this.header.addParagraph(image);
|
|
|
|
return this;
|
2018-01-31 00:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public get Header(): Header {
|
|
|
|
return this.header;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get Relationships(): Relationships {
|
|
|
|
return this.relationships;
|
|
|
|
}
|
|
|
|
}
|