2018-01-24 00:01:38 +00:00
|
|
|
// http://officeopenxml.com/WPsection.php
|
2021-03-19 20:53:56 +00:00
|
|
|
|
2022-06-26 23:26:42 +01:00
|
|
|
import { FooterWrapper } from "@file/footer-wrapper";
|
|
|
|
import { HeaderWrapper } from "@file/header-wrapper";
|
|
|
|
import { VerticalAlign, VerticalAlignElement } from "@file/vertical-align";
|
|
|
|
import { OnOffElement, XmlComponent } from "@file/xml-components";
|
2021-05-25 03:41:12 +03:00
|
|
|
|
|
|
|
import { Columns, IColumnsAttributes } from "./properties/columns";
|
2025-04-14 16:43:15 +05:30
|
|
|
import { IDocGridAttributesProperties, createDocumentGrid } from "./properties/doc-grid";
|
2024-10-21 03:57:15 +01:00
|
|
|
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference";
|
2023-12-25 02:47:43 +00:00
|
|
|
import { ILineNumberAttributes, createLineNumberType } from "./properties/line-number";
|
2021-05-25 03:41:12 +03:00
|
|
|
import { IPageBordersOptions, PageBorders } from "./properties/page-borders";
|
|
|
|
import { IPageMarginAttributes, PageMargin } from "./properties/page-margin";
|
|
|
|
import { IPageNumberTypeAttributes, PageNumberType } from "./properties/page-number";
|
2025-04-14 16:43:15 +05:30
|
|
|
import { IPageSizeAttributes, PageOrientation, createPageSize } from "./properties/page-size";
|
2021-11-26 15:07:15 +00:00
|
|
|
import { PageTextDirection, PageTextDirectionType } from "./properties/page-text-direction";
|
2021-05-25 03:41:12 +03:00
|
|
|
import { SectionType, Type } from "./properties/section-type";
|
2018-09-04 17:16:31 +03:00
|
|
|
|
2024-10-21 03:57:15 +01:00
|
|
|
export type IHeaderFooterGroup<T> = {
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly default?: T;
|
|
|
|
readonly first?: T;
|
|
|
|
readonly even?: T;
|
2024-10-21 03:57:15 +01:00
|
|
|
};
|
2018-10-05 01:33:17 +01:00
|
|
|
|
2024-10-21 03:57:15 +01:00
|
|
|
export type ISectionPropertiesOptions = {
|
2021-03-19 20:53:56 +00:00
|
|
|
readonly page?: {
|
2025-04-14 16:43:15 +05:30
|
|
|
readonly size?: Partial<IPageSizeAttributes>;
|
2021-03-19 20:53:56 +00:00
|
|
|
readonly margin?: IPageMarginAttributes;
|
|
|
|
readonly pageNumbers?: IPageNumberTypeAttributes;
|
|
|
|
readonly borders?: IPageBordersOptions;
|
2023-12-22 10:25:00 +09:00
|
|
|
readonly textDirection?: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType];
|
2021-03-19 20:53:56 +00:00
|
|
|
};
|
2025-04-14 16:43:15 +05:30
|
|
|
readonly grid?: Partial<IDocGridAttributesProperties>;
|
2021-03-19 20:53:56 +00:00
|
|
|
readonly headerWrapperGroup?: IHeaderFooterGroup<HeaderWrapper>;
|
|
|
|
readonly footerWrapperGroup?: IHeaderFooterGroup<FooterWrapper>;
|
|
|
|
readonly lineNumbers?: ILineNumberAttributes;
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly titlePage?: boolean;
|
2023-12-22 10:25:00 +09:00
|
|
|
readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign];
|
2021-05-25 03:41:12 +03:00
|
|
|
readonly column?: IColumnsAttributes;
|
2023-12-22 10:25:00 +09:00
|
|
|
readonly type?: (typeof SectionType)[keyof typeof SectionType];
|
2024-10-21 03:57:15 +01:00
|
|
|
};
|
2021-05-24 21:06:34 +03:00
|
|
|
|
|
|
|
// <xsd:complexType name="CT_SectPr">
|
|
|
|
// <xsd:sequence>
|
|
|
|
// <xsd:group ref="EG_HdrFtrReferences" minOccurs="0" maxOccurs="6"/>
|
|
|
|
// <xsd:group ref="EG_SectPrContents" minOccurs="0"/>
|
|
|
|
// <xsd:element name="sectPrChange" type="CT_SectPrChange" minOccurs="0"/>
|
|
|
|
// </xsd:sequence>
|
|
|
|
// <xsd:attributeGroup ref="AG_SectPrAttributes"/>
|
|
|
|
// </xsd:complexType>
|
|
|
|
|
|
|
|
// <xsd:group name="EG_SectPrContents">
|
|
|
|
// <xsd:sequence>
|
|
|
|
// <xsd:element name="footnotePr" type="CT_FtnProps" minOccurs="0"/>
|
|
|
|
// <xsd:element name="endnotePr" type="CT_EdnProps" minOccurs="0"/>
|
|
|
|
// <xsd:element name="type" type="CT_SectType" minOccurs="0"/>
|
|
|
|
// <xsd:element name="pgSz" type="CT_PageSz" minOccurs="0"/>
|
|
|
|
// <xsd:element name="pgMar" type="CT_PageMar" minOccurs="0"/>
|
|
|
|
// <xsd:element name="paperSrc" type="CT_PaperSource" minOccurs="0"/>
|
|
|
|
// <xsd:element name="pgBorders" type="CT_PageBorders" minOccurs="0"/>
|
|
|
|
// <xsd:element name="lnNumType" type="CT_LineNumber" minOccurs="0"/>
|
|
|
|
// <xsd:element name="pgNumType" type="CT_PageNumber" minOccurs="0"/>
|
|
|
|
// <xsd:element name="cols" type="CT_Columns" minOccurs="0"/>
|
|
|
|
// <xsd:element name="formProt" type="CT_OnOff" minOccurs="0"/>
|
|
|
|
// <xsd:element name="vAlign" type="CT_VerticalJc" minOccurs="0"/>
|
|
|
|
// <xsd:element name="noEndnote" type="CT_OnOff" minOccurs="0"/>
|
|
|
|
// <xsd:element name="titlePg" type="CT_OnOff" minOccurs="0"/>
|
|
|
|
// <xsd:element name="textDirection" type="CT_TextDirection" minOccurs="0"/>
|
|
|
|
// <xsd:element name="bidi" type="CT_OnOff" minOccurs="0"/>
|
|
|
|
// <xsd:element name="rtlGutter" type="CT_OnOff" minOccurs="0"/>
|
|
|
|
// <xsd:element name="docGrid" type="CT_DocGrid" minOccurs="0"/>
|
|
|
|
// <xsd:element name="printerSettings" type="CT_Rel" minOccurs="0"/>
|
|
|
|
// </xsd:sequence>
|
|
|
|
// </xsd:group>
|
2021-05-25 03:41:12 +03:00
|
|
|
|
|
|
|
export const sectionMarginDefaults = {
|
2023-10-12 12:14:13 +09:00
|
|
|
TOP: 1440,
|
|
|
|
RIGHT: 1440,
|
|
|
|
BOTTOM: 1440,
|
|
|
|
LEFT: 1440,
|
2021-05-25 03:41:12 +03:00
|
|
|
HEADER: 708,
|
|
|
|
FOOTER: 708,
|
|
|
|
GUTTER: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const sectionPageSizeDefaults = {
|
|
|
|
WIDTH: 11906,
|
|
|
|
HEIGHT: 16838,
|
|
|
|
ORIENTATION: PageOrientation.PORTRAIT,
|
|
|
|
};
|
|
|
|
|
2018-01-24 00:01:38 +00:00
|
|
|
export class SectionProperties extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor({
|
2021-03-19 20:53:56 +00:00
|
|
|
page: {
|
2021-05-25 03:41:12 +03:00
|
|
|
size: {
|
|
|
|
width = sectionPageSizeDefaults.WIDTH,
|
|
|
|
height = sectionPageSizeDefaults.HEIGHT,
|
|
|
|
orientation = sectionPageSizeDefaults.ORIENTATION,
|
|
|
|
} = {},
|
2021-03-19 20:53:56 +00:00
|
|
|
margin: {
|
2021-05-25 03:41:12 +03:00
|
|
|
top = sectionMarginDefaults.TOP,
|
|
|
|
right = sectionMarginDefaults.RIGHT,
|
|
|
|
bottom = sectionMarginDefaults.BOTTOM,
|
|
|
|
left = sectionMarginDefaults.LEFT,
|
|
|
|
header = sectionMarginDefaults.HEADER,
|
|
|
|
footer = sectionMarginDefaults.FOOTER,
|
|
|
|
gutter = sectionMarginDefaults.GUTTER,
|
2021-03-19 20:53:56 +00:00
|
|
|
} = {},
|
2021-05-23 07:33:43 +03:00
|
|
|
pageNumbers = {},
|
|
|
|
borders,
|
2021-11-19 22:30:38 +09:00
|
|
|
textDirection,
|
2021-03-19 20:53:56 +00:00
|
|
|
} = {},
|
2021-11-30 21:11:06 +09:00
|
|
|
grid: { linePitch = 360, charSpace, type: gridType } = {},
|
2021-03-19 20:53:56 +00:00
|
|
|
headerWrapperGroup = {},
|
|
|
|
footerWrapperGroup = {},
|
2021-05-23 07:33:43 +03:00
|
|
|
lineNumbers,
|
2021-05-25 03:41:12 +03:00
|
|
|
titlePage,
|
2021-03-19 20:53:56 +00:00
|
|
|
verticalAlign,
|
2021-05-25 03:41:12 +03:00
|
|
|
column,
|
2021-03-19 20:53:56 +00:00
|
|
|
type,
|
|
|
|
}: ISectionPropertiesOptions = {}) {
|
2020-02-28 18:44:41 +00:00
|
|
|
super("w:sectPr");
|
2018-06-21 12:03:34 +02:00
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
this.addHeaderFooterGroup(HeaderFooterType.HEADER, headerWrapperGroup);
|
|
|
|
this.addHeaderFooterGroup(HeaderFooterType.FOOTER, footerWrapperGroup);
|
2018-09-07 21:48:59 +01:00
|
|
|
|
2021-05-20 02:18:17 +03:00
|
|
|
if (type) {
|
|
|
|
this.root.push(new Type(type));
|
2019-02-04 18:49:12 +05:30
|
|
|
}
|
|
|
|
|
2025-04-14 16:43:15 +05:30
|
|
|
this.root.push(createPageSize({ width, height, orientation }));
|
2021-05-20 03:42:10 +03:00
|
|
|
this.root.push(new PageMargin(top, right, bottom, left, header, footer, gutter));
|
2021-05-20 02:18:17 +03:00
|
|
|
|
2021-05-23 07:33:43 +03:00
|
|
|
if (borders) {
|
|
|
|
this.root.push(new PageBorders(borders));
|
2018-07-03 13:48:31 +02:00
|
|
|
}
|
|
|
|
|
2021-05-23 07:33:43 +03:00
|
|
|
if (lineNumbers) {
|
2023-12-25 02:47:43 +00:00
|
|
|
this.root.push(createLineNumberType(lineNumbers));
|
2018-09-04 17:16:31 +03:00
|
|
|
}
|
2019-10-29 12:55:15 +02:00
|
|
|
|
2021-05-23 07:33:43 +03:00
|
|
|
this.root.push(new PageNumberType(pageNumbers));
|
2021-05-20 02:18:17 +03:00
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
if (column) {
|
|
|
|
this.root.push(new Columns(column));
|
|
|
|
}
|
2021-05-20 02:18:17 +03:00
|
|
|
|
2019-10-31 13:54:53 +02:00
|
|
|
if (verticalAlign) {
|
2021-05-24 21:06:34 +03:00
|
|
|
this.root.push(new VerticalAlignElement(verticalAlign));
|
2019-10-29 12:55:15 +02:00
|
|
|
}
|
2021-02-22 21:04:02 +00:00
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
if (titlePage !== undefined) {
|
|
|
|
this.root.push(new OnOffElement("w:titlePg", titlePage));
|
2021-02-22 21:04:02 +00:00
|
|
|
}
|
2021-05-20 02:18:17 +03:00
|
|
|
|
2021-11-19 22:30:38 +09:00
|
|
|
if (textDirection) {
|
2021-11-26 15:07:15 +00:00
|
|
|
this.root.push(new PageTextDirection(textDirection));
|
2021-11-19 22:30:38 +09:00
|
|
|
}
|
|
|
|
|
2025-04-14 16:43:15 +05:30
|
|
|
this.root.push(createDocumentGrid({ linePitch, charSpace, type: gridType }));
|
2018-10-05 01:33:17 +01:00
|
|
|
}
|
2018-09-04 17:16:31 +03:00
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
private addHeaderFooterGroup(
|
2023-12-22 10:25:00 +09:00
|
|
|
type: (typeof HeaderFooterType)[keyof typeof HeaderFooterType],
|
2021-05-25 03:41:12 +03:00
|
|
|
group: IHeaderFooterGroup<HeaderWrapper> | IHeaderFooterGroup<FooterWrapper>,
|
|
|
|
): void {
|
|
|
|
if (group.default) {
|
2021-03-19 20:53:56 +00:00
|
|
|
this.root.push(
|
2021-05-25 03:41:12 +03:00
|
|
|
new HeaderFooterReference(type, {
|
|
|
|
type: HeaderFooterReferenceType.DEFAULT,
|
|
|
|
id: group.default.View.ReferenceId,
|
2021-03-19 20:53:56 +00:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
if (group.first) {
|
2021-03-19 20:53:56 +00:00
|
|
|
this.root.push(
|
2021-05-25 03:41:12 +03:00
|
|
|
new HeaderFooterReference(type, {
|
|
|
|
type: HeaderFooterReferenceType.FIRST,
|
|
|
|
id: group.first.View.ReferenceId,
|
2021-03-19 20:53:56 +00:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
if (group.even) {
|
2021-03-19 20:53:56 +00:00
|
|
|
this.root.push(
|
2021-05-25 03:41:12 +03:00
|
|
|
new HeaderFooterReference(type, {
|
|
|
|
type: HeaderFooterReferenceType.EVEN,
|
|
|
|
id: group.even.View.ReferenceId,
|
2021-03-19 20:53:56 +00:00
|
|
|
}),
|
|
|
|
);
|
2018-10-05 01:33:17 +01:00
|
|
|
}
|
2018-06-21 12:03:34 +02:00
|
|
|
}
|
2018-01-24 00:01:38 +00:00
|
|
|
}
|