2022-12-29 09:57:15 +00:00
|
|
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
2024-10-21 03:57:15 +01:00
|
|
|
import { PositiveUniversalMeasure, decimalNumber, twipsMeasureValue } from "@util/values";
|
2022-06-26 23:26:42 +01:00
|
|
|
|
2021-09-18 22:58:19 +10:00
|
|
|
import { Column } from "./column";
|
2021-05-25 03:41:12 +03:00
|
|
|
|
|
|
|
// <xsd:complexType name="CT_Columns">
|
|
|
|
// <xsd:sequence minOccurs="0">
|
|
|
|
// <xsd:element name="col" type="CT_Column" maxOccurs="45"/>
|
|
|
|
// </xsd:sequence>
|
|
|
|
// <xsd:attribute name="equalWidth" type="s:ST_OnOff" use="optional"/>
|
|
|
|
// <xsd:attribute name="space" type="s:ST_TwipsMeasure" use="optional" default="720"/>
|
|
|
|
// <xsd:attribute name="num" type="ST_DecimalNumber" use="optional" default="1"/>
|
|
|
|
// <xsd:attribute name="sep" type="s:ST_OnOff" use="optional"/>
|
|
|
|
// </xsd:complexType>
|
2022-12-29 09:57:15 +00:00
|
|
|
export type IColumnsAttributes = {
|
|
|
|
readonly space?: number | PositiveUniversalMeasure;
|
2021-05-25 03:41:12 +03:00
|
|
|
readonly count?: number;
|
|
|
|
readonly separate?: boolean;
|
|
|
|
readonly equalWidth?: boolean;
|
2022-09-15 20:00:50 +01:00
|
|
|
readonly children?: readonly Column[];
|
2022-12-29 09:57:15 +00:00
|
|
|
};
|
2021-05-25 03:41:12 +03:00
|
|
|
|
|
|
|
export class Columns extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor({ space, count, separate, equalWidth, children }: IColumnsAttributes) {
|
2021-05-25 03:41:12 +03:00
|
|
|
super("w:cols");
|
|
|
|
this.root.push(
|
2022-12-29 09:57:15 +00:00
|
|
|
new NextAttributeComponent<Omit<IColumnsAttributes, "children">>({
|
|
|
|
space: { key: "w:space", value: space === undefined ? undefined : twipsMeasureValue(space) },
|
|
|
|
count: { key: "w:num", value: count === undefined ? undefined : decimalNumber(count) },
|
|
|
|
separate: { key: "w:sep", value: separate },
|
|
|
|
equalWidth: { key: "w:equalWidth", value: equalWidth },
|
2021-05-25 03:41:12 +03:00
|
|
|
}),
|
|
|
|
);
|
2021-09-18 22:58:19 +10:00
|
|
|
|
|
|
|
if (!equalWidth && children) {
|
|
|
|
children.forEach((column) => this.addChildElement(column));
|
|
|
|
}
|
2021-05-25 03:41:12 +03:00
|
|
|
}
|
|
|
|
}
|