unify Border type

This commit is contained in:
Tom Hunkapiller
2021-05-23 07:14:00 +03:00
parent 496fcb55fa
commit 5155cdaf45
8 changed files with 116 additions and 243 deletions

View File

@ -70,22 +70,22 @@ describe("PageBorders", () => {
expect(tree["w:pgBorders"][0]).to.deep.equal({ _attr: { "w:display": "firstPage", "w:zOrder": "back" } });
expect(tree["w:pgBorders"][1]).to.deep.equal({
"w:top": {
_attr: { "w:color": "001122", "w:size": 10, "w:val": "doubleWave" },
_attr: { "w:color": "001122", "w:sz": 10, "w:val": "doubleWave" },
},
});
expect(tree["w:pgBorders"][2]).to.deep.equal({
"w:right": {
_attr: { "w:color": "223344", "w:size": 20, "w:val": "double" },
_attr: { "w:color": "223344", "w:sz": 20, "w:val": "double" },
},
});
expect(tree["w:pgBorders"][3]).to.deep.equal({
"w:bottom": {
_attr: { "w:color": "556677", "w:size": 30, "w:val": "single" },
_attr: { "w:color": "556677", "w:sz": 30, "w:val": "single" },
},
});
expect(tree["w:pgBorders"][4]).to.deep.equal({
"w:left": {
_attr: { "w:color": "889900", "w:size": 40, "w:val": "dotted" },
_attr: { "w:color": "889900", "w:sz": 40, "w:val": "dotted" },
},
});
});

View File

@ -1,6 +1,6 @@
// http://officeopenxml.com/WPsectionBorders.php
import { BorderStyle } from "file/styles";
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { BorderElement, IBorderOptions } from "file/border";
import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent } from "file/xml-components";
export enum PageBorderDisplay {
ALL_PAGES = "allPages",
@ -24,36 +24,12 @@ export interface IPageBorderAttributes {
readonly zOrder?: PageBorderZOrder;
}
export interface IPageBorderConfiguration {
readonly style?: BorderStyle;
readonly size?: number;
readonly color?: string;
readonly space?: number;
}
export interface IPageBordersOptions {
readonly pageBorders?: IPageBorderAttributes;
readonly pageBorderTop?: IPageBorderConfiguration;
readonly pageBorderRight?: IPageBorderConfiguration;
readonly pageBorderBottom?: IPageBorderConfiguration;
readonly pageBorderLeft?: IPageBorderConfiguration;
}
class PageBordeAttributes extends XmlAttributeComponent<IPageBorderConfiguration> {
protected readonly xmlKeys = {
style: "w:val",
size: "w:size",
color: "w:color",
space: "w:space",
};
}
class PageBorder extends XmlComponent {
constructor(key: string, options: IPageBorderConfiguration) {
super(key);
this.root.push(new PageBordeAttributes(options));
}
readonly pageBorderTop?: IBorderOptions;
readonly pageBorderRight?: IBorderOptions;
readonly pageBorderBottom?: IBorderOptions;
readonly pageBorderLeft?: IBorderOptions;
}
class PageBordersAttributes extends XmlAttributeComponent<IPageBorderAttributes> {
@ -85,16 +61,16 @@ export class PageBorders extends IgnoreIfEmptyXmlComponent {
}
if (options.pageBorderTop) {
this.root.push(new PageBorder("w:top", options.pageBorderTop));
this.root.push(new BorderElement("w:top", options.pageBorderTop));
}
if (options.pageBorderRight) {
this.root.push(new PageBorder("w:right", options.pageBorderRight));
this.root.push(new BorderElement("w:right", options.pageBorderRight));
}
if (options.pageBorderBottom) {
this.root.push(new PageBorder("w:bottom", options.pageBorderBottom));
this.root.push(new BorderElement("w:bottom", options.pageBorderBottom));
}
if (options.pageBorderLeft) {
this.root.push(new PageBorder("w:left", options.pageBorderLeft));
this.root.push(new BorderElement("w:left", options.pageBorderLeft));
}
}
}