Make Paragraph declaritive
This commit is contained in:
@ -1,22 +1,23 @@
|
||||
// http://officeopenxml.com/WPalignment.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export enum AlignmentOptions {
|
||||
export enum AlignmentType {
|
||||
START = "start",
|
||||
END = "end",
|
||||
CENTER = "center",
|
||||
BOTH = "both",
|
||||
JUSTIFIED = "both",
|
||||
DISTRIBUTE = "distribute",
|
||||
LEFT = "left",
|
||||
RIGHT = "right",
|
||||
}
|
||||
|
||||
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentOptions }> {
|
||||
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentType }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
export class Alignment extends XmlComponent {
|
||||
constructor(type: AlignmentOptions) {
|
||||
constructor(type: AlignmentType) {
|
||||
super("w:jc");
|
||||
this.root.push(new AlignmentAttributes({ val: type }));
|
||||
}
|
||||
|
17
src/file/paragraph/formatting/border-attributes.ts
Normal file
17
src/file/paragraph/formatting/border-attributes.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IBorderAttributesProperties {
|
||||
readonly color: string;
|
||||
readonly space: number;
|
||||
readonly val: string;
|
||||
readonly sz: number;
|
||||
}
|
||||
|
||||
export class BorderAttributes extends XmlAttributeComponent<IBorderAttributesProperties> {
|
||||
protected readonly xmlKeys = {
|
||||
val: "w:val",
|
||||
color: "w:color",
|
||||
space: "w:space",
|
||||
sz: "w:sz",
|
||||
};
|
||||
}
|
@ -31,9 +31,9 @@ describe("ThematicBreak", () => {
|
||||
const newJson = Utility.jsonify(thematicBreak);
|
||||
const attributes = {
|
||||
color: "auto",
|
||||
space: "1",
|
||||
space: 1,
|
||||
val: "single",
|
||||
sz: "6",
|
||||
sz: 6,
|
||||
};
|
||||
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes));
|
||||
});
|
||||
|
@ -1,13 +1,30 @@
|
||||
// http://officeopenxml.com/WPborders.php
|
||||
import { Attributes, XmlComponent } from "file/xml-components";
|
||||
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 {
|
||||
public setProperties(color: string, space: string, value: string, size: string): XmlComponent {
|
||||
const attrs = new Attributes({
|
||||
color: color,
|
||||
space: space,
|
||||
val: value,
|
||||
sz: size,
|
||||
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);
|
||||
|
||||
@ -16,48 +33,40 @@ class BorderProperty extends XmlComponent {
|
||||
}
|
||||
|
||||
export class Border extends XmlComponent {
|
||||
constructor() {
|
||||
constructor(options: IBorderOptions) {
|
||||
super("w:pBdr");
|
||||
}
|
||||
|
||||
public addTopBorder(color: string = "auto", space: string = "1", value: string = "single", size: string = "6"): XmlComponent {
|
||||
const top = new BorderProperty("w:top");
|
||||
top.setProperties(color, space, value, size);
|
||||
this.root.push(top);
|
||||
if (options.top !== undefined) {
|
||||
const borderProperty = new BorderProperty("w:top", options.top);
|
||||
this.root.push(borderProperty);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
if (options.bottom !== undefined) {
|
||||
const borderProperty = new BorderProperty("w:bottom", options.bottom);
|
||||
this.root.push(borderProperty);
|
||||
}
|
||||
|
||||
public addBottomBorder(color: string = "auto", space: string = "1", value: string = "single", size: string = "6"): XmlComponent {
|
||||
const bottom = new BorderProperty("w:bottom");
|
||||
bottom.setProperties(color, space, value, size);
|
||||
this.root.push(bottom);
|
||||
if (options.left !== undefined) {
|
||||
const borderProperty = new BorderProperty("w:left", options.left);
|
||||
this.root.push(borderProperty);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public addLeftBorder(color: string = "auto", space: string = "1", value: string = "single", size: string = "6"): XmlComponent {
|
||||
const left = new BorderProperty("w:left");
|
||||
left.setProperties(color, space, value, size);
|
||||
this.root.push(left);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public addRightBorder(color: string = "auto", space: string = "1", value: string = "single", size: string = "6"): XmlComponent {
|
||||
const right = new BorderProperty("w:right");
|
||||
right.setProperties(color, space, value, size);
|
||||
this.root.push(right);
|
||||
|
||||
return this;
|
||||
if (options.right !== undefined) {
|
||||
const borderProperty = new BorderProperty("w:right", options.right);
|
||||
this.root.push(borderProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ThematicBreak extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:pBdr");
|
||||
const bottom = new BorderProperty("w:bottom");
|
||||
bottom.setProperties("auto", "1", "single", "6");
|
||||
const bottom = new BorderProperty("w:bottom", {
|
||||
color: "auto",
|
||||
space: 1,
|
||||
value: "single",
|
||||
size: 6,
|
||||
});
|
||||
this.root.push(bottom);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,15 @@
|
||||
import { Attributes, XmlComponent } from "file/xml-components";
|
||||
|
||||
export enum HeadingLevel {
|
||||
HEADING_1 = "Heading1",
|
||||
HEADING_2 = "Heading2",
|
||||
HEADING_3 = "Heading3",
|
||||
HEADING_4 = "Heading4",
|
||||
HEADING_5 = "Heading5",
|
||||
HEADING_6 = "Heading6",
|
||||
TITLE = "Title",
|
||||
}
|
||||
|
||||
export class Style extends XmlComponent {
|
||||
public readonly styleId: string;
|
||||
|
||||
|
Reference in New Issue
Block a user