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";
|
|
|
|
|
|
|
|
export type RunChild = Text | DeleteText | Tab | Break;
|
|
|
|
|
|
|
|
export type RunProperty = {
|
|
|
|
size?: number;
|
|
|
|
color?: string;
|
|
|
|
highlight?: string;
|
|
|
|
bold?: boolean;
|
|
|
|
italic?: boolean;
|
|
|
|
underline?: string;
|
|
|
|
vanish?: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|