2018-07-03 13:48:31 +02:00
|
|
|
// http://officeopenxml.com/WPsectionBorders.php
|
2022-06-26 23:26:42 +01:00
|
|
|
import { BorderElement, IBorderOptions } from "@file/border";
|
|
|
|
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent } from "@file/xml-components";
|
2018-07-03 13:48:31 +02:00
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
// <xsd:simpleType name="ST_PageBorderDisplay">
|
|
|
|
// <xsd:restriction base="xsd:string">
|
|
|
|
// <xsd:enumeration value="allPages"/>
|
|
|
|
// <xsd:enumeration value="firstPage"/>
|
|
|
|
// <xsd:enumeration value="notFirstPage"/>
|
|
|
|
// </xsd:restriction>
|
|
|
|
// </xsd:simpleType>
|
2018-07-03 13:48:31 +02:00
|
|
|
export enum PageBorderDisplay {
|
|
|
|
ALL_PAGES = "allPages",
|
|
|
|
FIRST_PAGE = "firstPage",
|
|
|
|
NOT_FIRST_PAGE = "notFirstPage",
|
|
|
|
}
|
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
// <xsd:simpleType name="ST_PageBorderOffset">
|
|
|
|
// <xsd:restriction base="xsd:string">
|
|
|
|
// <xsd:enumeration value="page"/>
|
|
|
|
// <xsd:enumeration value="text"/>
|
|
|
|
// </xsd:restriction>
|
|
|
|
// </xsd:simpleType>
|
2018-07-03 13:48:31 +02:00
|
|
|
export enum PageBorderOffsetFrom {
|
|
|
|
PAGE = "page",
|
|
|
|
TEXT = "text",
|
|
|
|
}
|
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
// <xsd:simpleType name="ST_PageBorderZOrder">
|
|
|
|
// <xsd:restriction base="xsd:string">
|
|
|
|
// <xsd:enumeration value="front"/>
|
|
|
|
// <xsd:enumeration value="back"/>
|
|
|
|
// </xsd:restriction>
|
|
|
|
// </xsd:simpleType>
|
2018-07-03 13:48:31 +02:00
|
|
|
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 IPageBordersOptions {
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly pageBorders?: IPageBorderAttributes;
|
2021-05-23 07:14:00 +03:00
|
|
|
readonly pageBorderTop?: IBorderOptions;
|
|
|
|
readonly pageBorderRight?: IBorderOptions;
|
|
|
|
readonly pageBorderBottom?: IBorderOptions;
|
|
|
|
readonly pageBorderLeft?: IBorderOptions;
|
2018-07-03 13:48:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
// <xsd:complexType name="CT_PageBorders">
|
|
|
|
// <xsd:sequence>
|
|
|
|
// <xsd:element name="top" type="CT_TopPageBorder" minOccurs="0"/>
|
|
|
|
// <xsd:element name="left" type="CT_PageBorder" minOccurs="0"/>
|
|
|
|
// <xsd:element name="bottom" type="CT_BottomPageBorder" minOccurs="0"/>
|
|
|
|
// <xsd:element name="right" type="CT_PageBorder" minOccurs="0"/>
|
|
|
|
// </xsd:sequence>
|
|
|
|
// <xsd:attribute name="zOrder" type="ST_PageBorderZOrder" use="optional" default="front"/>
|
|
|
|
// <xsd:attribute name="display" type="ST_PageBorderDisplay" use="optional"/>
|
|
|
|
// <xsd:attribute name="offsetFrom" type="ST_PageBorderOffset" use="optional" default="text"/>
|
|
|
|
// </xsd:complexType>
|
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) {
|
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
|
|
|
}
|
2021-05-25 03:41:12 +03:00
|
|
|
if (options.pageBorderLeft) {
|
|
|
|
this.root.push(new BorderElement("w:left", options.pageBorderLeft));
|
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
|
|
|
}
|
2021-05-25 03:41:12 +03:00
|
|
|
if (options.pageBorderRight) {
|
|
|
|
this.root.push(new BorderElement("w:right", options.pageBorderRight));
|
2018-08-09 23:22:03 +01:00
|
|
|
}
|
2018-07-03 13:48:31 +02:00
|
|
|
}
|
|
|
|
}
|