unify Border type
This commit is contained in:
@ -18,7 +18,6 @@ describe("TableBorders", () => {
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -28,7 +27,6 @@ describe("TableBorders", () => {
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -38,7 +36,6 @@ describe("TableBorders", () => {
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -48,7 +45,6 @@ describe("TableBorders", () => {
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -58,7 +54,6 @@ describe("TableBorders", () => {
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -68,7 +63,6 @@ describe("TableBorders", () => {
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -96,7 +90,6 @@ describe("TableBorders", () => {
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
@ -106,7 +99,6 @@ describe("TableBorders", () => {
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -116,7 +108,6 @@ describe("TableBorders", () => {
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -126,7 +117,6 @@ describe("TableBorders", () => {
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -136,7 +126,6 @@ describe("TableBorders", () => {
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -146,7 +135,6 @@ describe("TableBorders", () => {
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -174,7 +162,6 @@ describe("TableBorders", () => {
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -184,7 +171,6 @@ describe("TableBorders", () => {
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
@ -194,7 +180,6 @@ describe("TableBorders", () => {
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -204,7 +189,6 @@ describe("TableBorders", () => {
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -214,7 +198,6 @@ describe("TableBorders", () => {
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -224,7 +207,6 @@ describe("TableBorders", () => {
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -252,7 +234,6 @@ describe("TableBorders", () => {
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -262,7 +243,6 @@ describe("TableBorders", () => {
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -272,7 +252,6 @@ describe("TableBorders", () => {
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
@ -282,7 +261,6 @@ describe("TableBorders", () => {
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -292,7 +270,6 @@ describe("TableBorders", () => {
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -302,7 +279,6 @@ describe("TableBorders", () => {
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -330,7 +306,6 @@ describe("TableBorders", () => {
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -340,7 +315,6 @@ describe("TableBorders", () => {
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -350,7 +324,6 @@ describe("TableBorders", () => {
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -360,7 +333,6 @@ describe("TableBorders", () => {
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
@ -370,7 +342,6 @@ describe("TableBorders", () => {
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -380,7 +351,6 @@ describe("TableBorders", () => {
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -408,7 +378,6 @@ describe("TableBorders", () => {
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -418,7 +387,6 @@ describe("TableBorders", () => {
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -428,7 +396,6 @@ describe("TableBorders", () => {
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -438,7 +405,6 @@ describe("TableBorders", () => {
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -448,7 +414,6 @@ describe("TableBorders", () => {
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
@ -458,7 +423,6 @@ describe("TableBorders", () => {
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -486,7 +450,6 @@ describe("TableBorders", () => {
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -496,7 +459,6 @@ describe("TableBorders", () => {
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -506,7 +468,6 @@ describe("TableBorders", () => {
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -516,7 +477,6 @@ describe("TableBorders", () => {
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -526,7 +486,6 @@ describe("TableBorders", () => {
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 4,
|
||||
"w:val": "single",
|
||||
},
|
||||
@ -536,7 +495,6 @@ describe("TableBorders", () => {
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "red",
|
||||
"w:space": 0,
|
||||
"w:sz": 1,
|
||||
"w:val": "double",
|
||||
},
|
||||
@ -558,7 +516,6 @@ describe("TableBorders", () => {
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
@ -568,7 +525,6 @@ describe("TableBorders", () => {
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
@ -578,7 +534,6 @@ describe("TableBorders", () => {
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
@ -588,7 +543,6 @@ describe("TableBorders", () => {
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
@ -598,7 +552,6 @@ describe("TableBorders", () => {
|
||||
"w:insideH": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
@ -608,7 +561,6 @@ describe("TableBorders", () => {
|
||||
"w:insideV": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": 0,
|
||||
"w:sz": 0,
|
||||
"w:val": "none",
|
||||
},
|
||||
|
@ -1,155 +1,76 @@
|
||||
// http://officeopenxml.com/WPtableBorders.php
|
||||
import { BorderElement, IBorderOptions } from "file/border";
|
||||
import { BorderStyle } from "file/styles";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
export interface ITableBordersOptions {
|
||||
readonly top?: {
|
||||
readonly style: BorderStyle;
|
||||
readonly size: number;
|
||||
readonly color: string;
|
||||
};
|
||||
readonly bottom?: {
|
||||
readonly style: BorderStyle;
|
||||
readonly size: number;
|
||||
readonly color: string;
|
||||
};
|
||||
readonly left?: {
|
||||
readonly style: BorderStyle;
|
||||
readonly size: number;
|
||||
readonly color: string;
|
||||
};
|
||||
readonly right?: {
|
||||
readonly style: BorderStyle;
|
||||
readonly size: number;
|
||||
readonly color: string;
|
||||
};
|
||||
readonly insideHorizontal?: {
|
||||
readonly style: BorderStyle;
|
||||
readonly size: number;
|
||||
readonly color: string;
|
||||
};
|
||||
readonly insideVertical?: {
|
||||
readonly style: BorderStyle;
|
||||
readonly size: number;
|
||||
readonly color: string;
|
||||
};
|
||||
readonly top?: IBorderOptions;
|
||||
readonly bottom?: IBorderOptions;
|
||||
readonly left?: IBorderOptions;
|
||||
readonly right?: IBorderOptions;
|
||||
readonly insideHorizontal?: IBorderOptions;
|
||||
readonly insideVertical?: IBorderOptions;
|
||||
}
|
||||
|
||||
const NONE_BORDER = {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
};
|
||||
|
||||
const DEFAULT_BORDER = {
|
||||
style: BorderStyle.SINGLE,
|
||||
size: 4,
|
||||
color: "auto",
|
||||
};
|
||||
|
||||
export class TableBorders extends XmlComponent {
|
||||
public static readonly NONE = {
|
||||
top: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
bottom: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
insideHorizontal: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
insideVertical: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "auto",
|
||||
},
|
||||
top: NONE_BORDER,
|
||||
bottom: NONE_BORDER,
|
||||
left: NONE_BORDER,
|
||||
right: NONE_BORDER,
|
||||
insideHorizontal: NONE_BORDER,
|
||||
insideVertical: NONE_BORDER,
|
||||
};
|
||||
|
||||
constructor(options: ITableBordersOptions) {
|
||||
super("w:tblBorders");
|
||||
|
||||
if (options.top) {
|
||||
this.root.push(new TableBordersElement("w:top", options.top.style, options.top.size, 0, options.top.color));
|
||||
this.root.push(new BorderElement("w:top", options.top));
|
||||
} else {
|
||||
this.root.push(new TableBordersElement("w:top", BorderStyle.SINGLE, 4, 0, "auto"));
|
||||
this.root.push(new BorderElement("w:top", DEFAULT_BORDER));
|
||||
}
|
||||
|
||||
if (options.left) {
|
||||
this.root.push(new TableBordersElement("w:left", options.left.style, options.left.size, 0, options.left.color));
|
||||
this.root.push(new BorderElement("w:left", options.left));
|
||||
} else {
|
||||
this.root.push(new TableBordersElement("w:left", BorderStyle.SINGLE, 4, 0, "auto"));
|
||||
this.root.push(new BorderElement("w:left", DEFAULT_BORDER));
|
||||
}
|
||||
|
||||
if (options.bottom) {
|
||||
this.root.push(new TableBordersElement("w:bottom", options.bottom.style, options.bottom.size, 0, options.bottom.color));
|
||||
this.root.push(new BorderElement("w:bottom", options.bottom));
|
||||
} else {
|
||||
this.root.push(new TableBordersElement("w:bottom", BorderStyle.SINGLE, 4, 0, "auto"));
|
||||
this.root.push(new BorderElement("w:bottom", DEFAULT_BORDER));
|
||||
}
|
||||
|
||||
if (options.right) {
|
||||
this.root.push(new TableBordersElement("w:right", options.right.style, options.right.size, 0, options.right.color));
|
||||
this.root.push(new BorderElement("w:right", options.right));
|
||||
} else {
|
||||
this.root.push(new TableBordersElement("w:right", BorderStyle.SINGLE, 4, 0, "auto"));
|
||||
this.root.push(new BorderElement("w:right", DEFAULT_BORDER));
|
||||
}
|
||||
|
||||
if (options.insideHorizontal) {
|
||||
this.root.push(
|
||||
new TableBordersElement(
|
||||
"w:insideH",
|
||||
options.insideHorizontal.style,
|
||||
options.insideHorizontal.size,
|
||||
0,
|
||||
options.insideHorizontal.color,
|
||||
),
|
||||
);
|
||||
this.root.push(new BorderElement("w:insideH", options.insideHorizontal));
|
||||
} else {
|
||||
this.root.push(new TableBordersElement("w:insideH", BorderStyle.SINGLE, 4, 0, "auto"));
|
||||
this.root.push(new BorderElement("w:insideH", DEFAULT_BORDER));
|
||||
}
|
||||
|
||||
if (options.insideVertical) {
|
||||
this.root.push(
|
||||
new TableBordersElement(
|
||||
"w:insideV",
|
||||
options.insideVertical.style,
|
||||
options.insideVertical.size,
|
||||
0,
|
||||
options.insideVertical.color,
|
||||
),
|
||||
);
|
||||
this.root.push(new BorderElement("w:insideV", options.insideVertical));
|
||||
} else {
|
||||
this.root.push(new TableBordersElement("w:insideV", BorderStyle.SINGLE, 4, 0, "auto"));
|
||||
this.root.push(new BorderElement("w:insideV", DEFAULT_BORDER));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TableBordersElement extends XmlComponent {
|
||||
constructor(elementName: string, value: string, size: number, space: number, color: string) {
|
||||
super(elementName);
|
||||
this.root.push(
|
||||
new TableBordersAttributes({
|
||||
value,
|
||||
size,
|
||||
space,
|
||||
color,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TableBordersAttributes extends XmlAttributeComponent<{
|
||||
readonly value: string;
|
||||
readonly size: number;
|
||||
readonly space: number;
|
||||
readonly color: string;
|
||||
}> {
|
||||
protected readonly xmlKeys = {
|
||||
value: "w:val",
|
||||
size: "w:sz",
|
||||
space: "w:space",
|
||||
color: "w:color",
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user