2018-07-03 13:48:31 +02:00
|
|
|
// http://officeopenxml.com/WPsectionBorders.php
|
2018-10-26 01:04:07 +01:00
|
|
|
import { BorderStyle } from "file/styles";
|
2019-04-09 05:27:18 -04:00
|
|
|
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
2018-07-03 13:48:31 +02:00
|
|
|
|
|
|
|
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 {
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly display?: PageBorderDisplay;
|
|
|
|
readonly offsetFrom?: PageBorderOffsetFrom;
|
|
|
|
readonly zOrder?: PageBorderZOrder;
|
2018-07-03 13:48:31 +02:00
|
|
|
}
|
|
|
|
|
2018-08-09 23:22:03 +01:00
|
|
|
export interface IPageBorderConfiguration {
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly style?: BorderStyle;
|
|
|
|
readonly size?: number;
|
|
|
|
readonly color?: string;
|
|
|
|
readonly space?: number;
|
2018-07-03 13:48:31 +02:00
|
|
|
}
|
|
|
|
|
2018-08-09 23:22:03 +01:00
|
|
|
export interface IPageBordersOptions {
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly pageBorders?: IPageBorderAttributes;
|
|
|
|
readonly pageBorderTop?: IPageBorderConfiguration;
|
|
|
|
readonly pageBorderRight?: IPageBorderConfiguration;
|
|
|
|
readonly pageBorderBottom?: IPageBorderConfiguration;
|
|
|
|
readonly pageBorderLeft?: IPageBorderConfiguration;
|
2018-08-09 23:22:03 +01:00
|
|
|
}
|
2018-07-03 13:48:31 +02:00
|
|
|
|
2018-08-09 23:22:03 +01:00
|
|
|
class PageBordeAttributes extends XmlAttributeComponent<IPageBorderConfiguration> {
|
2018-11-02 02:51:57 +00:00
|
|
|
protected readonly xmlKeys = {
|
2018-07-03 13:48:31 +02:00
|
|
|
style: "w:val",
|
|
|
|
size: "w:size",
|
|
|
|
color: "w:color",
|
|
|
|
space: "w:space",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class PageBorder extends XmlComponent {
|
2018-08-09 23:22:03 +01:00
|
|
|
constructor(key: string, options: IPageBorderConfiguration) {
|
2018-07-03 13:48:31 +02:00
|
|
|
super(key);
|
|
|
|
|
|
|
|
this.root.push(new PageBordeAttributes(options));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PageBordersAttributes extends XmlAttributeComponent<IPageBorderAttributes> {
|
2018-11-02 02:51:57 +00:00
|
|
|
protected readonly xmlKeys = {
|
2018-07-03 13:48:31 +02:00
|
|
|
display: "w:display",
|
|
|
|
offsetFrom: "w:offsetFrom",
|
|
|
|
zOrder: "w:zOrder",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-09 05:27:18 -04:00
|
|
|
export class PageBorders extends IgnoreIfEmptyXmlComponent {
|
2018-08-09 23:22:03 +01:00
|
|
|
constructor(options?: IPageBordersOptions) {
|
2018-07-03 13:48:31 +02:00
|
|
|
super("w:pgBorders");
|
|
|
|
|
2018-08-09 23:22:03 +01:00
|
|
|
if (!options) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-03 13:48:31 +02:00
|
|
|
|
|
|
|
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-07-03 13:48:31 +02:00
|
|
|
}
|
|
|
|
|
2018-08-09 23:22:03 +01:00
|
|
|
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));
|
|
|
|
}
|
2018-07-03 13:48:31 +02:00
|
|
|
}
|
|
|
|
}
|