Fix linting errors
This commit is contained in:
@ -59,13 +59,13 @@ export class Compiler {
|
||||
}
|
||||
|
||||
for (const header of file.Headers) {
|
||||
for (const data of header.media.Array) {
|
||||
for (const data of header.Media.Array) {
|
||||
zip.file(`word/media/${data.fileName}`, data.stream);
|
||||
}
|
||||
}
|
||||
|
||||
for (const footer of file.Footers) {
|
||||
for (const data of footer.media.Array) {
|
||||
for (const data of footer.Media.Array) {
|
||||
zip.file(`word/media/${data.fileName}`, data.stream);
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ describe("SectionProperties", () => {
|
||||
gutter: 0,
|
||||
space: 708,
|
||||
linePitch: 360,
|
||||
headers: [{headerId: 100, headerType: HeaderReferenceType.DEFAULT}],
|
||||
footers: [{footerId: 200, footerType: FooterReferenceType.EVEN}],
|
||||
headers: [{ headerId: 100, headerType: HeaderReferenceType.DEFAULT }],
|
||||
footers: [{ footerId: 200, footerType: FooterReferenceType.EVEN }],
|
||||
pageNumberStart: 10,
|
||||
pageNumberFormatType: PageNumberFormat.CARDINAL_TEXT,
|
||||
});
|
||||
|
@ -13,8 +13,13 @@ import { PageSize } from "./page-size/page-size";
|
||||
import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attributes";
|
||||
import { TitlePage } from "./title-page/title-page";
|
||||
|
||||
type IHeadersOptions = {headers? : IHeaderOptions[]}
|
||||
type IFootersOptions = {footers? : IFooterOptions[]}
|
||||
interface IHeadersOptions {
|
||||
headers?: IHeaderOptions[];
|
||||
}
|
||||
|
||||
interface IFootersOptions {
|
||||
footers?: IFooterOptions[];
|
||||
}
|
||||
|
||||
export type SectionPropertiesOptions = IPageSizeAttributes &
|
||||
IPageMarginAttributes &
|
||||
@ -53,7 +58,7 @@ export class SectionProperties extends XmlComponent {
|
||||
pageBorderRight: undefined,
|
||||
pageBorderBottom: undefined,
|
||||
pageBorderLeft: undefined,
|
||||
titlePage : true
|
||||
titlePage: true,
|
||||
};
|
||||
|
||||
const mergedOptions = {
|
||||
@ -61,7 +66,6 @@ export class SectionProperties extends XmlComponent {
|
||||
...options,
|
||||
};
|
||||
|
||||
|
||||
this.root.push(new PageSize(mergedOptions.width, mergedOptions.height, mergedOptions.orientation));
|
||||
this.root.push(
|
||||
new PageMargin(
|
||||
@ -77,7 +81,7 @@ export class SectionProperties extends XmlComponent {
|
||||
this.root.push(new Columns(mergedOptions.space));
|
||||
this.root.push(new DocumentGrid(mergedOptions.linePitch));
|
||||
|
||||
for (let header of mergedOptions.headers) {
|
||||
for (const header of mergedOptions.headers) {
|
||||
this.root.push(
|
||||
new HeaderReference({
|
||||
headerType: header.headerType,
|
||||
@ -86,7 +90,7 @@ export class SectionProperties extends XmlComponent {
|
||||
);
|
||||
}
|
||||
|
||||
for (let footer of mergedOptions.footers) {
|
||||
for (const footer of mergedOptions.footers) {
|
||||
this.root.push(
|
||||
new FooterReference({
|
||||
footerType: footer.footerType,
|
||||
@ -94,7 +98,7 @@ export class SectionProperties extends XmlComponent {
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
this.root.push(new PageNumberType(mergedOptions.pageNumberStart, mergedOptions.pageNumberFormatType));
|
||||
|
||||
if (
|
||||
|
@ -224,32 +224,12 @@ export class File {
|
||||
return header;
|
||||
}
|
||||
|
||||
private addHeaderToDocument(header: HeaderWrapper, type: HeaderReferenceType = HeaderReferenceType.DEFAULT): void {
|
||||
this.documentHeaders.push({ header, type });
|
||||
this.docRelationships.createRelationship(
|
||||
header.Header.ReferenceId,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
|
||||
`header${this.documentHeaders.length}.xml`,
|
||||
);
|
||||
this.contentTypes.addHeader(this.documentHeaders.length);
|
||||
}
|
||||
|
||||
public createFooter(): FooterWrapper {
|
||||
const footer = new FooterWrapper(this.currentRelationshipId++);
|
||||
this.addFooterToDocument(footer);
|
||||
return footer;
|
||||
}
|
||||
|
||||
private addFooterToDocument(footer: FooterWrapper, type: FooterReferenceType = FooterReferenceType.DEFAULT): void {
|
||||
this.documentFooters.push({ footer, type });
|
||||
this.docRelationships.createRelationship(
|
||||
footer.Footer.ReferenceId,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
|
||||
`footer${this.documentFooters.length}.xml`,
|
||||
);
|
||||
this.contentTypes.addFooter(this.documentFooters.length);
|
||||
}
|
||||
|
||||
public createFirstPageHeader(): HeaderWrapper {
|
||||
const headerWrapper = this.createHeader();
|
||||
|
||||
@ -263,6 +243,42 @@ export class File {
|
||||
return headerWrapper;
|
||||
}
|
||||
|
||||
public getFooterByRefNumber(refId: number): FooterWrapper {
|
||||
const entry = this.documentFooters.map((item) => item.footer).find((h) => h.Footer.ReferenceId === refId);
|
||||
if (entry) {
|
||||
return entry;
|
||||
}
|
||||
throw new Error(`There is no footer with given reference id ${refId}`);
|
||||
}
|
||||
|
||||
public getHeaderByRefNumber(refId: number): HeaderWrapper {
|
||||
const entry = this.documentHeaders.map((item) => item.header).find((h) => h.Header.ReferenceId === refId);
|
||||
if (entry) {
|
||||
return entry;
|
||||
}
|
||||
throw new Error(`There is no header with given reference id ${refId}`);
|
||||
}
|
||||
|
||||
private addHeaderToDocument(header: HeaderWrapper, type: HeaderReferenceType = HeaderReferenceType.DEFAULT): void {
|
||||
this.documentHeaders.push({ header, type });
|
||||
this.docRelationships.createRelationship(
|
||||
header.Header.ReferenceId,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
|
||||
`header${this.documentHeaders.length}.xml`,
|
||||
);
|
||||
this.contentTypes.addHeader(this.documentHeaders.length);
|
||||
}
|
||||
|
||||
private addFooterToDocument(footer: FooterWrapper, type: FooterReferenceType = FooterReferenceType.DEFAULT): void {
|
||||
this.documentFooters.push({ footer, type });
|
||||
this.docRelationships.createRelationship(
|
||||
footer.Footer.ReferenceId,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
|
||||
`footer${this.documentFooters.length}.xml`,
|
||||
);
|
||||
this.contentTypes.addFooter(this.documentFooters.length);
|
||||
}
|
||||
|
||||
public get Document(): Document {
|
||||
return this.document;
|
||||
}
|
||||
@ -299,14 +315,6 @@ export class File {
|
||||
return this.documentHeaders.map((item) => item.header);
|
||||
}
|
||||
|
||||
public HeaderByRefNumber(refId: number): HeaderWrapper {
|
||||
const entry = this.documentHeaders.map((item) => item.header).find((h) => h.Header.ReferenceId === refId);
|
||||
if (entry) {
|
||||
return entry;
|
||||
}
|
||||
throw new Error(`There is no header with given reference id ${refId}`);
|
||||
}
|
||||
|
||||
public get Footer(): FooterWrapper {
|
||||
return this.documentFooters[0].footer;
|
||||
}
|
||||
@ -315,14 +323,6 @@ export class File {
|
||||
return this.documentFooters.map((item) => item.footer);
|
||||
}
|
||||
|
||||
public FooterByRefNumber(refId: number): FooterWrapper {
|
||||
const entry = this.documentFooters.map((item) => item.footer).find((h) => h.Footer.ReferenceId === refId);
|
||||
if (entry) {
|
||||
return entry;
|
||||
}
|
||||
throw new Error(`There is no footer with given reference id ${refId}`);
|
||||
}
|
||||
|
||||
public get ContentTypes(): ContentTypes {
|
||||
return this.contentTypes;
|
||||
}
|
||||
|
@ -1,20 +1,19 @@
|
||||
import { IMediaData } from "file/media";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { Footer } from "./footer/footer";
|
||||
import { Image, Media } from "./media";
|
||||
import { ImageParagraph, Paragraph } from "./paragraph";
|
||||
import { Relationships } from "./relationships";
|
||||
import { Table } from "./table";
|
||||
import { IMediaData } from 'file/media';
|
||||
|
||||
export class FooterWrapper {
|
||||
private readonly footer: Footer;
|
||||
private readonly relationships: Relationships;
|
||||
public readonly media = new Media();
|
||||
private readonly media = new Media();
|
||||
|
||||
constructor(referenceId: number, initContent? : XmlComponent) {
|
||||
constructor(referenceId: number, initContent?: XmlComponent) {
|
||||
this.footer = new Footer(referenceId, initContent);
|
||||
this.relationships = new Relationships();
|
||||
|
||||
}
|
||||
|
||||
public addParagraph(paragraph: Paragraph): void {
|
||||
@ -39,7 +38,7 @@ export class FooterWrapper {
|
||||
this.footer.addChildElement(childElement);
|
||||
}
|
||||
|
||||
public addImageRelation(image: Buffer, refId : number, width?: number, height?: number) : IMediaData {
|
||||
public addImageRelation(image: Buffer, refId: number, width?: number, height?: number): IMediaData {
|
||||
const mediaData = this.media.addMedia(image, refId, width, height);
|
||||
this.relationships.createRelationship(
|
||||
refId,
|
||||
@ -48,13 +47,12 @@ export class FooterWrapper {
|
||||
);
|
||||
return mediaData;
|
||||
}
|
||||
|
||||
|
||||
public createImage(image: Buffer, width?: number, height?: number): void {
|
||||
let mediaData = this.addImageRelation(image, this.relationships.RelationshipCount, width, height);
|
||||
const mediaData = this.addImageRelation(image, this.relationships.RelationshipCount, width, height);
|
||||
this.addImage(new Image(new ImageParagraph(mediaData)));
|
||||
}
|
||||
|
||||
|
||||
public addImage(image: Image): FooterWrapper {
|
||||
this.footer.addParagraph(image.Paragraph);
|
||||
return this;
|
||||
@ -67,4 +65,8 @@ export class FooterWrapper {
|
||||
public get Relationships(): Relationships {
|
||||
return this.relationships;
|
||||
}
|
||||
|
||||
public get Media(): Media {
|
||||
return this.media;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import { FooterAttributes } from "./footer-attributes";
|
||||
export class Footer extends XmlComponent {
|
||||
private readonly refId: number;
|
||||
|
||||
constructor(referenceNumber: number, initContent? : XmlComponent) {
|
||||
constructor(referenceNumber: number, initContent?: XmlComponent) {
|
||||
super("w:ftr", initContent);
|
||||
this.refId = referenceNumber;
|
||||
this.root.push(
|
||||
|
@ -9,7 +9,7 @@ import { Table } from "./table";
|
||||
export class HeaderWrapper {
|
||||
private readonly header: Header;
|
||||
private readonly relationships: Relationships;
|
||||
public readonly media = new Media();
|
||||
private readonly media = new Media();
|
||||
|
||||
// constructor(private readonly media: Media, referenceId: number, initContent? : XmlComponent) {
|
||||
constructor(referenceId: number, initContent?: XmlComponent) {
|
||||
@ -66,4 +66,8 @@ export class HeaderWrapper {
|
||||
public get Relationships(): Relationships {
|
||||
return this.relationships;
|
||||
}
|
||||
|
||||
public get Media(): Media {
|
||||
return this.media;
|
||||
}
|
||||
}
|
||||
|
@ -23,17 +23,17 @@ export interface IHeaderAttributesProperties {
|
||||
dcmitype?: string;
|
||||
xsi?: string;
|
||||
type?: string;
|
||||
cx? : string,
|
||||
cx1? : string,
|
||||
cx2? : string,
|
||||
cx3? : string,
|
||||
cx4? : string,
|
||||
cx5? : string,
|
||||
cx6? : string,
|
||||
cx7? : string,
|
||||
cx8? : string,
|
||||
w16cid: string,
|
||||
w16se: string
|
||||
cx?: string;
|
||||
cx1?: string;
|
||||
cx2?: string;
|
||||
cx3?: string;
|
||||
cx4?: string;
|
||||
cx5?: string;
|
||||
cx6?: string;
|
||||
cx7?: string;
|
||||
cx8?: string;
|
||||
w16cid: string;
|
||||
w16se: string;
|
||||
}
|
||||
|
||||
export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesProperties> {
|
||||
@ -60,7 +60,7 @@ export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesPro
|
||||
dcmitype: "xmlns:dcmitype",
|
||||
xsi: "xmlns:xsi",
|
||||
type: "xsi:type",
|
||||
cx : "xmlns:cx",
|
||||
cx: "xmlns:cx",
|
||||
cx1: "xmlns:cx1",
|
||||
cx2: "xmlns:cx2",
|
||||
cx3: "xmlns:cx3",
|
||||
@ -69,7 +69,7 @@ export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesPro
|
||||
cx6: "xmlns:cx6",
|
||||
cx7: "xmlns:cx7",
|
||||
cx8: "xmlns:cx8",
|
||||
w16cid: "xmlns:w16cid",
|
||||
w16se: "xmlns:w16se"
|
||||
w16cid: "xmlns:w16cid",
|
||||
w16se: "xmlns:w16se",
|
||||
};
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ export const parseOptions = {
|
||||
ignoreAttributes: false,
|
||||
attributeNamePrefix: "",
|
||||
attrNodeName: "_attr",
|
||||
textNodeName: '',
|
||||
trimValues: false
|
||||
textNodeName: "",
|
||||
trimValues: false,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -59,7 +59,6 @@ export class ImportedXmlComponent extends XmlComponent {
|
||||
private _attr: any;
|
||||
|
||||
constructor(rootKey: string, _attr?: any) {
|
||||
|
||||
super(rootKey);
|
||||
if (_attr) {
|
||||
this._attr = _attr;
|
||||
|
@ -87,7 +87,11 @@ export class ImportDocx {
|
||||
return templateDocument;
|
||||
}
|
||||
|
||||
public async addImagesToWrapper(relationFile: IRelationFileInfo, zipContent: JSZip, wrapper: HeaderWrapper | FooterWrapper): Promise<void> {
|
||||
public async addImagesToWrapper(
|
||||
relationFile: IRelationFileInfo,
|
||||
zipContent: JSZip,
|
||||
wrapper: HeaderWrapper | FooterWrapper,
|
||||
): Promise<void> {
|
||||
let wrapperImagesReferences: IRelationFileInfo[] = [];
|
||||
const refFile = zipContent.files[`word/_rels/${relationFile.targetFile}.rels`];
|
||||
if (refFile) {
|
||||
|
Reference in New Issue
Block a user