further clean up border code; update paragraph borders to use shared type; BREAKING: paragraph border value attr renamed to style, to match other usages of borders

This commit is contained in:
Tom Hunkapiller
2021-05-23 08:00:49 +03:00
parent 54ab55b92c
commit 08bd2744b6
18 changed files with 100 additions and 115 deletions

View File

@ -1,57 +1,32 @@
// http://officeopenxml.com/WPborders.php
import { BorderElement, BorderStyle, IBorderOptions } from "file/border";
import { XmlComponent } from "file/xml-components";
import { BorderAttributes } from "./border-attributes";
interface IBorderPropertyOptions {
readonly color: string;
readonly space: number;
readonly value: string;
readonly size: number;
}
export interface IBorderOptions {
readonly top?: IBorderPropertyOptions;
readonly bottom?: IBorderPropertyOptions;
readonly left?: IBorderPropertyOptions;
readonly right?: IBorderPropertyOptions;
}
class BorderProperty extends XmlComponent {
constructor(rootKey: string, options: IBorderPropertyOptions = { color: "auto", space: 1, value: "single", size: 6 }) {
super(rootKey);
const attrs = new BorderAttributes({
color: options.color,
space: options.space,
val: options.value,
sz: options.size,
});
this.root.push(attrs);
}
export interface IBordersOptions {
readonly top?: IBorderOptions;
readonly bottom?: IBorderOptions;
readonly left?: IBorderOptions;
readonly right?: IBorderOptions;
}
export class Border extends XmlComponent {
constructor(options: IBorderOptions) {
constructor(options: IBordersOptions) {
super("w:pBdr");
if (options.top !== undefined) {
const borderProperty = new BorderProperty("w:top", options.top);
this.root.push(borderProperty);
if (options.top) {
this.root.push(new BorderElement("w:top", options.top));
}
if (options.bottom !== undefined) {
const borderProperty = new BorderProperty("w:bottom", options.bottom);
this.root.push(borderProperty);
if (options.bottom) {
this.root.push(new BorderElement("w:bottom", options.bottom));
}
if (options.left !== undefined) {
const borderProperty = new BorderProperty("w:left", options.left);
this.root.push(borderProperty);
if (options.left) {
this.root.push(new BorderElement("w:left", options.left));
}
if (options.right !== undefined) {
const borderProperty = new BorderProperty("w:right", options.right);
this.root.push(borderProperty);
if (options.right) {
this.root.push(new BorderElement("w:right", options.right));
}
}
}
@ -59,10 +34,10 @@ export class Border extends XmlComponent {
export class ThematicBreak extends XmlComponent {
constructor() {
super("w:pBdr");
const bottom = new BorderProperty("w:bottom", {
const bottom = new BorderElement("w:bottom", {
color: "auto",
space: 1,
value: "single",
style: BorderStyle.SINGLE,
size: 6,
});
this.root.push(bottom);