// http://officeopenxml.com/WPsectionBorders.php
import { BorderElement, IBorderOptions } from "@file/border";
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent } from "@file/xml-components";
//
//
//
//
//
//
//
/* eslint-disable @typescript-eslint/naming-convention */
export const PageBorderDisplay = {
ALL_PAGES: "allPages",
FIRST_PAGE: "firstPage",
NOT_FIRST_PAGE: "notFirstPage",
} as const;
/* eslint-enable */
//
//
//
//
//
//
export const PageBorderOffsetFrom = {
PAGE: "page",
TEXT: "text",
} as const;
//
//
//
//
//
//
export const PageBorderZOrder = {
BACK: "back",
FRONT: "front",
} as const;
export interface IPageBorderAttributes {
readonly display?: (typeof PageBorderDisplay)[keyof typeof PageBorderDisplay];
readonly offsetFrom?: (typeof PageBorderOffsetFrom)[keyof typeof PageBorderOffsetFrom];
readonly zOrder?: (typeof PageBorderZOrder)[keyof typeof PageBorderZOrder];
}
export interface IPageBordersOptions {
readonly pageBorders?: IPageBorderAttributes;
readonly pageBorderTop?: IBorderOptions;
readonly pageBorderRight?: IBorderOptions;
readonly pageBorderBottom?: IBorderOptions;
readonly pageBorderLeft?: IBorderOptions;
}
class PageBordersAttributes extends XmlAttributeComponent {
protected readonly xmlKeys = {
display: "w:display",
offsetFrom: "w:offsetFrom",
zOrder: "w:zOrder",
};
}
//
//
//
//
//
//
//
//
//
//
//
export class PageBorders extends IgnoreIfEmptyXmlComponent {
public constructor(options?: IPageBordersOptions) {
super("w:pgBorders");
if (!options) {
return this;
}
if (options.pageBorders) {
this.root.push(
new PageBordersAttributes({
display: options.pageBorders.display,
offsetFrom: options.pageBorders.offsetFrom,
zOrder: options.pageBorders.zOrder,
}),
);
} else {
this.root.push(new PageBordersAttributes({}));
}
if (options.pageBorderTop) {
this.root.push(new BorderElement("w:top", options.pageBorderTop));
}
if (options.pageBorderLeft) {
this.root.push(new BorderElement("w:left", options.pageBorderLeft));
}
if (options.pageBorderBottom) {
this.root.push(new BorderElement("w:bottom", options.pageBorderBottom));
}
if (options.pageBorderRight) {
this.root.push(new BorderElement("w:right", options.pageBorderRight));
}
}
}