2022-06-26 23:26:42 +01:00
|
|
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
2021-05-25 03:41:12 +03:00
|
|
|
|
|
|
|
// <xsd:simpleType name="ST_HdrFtr">
|
|
|
|
// <xsd:restriction base="xsd:string">
|
|
|
|
// <xsd:enumeration value="even"/>
|
|
|
|
// <xsd:enumeration value="default"/>
|
|
|
|
// <xsd:enumeration value="first"/>
|
|
|
|
// </xsd:restriction>
|
|
|
|
// </xsd:simpleType>
|
2023-12-22 10:25:00 +09:00
|
|
|
export const HeaderFooterReferenceType = {
|
|
|
|
DEFAULT: "default",
|
|
|
|
FIRST: "first",
|
|
|
|
EVEN: "even",
|
|
|
|
} as const;
|
2021-05-25 03:41:12 +03:00
|
|
|
|
|
|
|
// </xsd:complexType>
|
|
|
|
// <xsd:group name="EG_HdrFtrReferences">
|
|
|
|
// <xsd:choice>
|
|
|
|
// <xsd:element name="headerReference" type="CT_HdrFtrRef" minOccurs="0"/>
|
|
|
|
// <xsd:element name="footerReference" type="CT_HdrFtrRef" minOccurs="0"/>
|
|
|
|
// </xsd:choice>
|
|
|
|
// </xsd:group>
|
|
|
|
|
|
|
|
// <xsd:complexType name="CT_HdrFtrRef">
|
|
|
|
// <xsd:complexContent>
|
|
|
|
// <xsd:extension base="CT_Rel">
|
|
|
|
// <xsd:attribute name="type" type="ST_HdrFtr" use="required"/>
|
|
|
|
// </xsd:extension>
|
|
|
|
// </xsd:complexContent>
|
|
|
|
|
|
|
|
// <xsd:complexType name="CT_Rel">
|
|
|
|
// <xsd:attribute ref="r:id" use="required"/>
|
|
|
|
// </xsd:complexType>
|
|
|
|
|
|
|
|
export interface IHeaderFooterOptions {
|
2023-12-22 10:25:00 +09:00
|
|
|
readonly type?: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
|
2021-05-25 03:41:12 +03:00
|
|
|
readonly id?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
class FooterReferenceAttributes extends XmlAttributeComponent<{
|
2023-12-22 10:25:00 +09:00
|
|
|
readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType];
|
2021-05-25 03:41:12 +03:00
|
|
|
readonly id: string;
|
|
|
|
}> {
|
|
|
|
protected readonly xmlKeys = {
|
|
|
|
type: "w:type",
|
|
|
|
id: "r:id",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-12-22 10:25:00 +09:00
|
|
|
export const HeaderFooterType = {
|
|
|
|
HEADER: "w:headerReference",
|
|
|
|
FOOTER: "w:footerReference",
|
|
|
|
} as const;
|
|
|
|
|
2021-05-25 03:41:12 +03:00
|
|
|
export class HeaderFooterReference extends XmlComponent {
|
2023-12-22 10:25:00 +09:00
|
|
|
public constructor(type: (typeof HeaderFooterType)[keyof typeof HeaderFooterType], options: IHeaderFooterOptions) {
|
2021-05-25 03:41:12 +03:00
|
|
|
super(type);
|
|
|
|
|
|
|
|
this.root.push(
|
|
|
|
new FooterReferenceAttributes({
|
|
|
|
type: options.type || HeaderFooterReferenceType.DEFAULT,
|
|
|
|
id: `rId${options.id}`,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|