import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
//
//
//
//
//
//
export const PageOrientation = {
PORTRAIT: "portrait",
LANDSCAPE: "landscape",
} as const;
//
//
//
//
//
//
export type IPageSizeAttributes = {
readonly width?: number | PositiveUniversalMeasure;
readonly height?: number | PositiveUniversalMeasure;
readonly orientation?: (typeof PageOrientation)[keyof typeof PageOrientation];
};
export class PageSize extends XmlComponent {
public constructor(
width: number | PositiveUniversalMeasure,
height: number | PositiveUniversalMeasure,
orientation: (typeof PageOrientation)[keyof typeof 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 },
}),
);
}
}