/
page-number.ts
59 lines (52 loc) · 2.02 KB
/
page-number.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// http://officeopenxml.com/WPSectionPgNumType.php
import { NumberFormat } from "@file/shared/number-format";
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { decimalNumber } from "@util/values";
// <xsd:simpleType name="ST_ChapterSep">
// <xsd:restriction base="xsd:string">
// <xsd:enumeration value="hyphen"/>
// <xsd:enumeration value="period"/>
// <xsd:enumeration value="colon"/>
// <xsd:enumeration value="emDash"/>
// <xsd:enumeration value="enDash"/>
// </xsd:restriction>
// </xsd:simpleType>
/* eslint-disable @typescript-eslint/naming-convention */
export const PageNumberSeparator = {
HYPHEN: "hyphen",
PERIOD: "period",
COLON: "colon",
EM_DASH: "emDash",
EN_DASH: "endash",
} as const;
/* eslint-enable */
export interface IPageNumberTypeAttributes {
readonly start?: number;
readonly formatType?: (typeof NumberFormat)[keyof typeof NumberFormat];
readonly separator?: (typeof PageNumberSeparator)[keyof typeof PageNumberSeparator];
}
// <xsd:complexType name="CT_PageNumber">
// <xsd:attribute name="fmt" type="ST_NumberFormat" use="optional" default="decimal"/>
// <xsd:attribute name="start" type="ST_DecimalNumber" use="optional"/>
// <xsd:attribute name="chapStyle" type="ST_DecimalNumber" use="optional"/>
// <xsd:attribute name="chapSep" type="ST_ChapterSep" use="optional" default="hyphen"/>
// </xsd:complexType>
export class PageNumberTypeAttributes extends XmlAttributeComponent<IPageNumberTypeAttributes> {
protected readonly xmlKeys = {
start: "w:start",
formatType: "w:fmt",
separator: "w:chapSep",
};
}
export class PageNumberType extends XmlComponent {
public constructor({ start, formatType, separator }: IPageNumberTypeAttributes) {
super("w:pgNumType");
this.root.push(
new PageNumberTypeAttributes({
start: start === undefined ? undefined : decimalNumber(start),
formatType,
separator,
}),
);
}
}