diff --git a/src/file/document/body/body.ts b/src/file/document/body/body.ts index 7fc0e98f38..e274fa359f 100644 --- a/src/file/document/body/body.ts +++ b/src/file/document/body/body.ts @@ -1,7 +1,6 @@ import { IXmlableObject, XmlComponent } from "file/xml-components"; -import { SectionProperties, SectionPropertiesOptions } from "./section-properties/section-properties"; import { Paragraph, ParagraphProperties } from "../.."; -import { SectionProperties, SectionPropertiesOptions } from "./section-properties"; +import { SectionProperties, SectionPropertiesOptions } from "./section-properties/section-properties"; export class Body extends XmlComponent { private readonly defaultSection: SectionProperties; diff --git a/src/file/document/body/section-properties/page-border/page-borders.spec.ts b/src/file/document/body/section-properties/page-border/page-borders.spec.ts index 782280f292..66abb9cc66 100644 --- a/src/file/document/body/section-properties/page-border/page-borders.spec.ts +++ b/src/file/document/body/section-properties/page-border/page-borders.spec.ts @@ -1,8 +1,8 @@ import { expect } from "chai"; import { Formatter } from "../../../../../export/formatter"; -import { PageBorders, PageBorderDisplay, PageBorderZOrder } from "./page-borders"; import { BorderStyle } from "../../../../styles"; +import { PageBorderDisplay, PageBorders, PageBorderZOrder } from "./page-borders"; describe("PageBorders", () => { describe("#constructor()", () => { diff --git a/src/file/document/body/section-properties/page-border/page-borders.ts b/src/file/document/body/section-properties/page-border/page-borders.ts index 88b6ce98dd..0af96cfd41 100644 --- a/src/file/document/body/section-properties/page-border/page-borders.ts +++ b/src/file/document/body/section-properties/page-border/page-borders.ts @@ -1,5 +1,5 @@ // http://officeopenxml.com/WPsectionBorders.php -import { XmlComponent, XmlAttributeComponent, IXmlableObject } from "file/xml-components"; +import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { BorderStyle } from "../../../../styles"; export enum PageBorderDisplay { @@ -24,22 +24,22 @@ export interface IPageBorderAttributes { zOrder?: PageBorderZOrder; } -export interface PageBorderConfiguration { +export interface IPageBorderConfiguration { style?: BorderStyle; size?: number; color?: string; space?: number; } -export type PageBordersOptions = { +export interface IPageBordersOptions { pageBorders?: IPageBorderAttributes; - pageBorderTop?: PageBorderConfiguration; - pageBorderRight?: PageBorderConfiguration; - pageBorderBottom?: PageBorderConfiguration; - pageBorderLeft?: PageBorderConfiguration; -}; + pageBorderTop?: IPageBorderConfiguration; + pageBorderRight?: IPageBorderConfiguration; + pageBorderBottom?: IPageBorderConfiguration; + pageBorderLeft?: IPageBorderConfiguration; +} -class PageBordeAttributes extends XmlAttributeComponent { +class PageBordeAttributes extends XmlAttributeComponent { protected xmlKeys = { style: "w:val", size: "w:size", @@ -49,7 +49,7 @@ class PageBordeAttributes extends XmlAttributeComponent } class PageBorder extends XmlComponent { - constructor(key: string, options: PageBorderConfiguration) { + constructor(key: string, options: IPageBorderConfiguration) { super(key); this.root.push(new PageBordeAttributes(options)); @@ -65,10 +65,12 @@ class PageBordersAttributes extends XmlAttributeComponent } export class PageBorders extends XmlComponent { - constructor(options?: PageBordersOptions) { + constructor(options?: IPageBordersOptions) { super("w:pgBorders"); - if (!options) return; + if (!options) { + return; + } let pageBordersAttributes = {}; @@ -82,10 +84,18 @@ export class PageBorders extends XmlComponent { this.root.push(new PageBordersAttributes(pageBordersAttributes)); - if (options.pageBorderTop) this.root.push(new PageBorder("w:top", options.pageBorderTop)); - if (options.pageBorderRight) this.root.push(new PageBorder("w:right", options.pageBorderRight)); - if (options.pageBorderBottom) this.root.push(new PageBorder("w:bottom", options.pageBorderBottom)); - if (options.pageBorderLeft) this.root.push(new PageBorder("w:left", options.pageBorderLeft)); + if (options.pageBorderTop) { + this.root.push(new PageBorder("w:top", options.pageBorderTop)); + } + if (options.pageBorderRight) { + this.root.push(new PageBorder("w:right", options.pageBorderRight)); + } + if (options.pageBorderBottom) { + this.root.push(new PageBorder("w:bottom", options.pageBorderBottom)); + } + if (options.pageBorderLeft) { + this.root.push(new PageBorder("w:left", options.pageBorderLeft)); + } } public prepForXml(): IXmlableObject { diff --git a/src/file/document/body/section-properties/section-properties.ts b/src/file/document/body/section-properties/section-properties.ts index 33d0a7a0ae..c23964cd14 100644 --- a/src/file/document/body/section-properties/section-properties.ts +++ b/src/file/document/body/section-properties/section-properties.ts @@ -1,6 +1,6 @@ // http://officeopenxml.com/WPsection.php import { XmlComponent } from "file/xml-components"; -import { FooterReferenceType, IPageNumberTypeAttributes, PageNumberFormat, PageNumberType } from "./"; +import { FooterReferenceType, IPageBordersOptions, IPageNumberTypeAttributes, PageBorders, PageNumberFormat, PageNumberType } from "./"; import { Columns } from "./columns/columns"; import { IColumnsAttributes } from "./columns/columns-attributes"; import { DocumentGrid } from "./doc-grid/doc-grid"; @@ -12,9 +12,6 @@ import { PageMargin } from "./page-margin/page-margin"; import { IPageMarginAttributes } from "./page-margin/page-margin-attributes"; import { PageSize } from "./page-size/page-size"; import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attributes"; -import { FooterReferenceType, IPageNumberTypeAttributes, PageNumberType, PageNumberFormat } from "."; -// import { TitlePage } from "./title-page/title-page"; -import { FooterReferenceType, IPageNumberTypeAttributes, PageNumberType, PageNumberFormat, PageBordersOptions, PageBorders } from "."; export type SectionPropertiesOptions = IPageSizeAttributes & IPageMarginAttributes & @@ -23,7 +20,7 @@ export type SectionPropertiesOptions = IPageSizeAttributes & IHeaderOptions & IFooterOptions & IPageNumberTypeAttributes & - PageBordersOptions; + IPageBordersOptions; export class SectionProperties extends XmlComponent { private readonly options: SectionPropertiesOptions; diff --git a/src/file/file.ts b/src/file/file.ts index 83d0c8c53b..2482d9b39c 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -2,7 +2,7 @@ import { AppProperties } from "./app-properties/app-properties"; import { ContentTypes } from "./content-types/content-types"; import { CoreProperties, IPropertiesOptions } from "./core-properties"; import { Document } from "./document"; -import { FooterReferenceType, HeaderReference, HeaderReferenceType } from "./document/body/section-properties"; +import { FooterReferenceType, HeaderReference, HeaderReferenceType, SectionPropertiesOptions } from "./document/body/section-properties"; import { FooterWrapper } from "./footer-wrapper"; import { FootNotes } from "./footnotes"; import { HeaderWrapper } from "./header-wrapper"; @@ -14,7 +14,6 @@ import { Styles } from "./styles"; import { ExternalStylesFactory } from "./styles/external-styles-factory"; import { DefaultStylesFactory } from "./styles/factory"; import { Table } from "./table"; -import { FooterReferenceType, HeaderReferenceType, SectionPropertiesOptions } from "./document/body/section-properties"; export class File { private readonly document: Document; diff --git a/src/file/media/media.ts b/src/file/media/media.ts index e8e6044569..aea65777f0 100644 --- a/src/file/media/media.ts +++ b/src/file/media/media.ts @@ -61,8 +61,6 @@ export class Media { this.map = new Map(); } - x: Math.round(dimensions.width * 9525), - y: Math.round(dimensions.height * 9525), public getMedia(key: string): IMediaData { const data = this.map.get(key); @@ -108,12 +106,12 @@ export class Media { fileName: key, dimensions: { pixels: { - x: dimensions.width, - y: dimensions.height, + x: Math.round(dimensions.width), + y: Math.round(dimensions.height), }, emus: { - x: dimensions.width * 9525, - y: dimensions.height * 9525, + x: Math.round(dimensions.width * 9525), + y: Math.round(dimensions.height * 9525), }, }, }; diff --git a/src/file/numbering/level.ts b/src/file/numbering/level.ts index 0df90758fb..8bdc7ff8d7 100644 --- a/src/file/numbering/level.ts +++ b/src/file/numbering/level.ts @@ -110,7 +110,7 @@ export class LevelBase extends XmlComponent { this.root.push(this.runProperties); } - public setSuffix(value: LevelSuffix) { + public setSuffix(value: LevelSuffix): LevelBase { this.root.push(new Suffix(value)); return this; } diff --git a/src/file/styles/external-styles-factory.ts b/src/file/styles/external-styles-factory.ts index 303d563907..301211bdc7 100644 --- a/src/file/styles/external-styles-factory.ts +++ b/src/file/styles/external-styles-factory.ts @@ -1,7 +1,5 @@ import * as fastXmlParser from "fast-xml-parser"; -import { ImportedXmlComponent, ImportedRootElementAttributes, parseOptions, convertToXmlComponent } from "./../../file/xml-components"; -import { convertToXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, parseOptions } from "file/xml-components"; -import { ImportedRootElementAttributes, parseOptions, convertToXmlComponent } from "./../../file/xml-components"; +import { convertToXmlComponent, ImportedRootElementAttributes, parseOptions } from "file/xml-components"; import { Styles } from "./"; export class ExternalStylesFactory {