2020-01-30 16:14:25 +02:00
|
|
|
import { Text } from "./text";
|
|
|
|
import { DeleteText } from "./delete-text";
|
|
|
|
import { Tab } from "./tab";
|
|
|
|
import { Break, BreakType } from "./break";
|
2021-03-20 17:16:43 +02:00
|
|
|
import { BorderType } from "./border";
|
2020-01-30 16:14:25 +02:00
|
|
|
|
|
|
|
export type RunChild = Text | DeleteText | Tab | Break;
|
|
|
|
|
2021-03-20 17:16:43 +02:00
|
|
|
export type TextBorder = {
|
|
|
|
borderType: BorderType;
|
|
|
|
color: string;
|
|
|
|
space: number;
|
|
|
|
size: number;
|
|
|
|
};
|
|
|
|
|
2021-06-07 18:10:44 +03:00
|
|
|
export type VertAlignType = "baseline" | "superscript" | "subscript";
|
|
|
|
|
2020-01-30 16:14:25 +02:00
|
|
|
export type RunProperty = {
|
|
|
|
size?: number;
|
|
|
|
color?: string;
|
|
|
|
highlight?: string;
|
2021-06-07 18:10:44 +03:00
|
|
|
vertAlign?: VertAlignType;
|
2020-01-30 16:14:25 +02:00
|
|
|
bold?: boolean;
|
|
|
|
italic?: boolean;
|
|
|
|
underline?: string;
|
|
|
|
vanish?: boolean;
|
2020-06-08 07:41:13 +03:00
|
|
|
fonts?: RunFonts;
|
2020-10-14 04:16:13 +03:00
|
|
|
spacing?: number;
|
2021-03-20 17:16:43 +02:00
|
|
|
textBorder?: TextBorder;
|
2020-06-08 07:41:13 +03:00
|
|
|
};
|
|
|
|
|
2021-04-14 06:01:38 +03:00
|
|
|
export const createDefaultRunProperty = (): RunProperty => {
|
|
|
|
return {};
|
|
|
|
};
|
|
|
|
|
2020-06-08 20:14:08 +03:00
|
|
|
export class RunFonts {
|
|
|
|
_ascii?: string;
|
|
|
|
_hiAnsi?: string;
|
|
|
|
_eastAsia?: string;
|
|
|
|
_cs?: string;
|
|
|
|
|
|
|
|
ascii(f: string) {
|
|
|
|
this._ascii = f;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
hiAnsi(f: string) {
|
|
|
|
this._hiAnsi = f;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
cs(f: string) {
|
|
|
|
this._cs = f;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
eastAsia(f: string) {
|
|
|
|
this._eastAsia = f;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 16:14:25 +02:00
|
|
|
|
|
|
|
export class Run {
|
|
|
|
children: RunChild[] = [];
|
|
|
|
property: RunProperty = {};
|
|
|
|
|
|
|
|
addText(text: string) {
|
|
|
|
this.children.push(new Text(text));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
addDeleteText(text: string) {
|
|
|
|
this.children.push(new DeleteText(text));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
addTab() {
|
|
|
|
this.children.push(new Tab());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
addBreak(type: BreakType) {
|
|
|
|
this.children.push(new Break(type));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
size(size: number) {
|
2020-01-30 18:14:48 +02:00
|
|
|
this.property = { ...this.property, size };
|
2020-01-30 16:14:25 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
color(color: string) {
|
2020-01-30 18:14:48 +02:00
|
|
|
this.property = { ...this.property, color };
|
2020-01-30 16:14:25 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
highlight(color: string) {
|
2020-01-30 18:14:48 +02:00
|
|
|
this.property = { ...this.property, highlight: color };
|
2020-01-30 16:14:25 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:10:44 +03:00
|
|
|
vertAlign(vertAlign: VertAlignType) {
|
|
|
|
this.property = { ...this.property, vertAlign };
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-01-30 16:14:25 +02:00
|
|
|
bold() {
|
2020-01-30 18:14:48 +02:00
|
|
|
this.property = { ...this.property, bold: true };
|
2020-01-30 16:14:25 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
italic() {
|
2020-01-30 18:14:48 +02:00
|
|
|
this.property = { ...this.property, italic: true };
|
2020-01-30 16:14:25 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
underline(type: string) {
|
2020-01-30 18:14:48 +02:00
|
|
|
this.property = { ...this.property, underline: type };
|
2020-01-30 16:14:25 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
vanish() {
|
2020-01-30 18:14:48 +02:00
|
|
|
this.property = { ...this.property, vanish: true };
|
2020-01-30 16:14:25 +02:00
|
|
|
return this;
|
|
|
|
}
|
2020-06-08 07:41:13 +03:00
|
|
|
|
|
|
|
fonts(fonts: RunFonts) {
|
|
|
|
this.property = { ...this.property, fonts };
|
|
|
|
return this;
|
|
|
|
}
|
2020-10-14 04:16:13 +03:00
|
|
|
|
|
|
|
spacing(spacing: number) {
|
|
|
|
this.property = { ...this.property, spacing };
|
|
|
|
return this;
|
|
|
|
}
|
2021-03-20 17:16:43 +02:00
|
|
|
|
|
|
|
textBorder(type: BorderType, size: number, space: number, color: string) {
|
|
|
|
this.property = {
|
|
|
|
...this.property,
|
|
|
|
textBorder: {
|
|
|
|
borderType: type,
|
|
|
|
size,
|
|
|
|
space,
|
|
|
|
color,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return this;
|
|
|
|
}
|
2020-01-30 16:14:25 +02:00
|
|
|
}
|