2020-06-08 07:41:13 +03:00
|
|
|
import { Run, RunProperty, RunFonts } from "./run";
|
2020-01-30 16:14:25 +02:00
|
|
|
import { Insert } from "./insert";
|
|
|
|
import { Delete } from "./delete";
|
|
|
|
import { BookmarkStart } from "./bookmark-start";
|
|
|
|
import { BookmarkEnd } from "./bookmark-end";
|
|
|
|
import { Comment } from "./comment";
|
|
|
|
import { CommentEnd } from "./comment-end";
|
|
|
|
|
|
|
|
export type ParagraphChild =
|
|
|
|
| Run
|
|
|
|
| Insert
|
|
|
|
| Delete
|
|
|
|
| BookmarkStart
|
|
|
|
| BookmarkEnd
|
|
|
|
| Comment
|
|
|
|
| CommentEnd;
|
|
|
|
|
2020-06-12 08:32:40 +03:00
|
|
|
export type AlignmentType =
|
|
|
|
| "center"
|
|
|
|
| "left"
|
|
|
|
| "right"
|
2020-06-15 12:41:29 +03:00
|
|
|
| "both"
|
2020-06-12 08:32:40 +03:00
|
|
|
| "justified"
|
|
|
|
| "distribute"
|
|
|
|
| "end";
|
2020-01-30 16:14:25 +02:00
|
|
|
|
|
|
|
export type SpecialIndentKind = "firstLine" | "hanging";
|
|
|
|
|
|
|
|
export type ParagraphProperty = {
|
|
|
|
align?: AlignmentType;
|
|
|
|
styleId?: string;
|
|
|
|
indent?: {
|
|
|
|
left: number;
|
|
|
|
specialIndentKind?: SpecialIndentKind;
|
|
|
|
specialIndentSize?: number;
|
|
|
|
};
|
|
|
|
numbering?: {
|
|
|
|
id: number;
|
|
|
|
level: number;
|
|
|
|
};
|
2020-10-14 04:16:13 +03:00
|
|
|
lineHeight?: number;
|
2020-06-08 07:41:13 +03:00
|
|
|
runProperty: RunProperty;
|
2020-01-30 16:14:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export class Paragraph {
|
2020-05-15 09:51:45 +03:00
|
|
|
hasNumberings = false;
|
2020-01-30 16:14:25 +02:00
|
|
|
children: ParagraphChild[] = [];
|
2020-06-08 07:41:13 +03:00
|
|
|
property: ParagraphProperty = {
|
|
|
|
runProperty: {},
|
|
|
|
};
|
2020-01-30 16:14:25 +02:00
|
|
|
|
|
|
|
addRun(run: Run) {
|
|
|
|
this.children.push(run);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
addInsert(ins: Insert) {
|
|
|
|
this.children.push(ins);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
addDelete(del: Delete) {
|
|
|
|
this.children.push(del);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-02-11 10:01:39 +02:00
|
|
|
addBookmarkStart(id: number, name: string) {
|
2020-01-30 16:14:25 +02:00
|
|
|
this.children.push(new BookmarkStart(id, name));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-02-11 10:01:39 +02:00
|
|
|
addBookmarkEnd(id: number) {
|
2020-01-30 16:14:25 +02:00
|
|
|
this.children.push(new BookmarkEnd(id));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
addCommentStart(comment: Comment) {
|
|
|
|
this.children.push(comment);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
addCommentEnd(end: CommentEnd) {
|
|
|
|
this.children.push(end);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
align(type: AlignmentType) {
|
|
|
|
this.property.align = type;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
style(id: string) {
|
|
|
|
this.property.styleId = id;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
indent(
|
|
|
|
left: number,
|
|
|
|
specialIndentKind?: SpecialIndentKind,
|
|
|
|
specialIndentSize?: number
|
|
|
|
) {
|
|
|
|
this.property.indent = { left, specialIndentKind, specialIndentSize };
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
numbering(id: number, level: number) {
|
2020-05-15 09:51:45 +03:00
|
|
|
this.hasNumberings = true;
|
2020-01-30 16:14:25 +02:00
|
|
|
this.property.numbering = { id, level };
|
|
|
|
return this;
|
|
|
|
}
|
2020-06-08 07:41:13 +03:00
|
|
|
|
2020-10-14 04:16:13 +03:00
|
|
|
lineHeight(lineHeight: number) {
|
|
|
|
this.property = { ...this.property, lineHeight };
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-06-08 07:41:13 +03:00
|
|
|
// run property
|
|
|
|
size(size: number) {
|
|
|
|
this.property.runProperty = { ...this.property.runProperty, size };
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bold() {
|
|
|
|
this.property.runProperty = { ...this.property.runProperty, bold: true };
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
italic() {
|
|
|
|
this.property.runProperty = { ...this.property.runProperty, italic: true };
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
fonts(fonts: RunFonts) {
|
|
|
|
this.property.runProperty = { ...this.property.runProperty, fonts };
|
|
|
|
return this;
|
|
|
|
}
|
2020-01-30 16:14:25 +02:00
|
|
|
}
|