* fix: separate vertical alignment enums for table and section properties - Introduced `VerticalAlignTable` for table-cell vertical alignment with valid values: `top`, `center`, and `bottom`. - Added `VerticalAlignSection` for section properties, extending `VerticalAlignTable` with an additional value `both`. - Marked the original `VerticalAlign` as deprecated for backward compatibility, directing users to the new enums. - Updated type definitions for better clarity on valid vertical alignments. * refactor: update vertical alignment imports and types for section and table properties - Renamed `VerticalAlign` to `VerticalAlignSection` in section properties and `VerticalAlignTable` in table-cell properties for clarity. - Updated type definitions to reflect the new enum names, ensuring better organization and understanding of vertical alignment options. - Adjusted related test cases to utilize the new imports and types. * refactor: update demos to use new enums for table and section properties for vertical alignment
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
|
|
|
// <xsd:complexType name="CT_VerticalJc">
|
|
// <xsd:attribute name="val" type="ST_VerticalJc" use="required"/>
|
|
// </xsd:complexType>
|
|
|
|
// <xsd:simpleType name="ST_VerticalJc">
|
|
// <xsd:restriction base="xsd:string">
|
|
// <xsd:enumeration value="both"/>
|
|
// <xsd:enumeration value="top"/>
|
|
// <xsd:enumeration value="center"/>
|
|
// <xsd:enumeration value="bottom"/>
|
|
// </xsd:restriction>
|
|
// </xsd:simpleType>
|
|
|
|
/**
|
|
* Enumeration for table-cell vertical alignment. Only `top`, `center`, `bottom`
|
|
* are valid according to ECMA-376 (§17.18.87 ST_VerticalJc within <w:tcPr>).
|
|
*/
|
|
export const VerticalAlignTable = {
|
|
TOP: "top",
|
|
CENTER: "center",
|
|
BOTTOM: "bottom",
|
|
} as const;
|
|
|
|
/**
|
|
* Enumeration for section (<w:sectPr>) vertical alignment. Adds `both` on top of
|
|
* the table-cell set (§17.18.87 ST_VerticalJc within <w:sectPr>).
|
|
*/
|
|
export const VerticalAlignSection = {
|
|
...VerticalAlignTable,
|
|
BOTH: "both",
|
|
} as const;
|
|
|
|
/**
|
|
* @deprecated Use {@link VerticalAlignTable} for table cells or
|
|
* {@link VerticalAlignSection} for section properties. This alias remains for
|
|
* backward-compatibility and will be removed in the next major release.
|
|
*/
|
|
export const VerticalAlign = VerticalAlignSection;
|
|
|
|
export type TableVerticalAlign = (typeof VerticalAlignTable)[keyof typeof VerticalAlignTable];
|
|
|
|
export type SectionVerticalAlign = (typeof VerticalAlignSection)[keyof typeof VerticalAlignSection];
|
|
|
|
export class VerticalAlignAttributes extends XmlAttributeComponent<{
|
|
readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign];
|
|
}> {
|
|
protected readonly xmlKeys = {
|
|
verticalAlign: "w:val",
|
|
};
|
|
}
|
|
|
|
export class VerticalAlignElement extends XmlComponent {
|
|
public constructor(value: (typeof VerticalAlign)[keyof typeof VerticalAlign]) {
|
|
super("w:vAlign");
|
|
this.root.push(new VerticalAlignAttributes({ verticalAlign: value }));
|
|
}
|
|
}
|