Files
docx-js/src/file/paragraph/formatting/border.ts

73 lines
2.0 KiB
TypeScript
Raw Normal View History

2017-09-22 14:46:19 +01:00
// http://officeopenxml.com/WPborders.php
2019-06-12 01:03:36 +01:00
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;
}
2016-03-29 04:50:23 +01:00
class BorderProperty extends XmlComponent {
2019-06-12 01:03:36 +01:00
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);
return this;
}
}
export class Border extends XmlComponent {
2019-06-12 01:03:36 +01:00
constructor(options: IBorderOptions) {
super("w:pBdr");
2019-06-12 01:03:36 +01:00
if (options.top !== undefined) {
const borderProperty = new BorderProperty("w:top", options.top);
this.root.push(borderProperty);
}
2019-06-12 01:03:36 +01:00
if (options.bottom !== undefined) {
const borderProperty = new BorderProperty("w:bottom", options.bottom);
this.root.push(borderProperty);
}
2019-06-12 01:03:36 +01:00
if (options.left !== undefined) {
const borderProperty = new BorderProperty("w:left", options.left);
this.root.push(borderProperty);
}
2019-06-12 01:03:36 +01:00
if (options.right !== undefined) {
const borderProperty = new BorderProperty("w:right", options.right);
this.root.push(borderProperty);
}
2016-03-29 04:50:23 +01:00
}
}
2016-04-09 20:16:35 +01:00
export class ThematicBreak extends XmlComponent {
2016-03-29 04:50:23 +01:00
constructor() {
2016-04-09 20:16:35 +01:00
super("w:pBdr");
2019-06-12 01:03:36 +01:00
const bottom = new BorderProperty("w:bottom", {
color: "auto",
space: 1,
value: "single",
size: 6,
});
this.root.push(bottom);
2016-03-29 04:50:23 +01:00
}
2017-03-08 21:36:09 +00:00
}