2022-12-26 15:12:44 +00:00
|
|
|
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_docPr_topic_ID0ES32OB.html
|
|
|
|
import { ConcreteHyperlink } from "@file/paragraph";
|
2024-10-21 03:57:15 +01:00
|
|
|
import { IContext, IXmlableObject, NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
2023-04-28 13:17:02 +03:00
|
|
|
import { docPropertiesUniqueNumericIdGen } from "@util/convenience-functions";
|
2022-10-26 23:09:36 +01:00
|
|
|
|
2022-12-26 15:12:44 +00:00
|
|
|
import { createHyperlinkClick } from "./doc-properties-children";
|
|
|
|
|
|
|
|
// <complexType name="CT_NonVisualDrawingProps">
|
|
|
|
// <sequence>
|
|
|
|
// <element name="hlinkClick" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
|
|
|
// <element name="hlinkHover" type="CT_Hyperlink" minOccurs="0" maxOccurs="1" />
|
|
|
|
// <element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1" />
|
|
|
|
// </sequence>
|
|
|
|
// <attribute name="id" type="ST_DrawingElementId" use="required" />
|
|
|
|
// <attribute name="name" type="xsd:string" use="required" />
|
|
|
|
// <attribute name="descr" type="xsd:string" use="optional" default="" />
|
|
|
|
// <attribute name="hidden" type="xsd:boolean" use="optional" default="false" />
|
|
|
|
// </complexType>
|
2022-10-26 23:09:36 +01:00
|
|
|
|
2024-10-21 03:57:15 +01:00
|
|
|
export type DocPropertiesOptions = {
|
2022-10-26 23:09:36 +01:00
|
|
|
readonly name: string;
|
2025-05-03 01:55:22 +07:00
|
|
|
readonly description?: string;
|
|
|
|
readonly title?: string;
|
2024-10-21 03:57:15 +01:00
|
|
|
};
|
2018-01-16 01:31:47 +00:00
|
|
|
|
|
|
|
export class DocProperties extends XmlComponent {
|
2023-04-28 13:17:02 +03:00
|
|
|
private readonly docPropertiesUniqueNumericId = docPropertiesUniqueNumericIdGen();
|
|
|
|
|
2022-10-26 23:09:36 +01:00
|
|
|
public constructor({ name, description, title }: DocPropertiesOptions = { name: "", description: "", title: "" }) {
|
2018-01-16 01:31:47 +00:00
|
|
|
super("wp:docPr");
|
|
|
|
|
2025-05-03 01:55:22 +07:00
|
|
|
const attributes: Record<string, { readonly key: string; readonly value: string | number }> = {
|
|
|
|
id: {
|
|
|
|
key: "id",
|
|
|
|
value: this.docPropertiesUniqueNumericId(),
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
key: "name",
|
|
|
|
value: name,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (description !== null && description !== undefined) {
|
|
|
|
attributes.description = {
|
|
|
|
key: "descr",
|
|
|
|
value: description,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (title !== null && title !== undefined) {
|
|
|
|
attributes.title = {
|
|
|
|
key: "title",
|
|
|
|
value: title,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.root.push(new NextAttributeComponent(attributes));
|
2018-01-16 01:31:47 +00:00
|
|
|
}
|
2022-12-26 15:12:44 +00:00
|
|
|
|
|
|
|
public prepForXml(context: IContext): IXmlableObject | undefined {
|
|
|
|
for (let i = context.stack.length - 1; i >= 0; i--) {
|
|
|
|
const element = context.stack[i];
|
|
|
|
if (!(element instanceof ConcreteHyperlink)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.root.push(createHyperlinkClick(element.linkId, true));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.prepForXml(context);
|
|
|
|
}
|
2018-01-16 01:31:47 +00:00
|
|
|
}
|