Files
docx-js/src/file/document/body/section-properties/page-border/page-borders.ts

77 lines
2.2 KiB
TypeScript
Raw Normal View History

// http://officeopenxml.com/WPsectionBorders.php
2021-05-23 07:14:00 +03:00
import { BorderElement, IBorderOptions } from "file/border";
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent } from "file/xml-components";
export enum PageBorderDisplay {
ALL_PAGES = "allPages",
FIRST_PAGE = "firstPage",
NOT_FIRST_PAGE = "notFirstPage",
}
export enum PageBorderOffsetFrom {
PAGE = "page",
TEXT = "text",
}
export enum PageBorderZOrder {
BACK = "back",
FRONT = "front",
}
export interface IPageBorderAttributes {
readonly display?: PageBorderDisplay;
readonly offsetFrom?: PageBorderOffsetFrom;
readonly zOrder?: PageBorderZOrder;
}
2018-08-09 23:22:03 +01:00
export interface IPageBordersOptions {
readonly pageBorders?: IPageBorderAttributes;
2021-05-23 07:14:00 +03:00
readonly pageBorderTop?: IBorderOptions;
readonly pageBorderRight?: IBorderOptions;
readonly pageBorderBottom?: IBorderOptions;
readonly pageBorderLeft?: IBorderOptions;
}
class PageBordersAttributes extends XmlAttributeComponent<IPageBorderAttributes> {
protected readonly xmlKeys = {
display: "w:display",
offsetFrom: "w:offsetFrom",
zOrder: "w:zOrder",
};
}
export class PageBorders extends IgnoreIfEmptyXmlComponent {
2018-08-09 23:22:03 +01:00
constructor(options?: IPageBordersOptions) {
super("w:pgBorders");
2018-08-09 23:22:03 +01:00
if (!options) {
return;
}
if (options.pageBorders) {
2021-03-13 19:53:36 +00:00
this.root.push(
new PageBordersAttributes({
display: options.pageBorders.display,
offsetFrom: options.pageBorders.offsetFrom,
zOrder: options.pageBorders.zOrder,
}),
);
} else {
this.root.push(new PageBordersAttributes({}));
}
2018-08-09 23:22:03 +01:00
if (options.pageBorderTop) {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:top", options.pageBorderTop));
2018-08-09 23:22:03 +01:00
}
if (options.pageBorderRight) {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:right", options.pageBorderRight));
2018-08-09 23:22:03 +01:00
}
if (options.pageBorderBottom) {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:bottom", options.pageBorderBottom));
2018-08-09 23:22:03 +01:00
}
if (options.pageBorderLeft) {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:left", options.pageBorderLeft));
2018-08-09 23:22:03 +01:00
}
}
}