/
tab-stop.ts
64 lines (56 loc) · 1.76 KB
/
tab-stop.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
// http://officeopenxml.com/WPtab.php
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
export interface TabStopDefinition {
readonly type: (typeof TabStopType)[keyof typeof TabStopType];
readonly position: number | (typeof TabStopPosition)[keyof typeof TabStopPosition];
readonly leader?: (typeof LeaderType)[keyof typeof LeaderType];
}
export class TabStop extends XmlComponent {
public constructor(tabDefinitions: readonly TabStopDefinition[]) {
super("w:tabs");
for (const tabDefinition of tabDefinitions) {
this.root.push(new TabStopItem(tabDefinition));
}
}
}
export const TabStopType = {
LEFT: "left",
RIGHT: "right",
CENTER: "center",
BAR: "bar",
CLEAR: "clear",
DECIMAL: "decimal",
END: "end",
NUM: "num",
START: "start",
} as const;
export const LeaderType = {
DOT: "dot",
HYPHEN: "hyphen",
// eslint-disable-next-line @typescript-eslint/naming-convention
MIDDLE_DOT: "middleDot",
NONE: "none",
UNDERSCORE: "underscore",
} as const;
export const TabStopPosition = {
MAX: 9026,
} as const;
export class TabAttributes extends XmlAttributeComponent<{
readonly val: (typeof TabStopType)[keyof typeof TabStopType];
readonly pos: string | number;
readonly leader?: (typeof LeaderType)[keyof typeof LeaderType];
}> {
protected readonly xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" };
}
export class TabStopItem extends XmlComponent {
public constructor({ type, position, leader }: TabStopDefinition) {
super("w:tab");
this.root.push(
new TabAttributes({
val: type,
pos: position,
leader: leader,
}),
);
}
}