import { NextAttributeComponent, XmlComponent } from "@file/xml-components"; import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values"; // // // // // // export enum PageOrientation { PORTRAIT = "portrait", LANDSCAPE = "landscape", } // // // // // // export type IPageSizeAttributes = { readonly width?: number | PositiveUniversalMeasure; readonly height?: number | PositiveUniversalMeasure; readonly orientation?: PageOrientation; }; export class PageSize extends XmlComponent { public constructor(width: number | PositiveUniversalMeasure, height: number | PositiveUniversalMeasure, orientation: PageOrientation) { super("w:pgSz"); const flip = orientation === PageOrientation.LANDSCAPE; const widthTwips = twipsMeasureValue(width); const heightTwips = twipsMeasureValue(height); this.root.push( new NextAttributeComponent({ width: { key: "w:w", value: flip ? heightTwips : widthTwips }, height: { key: "w:h", value: flip ? widthTwips : heightTwips }, orientation: { key: "w:orient", value: orientation }, }), ); } }