2017-09-19 15:17:58 +01:00
|
|
|
// http://officeopenxml.com/WPtab.php
|
2022-06-26 23:26:42 +01:00
|
|
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
2016-05-18 17:06:21 +01:00
|
|
|
|
2022-10-14 16:38:02 +05:45
|
|
|
export interface TabStopDefinition {
|
2022-10-16 00:20:16 +01:00
|
|
|
type: TabStopType;
|
|
|
|
position: number | TabStopPosition;
|
|
|
|
leader?: LeaderType;
|
|
|
|
}
|
2022-10-14 16:38:02 +05:45
|
|
|
|
2017-07-07 14:31:08 +01:00
|
|
|
export class TabStop extends XmlComponent {
|
2022-10-16 00:20:16 +01:00
|
|
|
public constructor(tabDefs: TabStopDefinition[] | TabStopDefinition | TabStopType, position?: number, leader?: LeaderType) {
|
2016-05-18 17:06:21 +01:00
|
|
|
super("w:tabs");
|
2022-10-16 00:20:16 +01:00
|
|
|
if (typeof tabDefs === "string") {
|
2022-10-14 17:01:41 +05:45
|
|
|
this.root.push(new TabStopItem(tabDefs, position, leader));
|
2022-10-14 16:38:02 +05:45
|
|
|
} else {
|
2022-10-14 17:01:41 +05:45
|
|
|
if (Array.isArray(tabDefs)) {
|
2022-10-16 00:20:16 +01:00
|
|
|
tabDefs.forEach(
|
|
|
|
function (tabDef) {
|
|
|
|
this.root.push(new TabStopItem(tabDef));
|
|
|
|
}.bind(this),
|
|
|
|
);
|
2022-10-14 17:01:41 +05:45
|
|
|
} else {
|
|
|
|
this.root.push(new TabStopItem(tabDefs));
|
|
|
|
}
|
2022-10-14 16:38:02 +05:45
|
|
|
}
|
2016-05-18 17:06:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 20:56:31 +01:00
|
|
|
export enum TabStopType {
|
2018-11-02 02:51:57 +00:00
|
|
|
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
|
|
|
|
2019-09-30 22:56:21 +01:00
|
|
|
export enum TabStopPosition {
|
|
|
|
MAX = 9026,
|
|
|
|
}
|
|
|
|
|
2018-11-02 02:51:57 +00:00
|
|
|
export class TabAttributes extends XmlAttributeComponent<{
|
2019-10-09 20:56:31 +01:00
|
|
|
readonly val: TabStopType;
|
2018-11-02 02:51:57 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-09-18 05:24:19 -03:00
|
|
|
export class TabStopItem extends XmlComponent {
|
2022-10-16 00:20:16 +01:00
|
|
|
public constructor(tabDef: TabStopDefinition | TabStopType, position?: number, leader?: LeaderType) {
|
2016-05-18 17:06:21 +01:00
|
|
|
super("w:tab");
|
2022-10-14 17:01:41 +05:45
|
|
|
if (typeof tabDef === "string") {
|
|
|
|
if (typeof position === "number")
|
|
|
|
this.root.push(
|
|
|
|
new TabAttributes({
|
|
|
|
val: tabDef,
|
|
|
|
pos: position,
|
|
|
|
leader,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
else throw Error("Undefined position: " + position);
|
|
|
|
} else {
|
|
|
|
this.root.push(
|
|
|
|
new TabAttributes({
|
|
|
|
val: tabDef.type,
|
|
|
|
pos: tabDef.position,
|
|
|
|
leader: tabDef.leader,
|
2022-10-16 00:20:16 +01:00
|
|
|
}),
|
2022-10-14 17:01:41 +05:45
|
|
|
);
|
|
|
|
}
|
2016-05-18 17:06:21 +01:00
|
|
|
}
|
|
|
|
}
|