Introduce some functional programming techniques
This commit is contained in:
@ -1,26 +1,32 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class FidCharAttrs extends XmlAttributeComponent<{ type: "begin" | "end" | "separate"; dirty?: boolean }> {
|
||||
protected xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" };
|
||||
enum FieldCharacterType {
|
||||
BEGIN = "begin",
|
||||
END = "end",
|
||||
SEPARATE = "separate",
|
||||
}
|
||||
|
||||
class FidCharAttrs extends XmlAttributeComponent<{ readonly type: FieldCharacterType; readonly dirty?: boolean }> {
|
||||
protected readonly xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" };
|
||||
}
|
||||
|
||||
export class Begin extends XmlComponent {
|
||||
constructor(dirty?: boolean) {
|
||||
super("w:fldChar");
|
||||
this.root.push(new FidCharAttrs({ type: "begin", dirty }));
|
||||
this.root.push(new FidCharAttrs({ type: FieldCharacterType.BEGIN, dirty }));
|
||||
}
|
||||
}
|
||||
|
||||
export class Separate extends XmlComponent {
|
||||
constructor(dirty?: boolean) {
|
||||
super("w:fldChar");
|
||||
this.root.push(new FidCharAttrs({ type: "separate", dirty }));
|
||||
this.root.push(new FidCharAttrs({ type: FieldCharacterType.SEPARATE, dirty }));
|
||||
}
|
||||
}
|
||||
|
||||
export class End extends XmlComponent {
|
||||
constructor(dirty?: boolean) {
|
||||
super("w:fldChar");
|
||||
this.root.push(new FidCharAttrs({ type: "end", dirty }));
|
||||
this.root.push(new FidCharAttrs({ type: FieldCharacterType.END, dirty }));
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { SpaceType } from "file/space-type";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> {
|
||||
protected xmlKeys = { space: "xml:space" };
|
||||
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
|
||||
protected readonly xmlKeys = { space: "xml:space" };
|
||||
}
|
||||
|
||||
export class Page extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:instrText");
|
||||
this.root.push(new TextAttributes({ space: "preserve" }));
|
||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||
this.root.push("PAGE");
|
||||
}
|
||||
}
|
||||
|
@ -18,15 +18,7 @@ export class PictureRun extends Run {
|
||||
this.root.push(this.drawing);
|
||||
}
|
||||
|
||||
public scale(factorX: number, factorY?: number): void {
|
||||
if (!factorX) {
|
||||
factorX = 1;
|
||||
}
|
||||
|
||||
if (!factorY) {
|
||||
factorY = factorX;
|
||||
}
|
||||
|
||||
public scale(factorX: number = 1, factorY: number = factorX): void {
|
||||
this.drawing.scale(factorX, factorY);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { SpaceType } from "file/space-type";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> {
|
||||
protected xmlKeys = { space: "xml:space" };
|
||||
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
|
||||
protected readonly xmlKeys = { space: "xml:space" };
|
||||
}
|
||||
|
||||
export class Text extends XmlComponent {
|
||||
constructor(text: string) {
|
||||
super("w:t");
|
||||
this.root.push(new TextAttributes({ space: "preserve" }));
|
||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||
if (text) {
|
||||
this.root.push(text);
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
interface IRunFontAttributesProperties {
|
||||
ascii: string;
|
||||
cs: string;
|
||||
eastAsia: string;
|
||||
hAnsi: string;
|
||||
hint?: string;
|
||||
readonly ascii: string;
|
||||
readonly cs: string;
|
||||
readonly eastAsia: string;
|
||||
readonly hAnsi: string;
|
||||
readonly hint?: string;
|
||||
}
|
||||
|
||||
class RunFontAttributes extends XmlAttributeComponent<IRunFontAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
ascii: "w:ascii",
|
||||
cs: "w:cs",
|
||||
eastAsia: "w:eastAsia",
|
||||
|
@ -25,7 +25,7 @@ import { Underline } from "./underline";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
export class Run extends XmlComponent {
|
||||
protected properties: RunProperties;
|
||||
protected readonly properties: RunProperties;
|
||||
|
||||
constructor() {
|
||||
super("w:r");
|
||||
|
@ -1,13 +1,9 @@
|
||||
// http://officeopenxml.com/WPfieldInstructions.php
|
||||
import { SpaceType } from "file/space-type";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
enum SpaceType {
|
||||
DEFAULT = "default",
|
||||
PRESERVE = "preserve",
|
||||
}
|
||||
|
||||
class TextAttributes extends XmlAttributeComponent<{ space: SpaceType }> {
|
||||
protected xmlKeys = { space: "xml:space" };
|
||||
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
|
||||
protected readonly xmlKeys = { space: "xml:space" };
|
||||
}
|
||||
|
||||
export class SequentialIdentifierInstruction extends XmlComponent {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class StyleAttributes extends XmlAttributeComponent<{ val: string }> {
|
||||
protected xmlKeys = { val: "w:val" };
|
||||
class StyleAttributes extends XmlAttributeComponent<{ readonly val: string }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
export class Style extends XmlComponent {
|
||||
|
Reference in New Issue
Block a user