2017-09-19 15:42:40 +01:00
|
|
|
// http://officeopenxml.com/WPtext.php
|
2019-08-06 21:37:33 +01:00
|
|
|
import { XmlComponent } from "file/xml-components";
|
|
|
|
|
2019-11-21 01:02:46 +00:00
|
|
|
import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run";
|
2019-09-30 22:56:21 +01:00
|
|
|
import { FieldInstruction } from "file/table-of-contents/field-instruction";
|
2017-09-19 15:42:40 +01:00
|
|
|
import { Break } from "./break";
|
2018-09-03 10:54:53 -03:00
|
|
|
import { Begin, End, Separate } from "./field";
|
2019-08-09 11:56:22 +03:00
|
|
|
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
|
2020-07-11 17:01:32 +08:00
|
|
|
import { IRunPropertiesOptions, RunProperties } from "./properties";
|
2019-11-21 01:02:46 +00:00
|
|
|
import { Text } from "./run-components/text";
|
2017-09-19 15:42:40 +01:00
|
|
|
|
2020-07-11 17:01:32 +08:00
|
|
|
export interface IRunOptions extends IRunPropertiesOptions {
|
2020-08-01 17:58:16 +01:00
|
|
|
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
2020-12-23 23:31:28 +00:00
|
|
|
readonly break?: number;
|
2019-11-21 01:02:46 +00:00
|
|
|
readonly text?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum PageNumber {
|
|
|
|
CURRENT = "CURRENT",
|
|
|
|
TOTAL_PAGES = "TOTAL_PAGES",
|
|
|
|
TOTAL_PAGES_IN_SECTION = "TOTAL_PAGES_IN_SECTION",
|
2019-06-17 01:51:57 +01:00
|
|
|
}
|
2017-09-19 15:42:40 +01:00
|
|
|
|
|
|
|
export class Run extends XmlComponent {
|
2018-11-02 02:51:57 +00:00
|
|
|
protected readonly properties: RunProperties;
|
2017-09-19 15:42:40 +01:00
|
|
|
|
2019-06-17 01:51:57 +01:00
|
|
|
constructor(options: IRunOptions) {
|
2017-09-19 15:42:40 +01:00
|
|
|
super("w:r");
|
2020-07-11 17:01:32 +08:00
|
|
|
this.properties = new RunProperties(options);
|
2017-09-19 15:42:40 +01:00
|
|
|
this.root.push(this.properties);
|
|
|
|
|
2019-09-30 22:56:21 +01:00
|
|
|
if (options.children) {
|
|
|
|
for (const child of options.children) {
|
2019-11-21 01:02:46 +00:00
|
|
|
if (typeof child === "string") {
|
|
|
|
switch (child) {
|
|
|
|
case PageNumber.CURRENT:
|
|
|
|
this.root.push(new Begin());
|
|
|
|
this.root.push(new Page());
|
|
|
|
this.root.push(new Separate());
|
|
|
|
this.root.push(new End());
|
|
|
|
break;
|
|
|
|
case PageNumber.TOTAL_PAGES:
|
|
|
|
this.root.push(new Begin());
|
|
|
|
this.root.push(new NumberOfPages());
|
|
|
|
this.root.push(new Separate());
|
|
|
|
this.root.push(new End());
|
|
|
|
break;
|
|
|
|
case PageNumber.TOTAL_PAGES_IN_SECTION:
|
|
|
|
this.root.push(new Begin());
|
|
|
|
this.root.push(new NumberOfPagesSection());
|
|
|
|
this.root.push(new Separate());
|
|
|
|
this.root.push(new End());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.root.push(new Text(child));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-09-30 22:56:21 +01:00
|
|
|
this.root.push(child);
|
|
|
|
}
|
2019-11-21 01:02:46 +00:00
|
|
|
} else if (options.text) {
|
|
|
|
this.root.push(new Text(options.text));
|
2019-09-30 22:56:21 +01:00
|
|
|
}
|
2018-07-24 18:52:45 +03:00
|
|
|
|
2020-12-23 23:31:28 +00:00
|
|
|
if (options.break) {
|
|
|
|
for (let i = 0; i < options.break; i++) {
|
|
|
|
this.root.splice(1, 0, new Break());
|
|
|
|
}
|
|
|
|
}
|
2017-09-19 15:42:40 +01:00
|
|
|
}
|
|
|
|
}
|