Files
docx-js/src/file/paragraph/formatting/tab-stop.ts

64 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-09-19 15:17:58 +01:00
// http://officeopenxml.com/WPtab.php
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
2016-05-18 17:06:21 +01:00
export interface TabStopDefinition {
2022-10-16 00:21:34 +01:00
readonly type: TabStopType;
readonly position: number | TabStopPosition;
readonly leader?: LeaderType;
2022-10-16 00:20:16 +01:00
}
export class TabStop extends XmlComponent {
2022-10-16 00:21:34 +01:00
public constructor(tabDefinitions: readonly TabStopDefinition[]) {
2016-05-18 17:06:21 +01:00
super("w:tabs");
2022-10-16 00:21:34 +01:00
for (const tabDefinition of tabDefinitions) {
this.root.push(new TabStopItem(tabDefinition));
}
2016-05-18 17:06:21 +01:00
}
}
2019-10-09 20:56:31 +01:00
export enum TabStopType {
LEFT = "left",
RIGHT = "right",
CENTER = "center",
BAR = "bar",
CLEAR = "clear",
DECIMAL = "decimal",
END = "end",
NUM = "num",
START = "start",
}
export enum LeaderType {
DOT = "dot",
HYPHEN = "hyphen",
MIDDLE_DOT = "middleDot",
NONE = "none",
UNDERSCORE = "underscore",
}
2017-03-12 22:06:11 +01:00
export enum TabStopPosition {
MAX = 9026,
}
export class TabAttributes extends XmlAttributeComponent<{
2019-10-09 20:56:31 +01:00
readonly val: TabStopType;
readonly pos: string | number;
readonly leader?: LeaderType;
}> {
protected readonly xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" };
2017-03-12 22:06:11 +01:00
}
export class TabStopItem extends XmlComponent {
2022-10-16 00:21:34 +01:00
public constructor({ type, position, leader }: TabStopDefinition) {
2016-05-18 17:06:21 +01:00
super("w:tab");
2022-10-16 00:21:34 +01:00
this.root.push(
new TabAttributes({
val: type,
pos: position,
leader: leader,
}),
);
2016-05-18 17:06:21 +01:00
}
}