Fix linting errors
This commit is contained in:
@ -59,13 +59,13 @@ export class Compiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const header of file.Headers) {
|
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);
|
zip.file(`word/media/${data.fileName}`, data.stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const footer of file.Footers) {
|
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);
|
zip.file(`word/media/${data.fileName}`, data.stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,13 @@ import { PageSize } from "./page-size/page-size";
|
|||||||
import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attributes";
|
import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attributes";
|
||||||
import { TitlePage } from "./title-page/title-page";
|
import { TitlePage } from "./title-page/title-page";
|
||||||
|
|
||||||
type IHeadersOptions = {headers? : IHeaderOptions[]}
|
interface IHeadersOptions {
|
||||||
type IFootersOptions = {footers? : IFooterOptions[]}
|
headers?: IHeaderOptions[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IFootersOptions {
|
||||||
|
footers?: IFooterOptions[];
|
||||||
|
}
|
||||||
|
|
||||||
export type SectionPropertiesOptions = IPageSizeAttributes &
|
export type SectionPropertiesOptions = IPageSizeAttributes &
|
||||||
IPageMarginAttributes &
|
IPageMarginAttributes &
|
||||||
@ -53,7 +58,7 @@ export class SectionProperties extends XmlComponent {
|
|||||||
pageBorderRight: undefined,
|
pageBorderRight: undefined,
|
||||||
pageBorderBottom: undefined,
|
pageBorderBottom: undefined,
|
||||||
pageBorderLeft: undefined,
|
pageBorderLeft: undefined,
|
||||||
titlePage : true
|
titlePage: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const mergedOptions = {
|
const mergedOptions = {
|
||||||
@ -61,7 +66,6 @@ export class SectionProperties extends XmlComponent {
|
|||||||
...options,
|
...options,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.root.push(new PageSize(mergedOptions.width, mergedOptions.height, mergedOptions.orientation));
|
this.root.push(new PageSize(mergedOptions.width, mergedOptions.height, mergedOptions.orientation));
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new PageMargin(
|
new PageMargin(
|
||||||
@ -77,7 +81,7 @@ export class SectionProperties extends XmlComponent {
|
|||||||
this.root.push(new Columns(mergedOptions.space));
|
this.root.push(new Columns(mergedOptions.space));
|
||||||
this.root.push(new DocumentGrid(mergedOptions.linePitch));
|
this.root.push(new DocumentGrid(mergedOptions.linePitch));
|
||||||
|
|
||||||
for (let header of mergedOptions.headers) {
|
for (const header of mergedOptions.headers) {
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new HeaderReference({
|
new HeaderReference({
|
||||||
headerType: header.headerType,
|
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(
|
this.root.push(
|
||||||
new FooterReference({
|
new FooterReference({
|
||||||
footerType: footer.footerType,
|
footerType: footer.footerType,
|
||||||
|
@ -224,32 +224,12 @@ export class File {
|
|||||||
return header;
|
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 {
|
public createFooter(): FooterWrapper {
|
||||||
const footer = new FooterWrapper(this.currentRelationshipId++);
|
const footer = new FooterWrapper(this.currentRelationshipId++);
|
||||||
this.addFooterToDocument(footer);
|
this.addFooterToDocument(footer);
|
||||||
return 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 {
|
public createFirstPageHeader(): HeaderWrapper {
|
||||||
const headerWrapper = this.createHeader();
|
const headerWrapper = this.createHeader();
|
||||||
|
|
||||||
@ -263,6 +243,42 @@ export class File {
|
|||||||
return headerWrapper;
|
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 {
|
public get Document(): Document {
|
||||||
return this.document;
|
return this.document;
|
||||||
}
|
}
|
||||||
@ -299,14 +315,6 @@ export class File {
|
|||||||
return this.documentHeaders.map((item) => item.header);
|
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 {
|
public get Footer(): FooterWrapper {
|
||||||
return this.documentFooters[0].footer;
|
return this.documentFooters[0].footer;
|
||||||
}
|
}
|
||||||
@ -315,14 +323,6 @@ export class File {
|
|||||||
return this.documentFooters.map((item) => item.footer);
|
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 {
|
public get ContentTypes(): ContentTypes {
|
||||||
return this.contentTypes;
|
return this.contentTypes;
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
|
import { IMediaData } from "file/media";
|
||||||
import { XmlComponent } from "file/xml-components";
|
import { XmlComponent } from "file/xml-components";
|
||||||
import { Footer } from "./footer/footer";
|
import { Footer } from "./footer/footer";
|
||||||
import { Image, Media } from "./media";
|
import { Image, Media } from "./media";
|
||||||
import { ImageParagraph, Paragraph } from "./paragraph";
|
import { ImageParagraph, Paragraph } from "./paragraph";
|
||||||
import { Relationships } from "./relationships";
|
import { Relationships } from "./relationships";
|
||||||
import { Table } from "./table";
|
import { Table } from "./table";
|
||||||
import { IMediaData } from 'file/media';
|
|
||||||
|
|
||||||
export class FooterWrapper {
|
export class FooterWrapper {
|
||||||
private readonly footer: Footer;
|
private readonly footer: Footer;
|
||||||
private readonly relationships: Relationships;
|
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.footer = new Footer(referenceId, initContent);
|
||||||
this.relationships = new Relationships();
|
this.relationships = new Relationships();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public addParagraph(paragraph: Paragraph): void {
|
public addParagraph(paragraph: Paragraph): void {
|
||||||
@ -50,11 +49,10 @@ export class FooterWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public createImage(image: Buffer, width?: number, height?: number): void {
|
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)));
|
this.addImage(new Image(new ImageParagraph(mediaData)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public addImage(image: Image): FooterWrapper {
|
public addImage(image: Image): FooterWrapper {
|
||||||
this.footer.addParagraph(image.Paragraph);
|
this.footer.addParagraph(image.Paragraph);
|
||||||
return this;
|
return this;
|
||||||
@ -67,4 +65,8 @@ export class FooterWrapper {
|
|||||||
public get Relationships(): Relationships {
|
public get Relationships(): Relationships {
|
||||||
return this.relationships;
|
return this.relationships;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get Media(): Media {
|
||||||
|
return this.media;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import { Table } from "./table";
|
|||||||
export class HeaderWrapper {
|
export class HeaderWrapper {
|
||||||
private readonly header: Header;
|
private readonly header: Header;
|
||||||
private readonly relationships: Relationships;
|
private readonly relationships: Relationships;
|
||||||
public readonly media = new Media();
|
private readonly media = new Media();
|
||||||
|
|
||||||
// constructor(private readonly media: Media, referenceId: number, initContent? : XmlComponent) {
|
// constructor(private readonly media: Media, referenceId: number, initContent? : XmlComponent) {
|
||||||
constructor(referenceId: number, initContent?: XmlComponent) {
|
constructor(referenceId: number, initContent?: XmlComponent) {
|
||||||
@ -66,4 +66,8 @@ export class HeaderWrapper {
|
|||||||
public get Relationships(): Relationships {
|
public get Relationships(): Relationships {
|
||||||
return this.relationships;
|
return this.relationships;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get Media(): Media {
|
||||||
|
return this.media;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,17 +23,17 @@ export interface IHeaderAttributesProperties {
|
|||||||
dcmitype?: string;
|
dcmitype?: string;
|
||||||
xsi?: string;
|
xsi?: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
cx? : string,
|
cx?: string;
|
||||||
cx1? : string,
|
cx1?: string;
|
||||||
cx2? : string,
|
cx2?: string;
|
||||||
cx3? : string,
|
cx3?: string;
|
||||||
cx4? : string,
|
cx4?: string;
|
||||||
cx5? : string,
|
cx5?: string;
|
||||||
cx6? : string,
|
cx6?: string;
|
||||||
cx7? : string,
|
cx7?: string;
|
||||||
cx8? : string,
|
cx8?: string;
|
||||||
w16cid: string,
|
w16cid: string;
|
||||||
w16se: string
|
w16se: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesProperties> {
|
export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesProperties> {
|
||||||
@ -70,6 +70,6 @@ export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesPro
|
|||||||
cx7: "xmlns:cx7",
|
cx7: "xmlns:cx7",
|
||||||
cx8: "xmlns:cx8",
|
cx8: "xmlns:cx8",
|
||||||
w16cid: "xmlns:w16cid",
|
w16cid: "xmlns:w16cid",
|
||||||
w16se: "xmlns:w16se"
|
w16se: "xmlns:w16se",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ export const parseOptions = {
|
|||||||
ignoreAttributes: false,
|
ignoreAttributes: false,
|
||||||
attributeNamePrefix: "",
|
attributeNamePrefix: "",
|
||||||
attrNodeName: "_attr",
|
attrNodeName: "_attr",
|
||||||
textNodeName: '',
|
textNodeName: "",
|
||||||
trimValues: false
|
trimValues: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +59,6 @@ export class ImportedXmlComponent extends XmlComponent {
|
|||||||
private _attr: any;
|
private _attr: any;
|
||||||
|
|
||||||
constructor(rootKey: string, _attr?: any) {
|
constructor(rootKey: string, _attr?: any) {
|
||||||
|
|
||||||
super(rootKey);
|
super(rootKey);
|
||||||
if (_attr) {
|
if (_attr) {
|
||||||
this._attr = _attr;
|
this._attr = _attr;
|
||||||
|
@ -87,7 +87,11 @@ export class ImportDocx {
|
|||||||
return templateDocument;
|
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[] = [];
|
let wrapperImagesReferences: IRelationFileInfo[] = [];
|
||||||
const refFile = zipContent.files[`word/_rels/${relationFile.targetFile}.rels`];
|
const refFile = zipContent.files[`word/_rels/${relationFile.targetFile}.rels`];
|
||||||
if (refFile) {
|
if (refFile) {
|
||||||
|
Reference in New Issue
Block a user