2017-09-19 15:42:40 +01:00
|
|
|
// http://officeopenxml.com/WPtext.php
|
2022-06-26 23:26:42 +01:00
|
|
|
import { FootnoteReferenceRun } from "@file/footnotes/footnote/run/reference-run";
|
|
|
|
import { FieldInstruction } from "@file/table-of-contents/field-instruction";
|
2024-10-21 03:57:15 +01:00
|
|
|
import { XmlComponent } from "@file/xml-components";
|
2022-06-15 00:07:12 +01:00
|
|
|
|
2017-09-19 15:42:40 +01:00
|
|
|
import { Break } from "./break";
|
2022-12-24 19:32:44 +00:00
|
|
|
import {
|
|
|
|
AnnotationReference,
|
|
|
|
CarriageReturn,
|
|
|
|
ContinuationSeparator,
|
|
|
|
DayLong,
|
|
|
|
DayShort,
|
|
|
|
EndnoteReference,
|
|
|
|
FootnoteReferenceElement,
|
|
|
|
LastRenderedPageBreak,
|
|
|
|
MonthLong,
|
|
|
|
MonthShort,
|
|
|
|
NoBreakHyphen,
|
|
|
|
PageNumberElement,
|
|
|
|
Separator,
|
|
|
|
SoftHyphen,
|
|
|
|
Tab,
|
|
|
|
YearLong,
|
|
|
|
YearShort,
|
|
|
|
} from "./empty-children";
|
2024-10-21 03:57:15 +01:00
|
|
|
import { Begin, End, Separate } from "./field";
|
|
|
|
import { CurrentSection, NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
|
2022-12-24 19:32:44 +00:00
|
|
|
import { PositionalTab } from "./positional-tab";
|
2024-10-21 03:57:15 +01:00
|
|
|
import { IRunPropertiesOptions, RunProperties } from "./properties";
|
|
|
|
import { Text } from "./run-components/text";
|
2017-09-19 15:42:40 +01:00
|
|
|
|
2024-10-21 03:57:15 +01:00
|
|
|
export type IRunOptions = {
|
2022-12-24 19:32:44 +00:00
|
|
|
// <xsd:choice>
|
|
|
|
// <xsd:element name="br" type="CT_Br" />
|
|
|
|
// <xsd:element name="t" type="CT_Text" />
|
|
|
|
// <xsd:element name="contentPart" type="CT_Rel" />
|
|
|
|
// <xsd:element name="delText" type="CT_Text" />
|
|
|
|
// <xsd:element name="instrText" type="CT_Text" />
|
|
|
|
// <xsd:element name="delInstrText" type="CT_Text" />
|
|
|
|
// <xsd:element name="noBreakHyphen" type="CT_Empty" />
|
|
|
|
// <xsd:element name="softHyphen" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="dayShort" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="monthShort" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="yearShort" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="dayLong" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="monthLong" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="yearLong" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="annotationRef" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="footnoteRef" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="endnoteRef" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="separator" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="continuationSeparator" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="sym" type="CT_Sym" minOccurs="0" />
|
|
|
|
// <xsd:element name="pgNum" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="cr" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="tab" type="CT_Empty" minOccurs="0" />
|
|
|
|
// <xsd:element name="object" type="CT_Object" />
|
|
|
|
// <xsd:element name="pict" type="CT_Picture" />
|
|
|
|
// <xsd:element name="fldChar" type="CT_FldChar" />
|
|
|
|
// <xsd:element name="ruby" type="CT_Ruby" />
|
|
|
|
// <xsd:element name="footnoteReference" type="CT_FtnEdnRef" />
|
|
|
|
// <xsd:element name="endnoteReference" type="CT_FtnEdnRef" />
|
|
|
|
// <xsd:element name="commentReference" type="CT_Markup" />
|
|
|
|
// <xsd:element name="drawing" type="CT_Drawing" />
|
|
|
|
// <xsd:element name="ptab" type="CT_PTab" minOccurs="0" />
|
|
|
|
// <xsd:element name="lastRenderedPageBreak" type="CT_Empty" minOccurs="0" maxOccurs="1" />
|
|
|
|
// </xsd:choice>
|
|
|
|
readonly children?: readonly (
|
|
|
|
| Begin
|
|
|
|
| FieldInstruction
|
|
|
|
| Separate
|
|
|
|
| End
|
2023-12-22 10:25:00 +09:00
|
|
|
| (typeof PageNumber)[keyof typeof PageNumber]
|
2022-12-24 19:32:44 +00:00
|
|
|
| FootnoteReferenceRun
|
|
|
|
| Break
|
|
|
|
| AnnotationReference
|
|
|
|
| CarriageReturn
|
|
|
|
| ContinuationSeparator
|
|
|
|
| DayLong
|
|
|
|
| DayShort
|
|
|
|
| EndnoteReference
|
|
|
|
| FootnoteReferenceElement
|
|
|
|
| LastRenderedPageBreak
|
|
|
|
| MonthLong
|
|
|
|
| MonthShort
|
|
|
|
| NoBreakHyphen
|
|
|
|
| PageNumberElement
|
|
|
|
| Separator
|
|
|
|
| SoftHyphen
|
|
|
|
| Tab
|
|
|
|
| YearLong
|
|
|
|
| YearShort
|
|
|
|
| PositionalTab
|
|
|
|
| string
|
|
|
|
)[];
|
2020-12-23 23:31:28 +00:00
|
|
|
readonly break?: number;
|
2019-11-21 01:02:46 +00:00
|
|
|
readonly text?: string;
|
2024-10-21 03:57:15 +01:00
|
|
|
} & IRunPropertiesOptions;
|
2019-11-21 01:02:46 +00:00
|
|
|
|
2023-12-22 10:25:00 +09:00
|
|
|
export const PageNumber = {
|
|
|
|
CURRENT: "CURRENT",
|
|
|
|
TOTAL_PAGES: "TOTAL_PAGES",
|
|
|
|
TOTAL_PAGES_IN_SECTION: "TOTAL_PAGES_IN_SECTION",
|
2023-12-25 22:29:32 +00:00
|
|
|
CURRENT_SECTION: "SECTION",
|
2023-12-22 10:25:00 +09:00
|
|
|
} as const;
|
|
|
|
|
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
|
|
|
|
2022-08-31 07:52:27 +01:00
|
|
|
public 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);
|
|
|
|
|
2021-05-22 05:00:30 +03:00
|
|
|
if (options.break) {
|
|
|
|
for (let i = 0; i < options.break; i++) {
|
|
|
|
this.root.push(new Break());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2023-12-25 22:29:32 +00:00
|
|
|
case PageNumber.CURRENT_SECTION:
|
|
|
|
this.root.push(new Begin());
|
2023-12-29 23:52:43 +00:00
|
|
|
this.root.push(new CurrentSection());
|
2023-12-25 22:29:32 +00:00
|
|
|
this.root.push(new Separate());
|
|
|
|
this.root.push(new End());
|
|
|
|
break;
|
2019-11-21 01:02:46 +00:00
|
|
|
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
|
|
|
}
|
2017-09-19 15:42:40 +01:00
|
|
|
}
|
|
|
|
}
|