docx-rs/docx-wasm/js/level.ts

119 lines
2.3 KiB
TypeScript
Raw Normal View History

import { LevelJSON } from "./json";
import {
createDefaultParagraphProperty,
ParagraphProperty,
SpecialIndentKind,
} from "./paragraph";
import { RunFonts, RunProperty } from "./run";
2020-06-04 12:09:20 +03:00
export type LevelSuffixType = "nothing" | "tab" | "space";
export class Level {
id: number;
start: number;
format: string;
text: string;
jc: string;
paragraphProperty: ParagraphProperty = createDefaultParagraphProperty();
runProperty: RunProperty = {};
2020-06-04 12:09:20 +03:00
levelSuffix: LevelSuffixType;
constructor(
id: number,
start: number,
format: string,
text: string,
jc: string
) {
this.id = id;
this.start = start;
this.format = format;
this.text = text;
this.jc = jc;
2020-06-04 12:09:20 +03:00
this.levelSuffix = "tab";
}
indent(
left: number,
specialIndentKind?: SpecialIndentKind,
specialIndentSize?: number
) {
this.paragraphProperty.indent = {
left,
specialIndentKind,
specialIndentSize,
};
return this;
}
2020-06-04 12:09:20 +03:00
suffix(s: LevelSuffixType) {
this.levelSuffix = s;
return this;
}
size(size: number) {
this.runProperty = { ...this.runProperty, size };
return this;
}
color(color: string) {
this.runProperty = { ...this.runProperty, color };
return this;
}
highlight(color: string) {
this.runProperty = { ...this.runProperty, highlight: color };
return this;
}
bold() {
this.runProperty = { ...this.runProperty, bold: true };
return this;
}
italic() {
this.runProperty = { ...this.runProperty, italic: true };
return this;
}
underline(type: string) {
this.runProperty = { ...this.runProperty, underline: type };
return this;
}
vanish() {
this.runProperty = { ...this.runProperty, vanish: true };
return this;
}
fonts(fonts: RunFonts) {
this.runProperty = { ...this.runProperty, fonts };
return this;
}
spacing(spacing: number) {
this.runProperty = { ...this.runProperty, spacing };
return this;
}
}
export class LevelOverride {
level: number;
startOverride: number | null = null;
levelOverride: LevelJSON | null = null;
constructor(level: number) {
this.level = level;
}
overrideStart(start: number) {
this.startOverride = start;
return this;
}
overrideLevel(level: LevelJSON) {
this.levelOverride = level;
return this;
}
}