diff --git a/src/export/packer/express.ts b/src/export/packer/express.ts index e6ee3693ac..4f99298424 100644 --- a/src/export/packer/express.ts +++ b/src/export/packer/express.ts @@ -5,10 +5,9 @@ import { Compiler } from "./compiler"; import { IPacker } from "./packer"; export class ExpressPacker implements IPacker { - private res: express.Response; - private packer: Compiler; + private readonly packer: Compiler; - constructor(file: File, res: express.Response) { + constructor(file: File, private readonly res: express.Response) { this.packer = new Compiler(file); this.res = res; diff --git a/src/export/packer/local.ts b/src/export/packer/local.ts index 2e33f74dfc..5d0c05fe81 100644 --- a/src/export/packer/local.ts +++ b/src/export/packer/local.ts @@ -9,8 +9,8 @@ import { PdfConvertWrapper } from "./pdf-convert-wrapper"; export class LocalPacker implements IPacker { private stream: fs.WriteStream; - private pdfConverter: PdfConvertWrapper; - private packer: Compiler; + private readonly pdfConverter: PdfConvertWrapper; + private readonly packer: Compiler; constructor(file: File) { this.pdfConverter = new PdfConvertWrapper(); diff --git a/src/file/document/document.ts b/src/file/document/document.ts index f29b2795b4..f4d580b9ca 100644 --- a/src/file/document/document.ts +++ b/src/file/document/document.ts @@ -8,7 +8,7 @@ import { SectionPropertiesOptions } from "./body/section-properties/section-prop import { DocumentAttributes } from "./document-attributes"; export class Document extends XmlComponent { - private body: Body; + private readonly body: Body; constructor(sectionPropertiesOptions?: SectionPropertiesOptions) { super("w:document"); diff --git a/src/file/media/media.ts b/src/file/media/media.ts index 854d19194a..92e8bea1fe 100644 --- a/src/file/media/media.ts +++ b/src/file/media/media.ts @@ -2,10 +2,11 @@ import * as fs from "fs"; import * as sizeOf from "image-size"; import * as path from "path"; +import { Relationships } from "file/relationships/relationships"; import { IMediaData } from "./data"; export class Media { - private map: Map; + private readonly map: Map; constructor() { this.map = new Map(); @@ -21,12 +22,12 @@ export class Media { return data; } - public addMedia(filePath: string): IMediaData { + public addMedia(filePath: string, relationshipsCount: number): IMediaData { const key = path.basename(filePath); const dimensions = sizeOf(filePath); const imageData = { - referenceId: this.map.size + 3, + referenceId: this.map.size + relationshipsCount, stream: fs.createReadStream(filePath), path: filePath, fileName: key, diff --git a/src/file/numbering/level.ts b/src/file/numbering/level.ts index ab8c3ccb53..bb50bfb2e2 100644 --- a/src/file/numbering/level.ts +++ b/src/file/numbering/level.ts @@ -61,8 +61,8 @@ class LevelJc extends XmlComponent { } export class LevelBase extends XmlComponent { - private paragraphProperties: ParagraphProperties; - private runProperties: RunProperties; + private readonly paragraphProperties: ParagraphProperties; + private readonly runProperties: RunProperties; constructor(level: number, start?: number, numberFormat?: string, levelText?: string, lvlJc?: string) { super("w:lvl"); diff --git a/src/file/numbering/num.ts b/src/file/numbering/num.ts index e6b4628ac4..cd3034d920 100644 --- a/src/file/numbering/num.ts +++ b/src/file/numbering/num.ts @@ -46,16 +46,14 @@ class LevelOverrideAttributes extends XmlAttributeComponent<{ ilvl: number }> { } export class LevelOverride extends XmlComponent { - private levelNum: number; private lvl?: LevelForOverride; - constructor(levelNum: number, start?: number) { + constructor(private readonly levelNum: number, start?: number) { super("w:lvlOverride"); this.root.push(new LevelOverrideAttributes({ ilvl: levelNum })); if (start !== undefined) { this.root.push(new StartOverride(start)); } - this.levelNum = levelNum; } get level(): LevelForOverride { diff --git a/src/file/relationships/relationships.ts b/src/file/relationships/relationships.ts index f338bdd736..c665be063e 100644 --- a/src/file/relationships/relationships.ts +++ b/src/file/relationships/relationships.ts @@ -13,6 +13,7 @@ export class Relationships extends XmlComponent { this.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml"); this.createRelationship(2, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml"); + this.createRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", "header1.xml"); } public addRelationship(relationship: Relationship): void { @@ -25,4 +26,8 @@ export class Relationships extends XmlComponent { return relationship; } + + public get RelationshipCount(): number { + return this.root.length - 1; + } } diff --git a/src/file/styles/defaults/index.ts b/src/file/styles/defaults/index.ts index 811eb0aa1d..2b6c49e299 100644 --- a/src/file/styles/defaults/index.ts +++ b/src/file/styles/defaults/index.ts @@ -3,8 +3,8 @@ import { ParagraphPropertiesDefaults } from "./paragraph-properties"; import { RunPropertiesDefaults } from "./run-properties"; export class DocumentDefaults extends XmlComponent { - private runPropertiesDefaults: RunPropertiesDefaults; - private paragraphPropertiesDefaults: ParagraphPropertiesDefaults; + private readonly runPropertiesDefaults: RunPropertiesDefaults; + private readonly paragraphPropertiesDefaults: ParagraphPropertiesDefaults; constructor() { super("w:docDefaults"); diff --git a/src/file/styles/defaults/run-properties.ts b/src/file/styles/defaults/run-properties.ts index 242aa3e58d..c00b6ccc79 100644 --- a/src/file/styles/defaults/run-properties.ts +++ b/src/file/styles/defaults/run-properties.ts @@ -4,7 +4,7 @@ import { RunProperties } from "../../paragraph/run/properties"; import { RunFonts } from "../../paragraph/run/run-fonts"; export class RunPropertiesDefaults extends XmlComponent { - private properties: RunProperties; + private readonly properties: RunProperties; constructor() { super("w:rPrDefault"); diff --git a/src/file/styles/style/index.ts b/src/file/styles/style/index.ts index 50265f182a..7436fbb22a 100644 --- a/src/file/styles/style/index.ts +++ b/src/file/styles/style/index.ts @@ -36,8 +36,8 @@ export class Style extends XmlComponent { } export class ParagraphStyle extends Style { - private paragraphProperties: paragraph.ParagraphProperties; - private runProperties: RunProperties; + private readonly paragraphProperties: paragraph.ParagraphProperties; + private readonly runProperties: RunProperties; constructor(styleId: string, name?: string) { super({ type: "paragraph", styleId: styleId }, name); diff --git a/src/file/table/table.ts b/src/file/table/table.ts index 43a41cd78e..f11b6959c7 100644 --- a/src/file/table/table.ts +++ b/src/file/table/table.ts @@ -5,9 +5,9 @@ import { TableGrid } from "./grid"; import { TableProperties, WidthTypes } from "./properties"; export class Table extends XmlComponent { - private properties: TableProperties; - private rows: TableRow[]; - private grid: TableGrid; + private readonly properties: TableProperties; + private readonly rows: TableRow[]; + private readonly grid: TableGrid; constructor(rows: number, cols: number) { super("w:tbl"); @@ -63,14 +63,12 @@ export class Table extends XmlComponent { } export class TableRow extends XmlComponent { - private properties: TableRowProperties; - private cells: TableCell[]; + private readonly properties: TableRowProperties; - constructor(cells: TableCell[]) { + constructor(private readonly cells: TableCell[]) { super("w:tr"); this.properties = new TableRowProperties(); this.root.push(this.properties); - this.cells = cells; cells.forEach((c) => this.root.push(c)); } @@ -86,7 +84,7 @@ export class TableRowProperties extends XmlComponent { } export class TableCell extends XmlComponent { - private properties: TableCellProperties; + private readonly properties: TableCellProperties; constructor() { super("w:tc");