/
document-background.ts
78 lines (72 loc) · 3.04 KB
/
document-background.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// http://officeopenxml.com/WPdocument.php
// http://www.datypic.com/sc/ooxml/e-w_background-1.html
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { hexColorValue, uCharHexNumber } from "@util/values";
// <xsd:simpleType name="ST_ThemeColor">
// <xsd:restriction base="xsd:string">
// <xsd:enumeration value="dark1"/>
// <xsd:enumeration value="light1"/>
// <xsd:enumeration value="dark2"/>
// <xsd:enumeration value="light2"/>
// <xsd:enumeration value="accent1"/>
// <xsd:enumeration value="accent2"/>
// <xsd:enumeration value="accent3"/>
// <xsd:enumeration value="accent4"/>
// <xsd:enumeration value="accent5"/>
// <xsd:enumeration value="accent6"/>
// <xsd:enumeration value="hyperlink"/>
// <xsd:enumeration value="followedHyperlink"/>
// <xsd:enumeration value="none"/>
// <xsd:enumeration value="background1"/>
// <xsd:enumeration value="text1"/>
// <xsd:enumeration value="background2"/>
// <xsd:enumeration value="text2"/>
// </xsd:restriction>
// </xsd:simpleType>
export class DocumentBackgroundAttributes extends XmlAttributeComponent<{
readonly color?: string;
readonly themeColor?: string;
readonly themeShade?: string;
readonly themeTint?: string;
}> {
protected readonly xmlKeys = {
color: "w:color",
themeColor: "w:themeColor",
themeShade: "w:themeShade",
themeTint: "w:themeTint",
};
}
export interface IDocumentBackgroundOptions {
readonly color?: string;
readonly themeColor?: string;
readonly themeShade?: string;
readonly themeTint?: string;
}
// <xsd:complexType name="CT_Background">
// <xsd:sequence>
// <xsd:sequence maxOccurs="unbounded">
// <xsd:any processContents="lax" namespace="urn:schemas-microsoft-com:vml" minOccurs="0"
// maxOccurs="unbounded"/>
// <xsd:any processContents="lax" namespace="urn:schemas-microsoft-com:office:office"
// minOccurs="0" maxOccurs="unbounded"/>
// </xsd:sequence>
// <xsd:element name="drawing" type="CT_Drawing" minOccurs="0"/>
// </xsd:sequence>
// <xsd:attribute name="color" type="ST_HexColor" use="optional" default="auto"/>
// <xsd:attribute name="themeColor" type="ST_ThemeColor" use="optional"/>
// <xsd:attribute name="themeTint" type="ST_UcharHexNumber" use="optional"/>
// <xsd:attribute name="themeShade" type="ST_UcharHexNumber" use="optional"/>
// </xsd:complexType>
export class DocumentBackground extends XmlComponent {
public constructor(options: IDocumentBackgroundOptions) {
super("w:background");
this.root.push(
new DocumentBackgroundAttributes({
color: options.color === undefined ? undefined : hexColorValue(options.color),
themeColor: options.themeColor,
themeShade: options.themeShade === undefined ? undefined : uCharHexNumber(options.themeShade),
themeTint: options.themeTint === undefined ? undefined : uCharHexNumber(options.themeTint),
}),
);
}
}