Files
docx-js/src/file/table/table-properties/table-float-properties.ts

210 lines
9.8 KiB
TypeScript
Raw Normal View History

2023-02-04 22:48:33 +00:00
import { NextAttributeComponent, StringEnumValueElement, XmlComponent } from "@file/xml-components";
2022-12-29 12:12:53 +00:00
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
2018-10-23 09:08:43 -02:00
export const TableAnchorType = {
MARGIN: "margin",
PAGE: "page",
TEXT: "text",
} as const;
export const RelativeHorizontalPosition = {
CENTER: "center",
INSIDE: "inside",
LEFT: "left",
OUTSIDE: "outside",
RIGHT: "right",
} as const;
export const RelativeVerticalPosition = {
CENTER: "center",
INSIDE: "inside",
BOTTOM: "bottom",
OUTSIDE: "outside",
INLINE: "inline",
TOP: "top",
} as const;
2018-10-23 09:08:43 -02:00
2022-11-03 00:30:16 +00:00
// <xsd:simpleType name="ST_TblOverlap">
// <xsd:restriction base="xsd:string">
// <xsd:enumeration value="never"/>
// <xsd:enumeration value="overlap"/>
// </xsd:restriction>
// </xsd:simpleType>
export const OverlapType = {
NEVER: "never",
OVERLAP: "overlap",
} as const;
2022-11-03 00:30:16 +00:00
2023-02-04 22:11:47 +00:00
export type ITableFloatOptions = {
2022-07-05 05:06:32 +01:00
/* cSpell:disable */
2018-10-23 09:08:43 -02:00
/**
* Specifies the horizontal anchor or the base object from which the horizontal positioning in the
* tblpX or tblpXSpec attribute should be determined.
* margin - relative to the vertical edge of the text margin before any text runs (left edge for left-to-right paragraphs)
* page - relative to the vertical edge of the page before any text runs (left edge for left-to-right paragraphs)
* text - relative to the vertical edge of the text margin for the column in which the anchor paragraph is located
* If omitted, the value is assumed to be page.
*/
2022-07-05 05:06:32 +01:00
/* cSpell:enable */
readonly horizontalAnchor?: (typeof TableAnchorType)[keyof typeof TableAnchorType];
2018-10-23 09:08:43 -02:00
/**
* Specifies an absolute horizontal position for the table, relative to the horizontalAnchor.
* The value is in twentieths of a point. Note that the value can be negative, in which case the
* table is positioned before the anchor object in the direction of horizontal text flow.
* If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosition attribute is ignored.
* If the attribute is omitted, the value is assumed to be zero.
*/
2022-12-29 12:12:53 +00:00
readonly absoluteHorizontalPosition?: number | UniversalMeasure;
2018-10-23 09:08:43 -02:00
/**
* Specifies a relative horizontal position for the table, relative to the horizontalAnchor attribute.
* This will supersede the absoluteHorizontalPosition attribute.
* Possible values are:
* center - the table should be horizontally centered with respect to the anchor
* inside - the table should be inside of the anchor
* left - the table should be left aligned with respect to the anchor
* outside - the table should be outside of the anchor
* right - the table should be right aligned with respect to the anchor
*/
readonly relativeHorizontalPosition?: (typeof RelativeHorizontalPosition)[keyof typeof RelativeHorizontalPosition];
2018-10-23 09:08:43 -02:00
/**
* Specifies the vertical anchor or the base object from which the vertical positioning
* in the absoluteVerticalPosition attribute should be determined. Possible values are:
* margin - relative to the horizontal edge of the text margin before any text runs (top edge for top-to-bottom paragraphs)
* page - relative to the horizontal edge of the page before any text runs (top edge for top-to-bottom paragraphs)
* text - relative to the horizontal edge of the text margin for the column in which the anchor paragraph is located
* If omitted, the value is assumed to be page.
*/
readonly verticalAnchor?: (typeof TableAnchorType)[keyof typeof TableAnchorType];
2018-10-23 09:08:43 -02:00
/**
* Specifies an absolute vertical position for the table, relative to the verticalAnchor anchor.
* The value is in twentieths of a point. Note that the value can be negative, in which case the table is
* positioned before the anchor object in the direction of vertical text flow.
* If relativeVerticalPosition is also specified, then the absoluteVerticalPosition attribute is ignored.
* If the attribute is omitted, the value is assumed to be zero.
*/
2022-12-29 12:12:53 +00:00
readonly absoluteVerticalPosition?: number | UniversalMeasure;
2018-10-23 09:08:43 -02:00
/**
* Specifies a relative vertical position for the table, relative to the verticalAnchor attribute.
* This will supersede the absoluteVerticalPosition attribute. Possible values are:
* center - the table should be vertically centered with respect to the anchor
* inside - the table should be vertically aligned to the edge of the anchor and inside the anchor
* bottom - the table should be vertically aligned to the bottom edge of the anchor
* outside - the table should be vertically aligned to the edge of the anchor and outside the anchor
* inline - the table should be vertically aligned in line with the surrounding text (so as to not allow any text wrapping around it)
* top - the table should be vertically aligned to the top edge of the anchor
*/
readonly relativeVerticalPosition?: (typeof RelativeVerticalPosition)[keyof typeof RelativeVerticalPosition];
2018-10-23 09:08:43 -02:00
/**
2022-07-04 14:51:36 +01:00
* Specifies the minimum distance to be maintained between the table and the top of text in the paragraph
2018-10-23 09:08:43 -02:00
* below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/
2022-12-29 12:12:53 +00:00
readonly bottomFromText?: number | PositiveUniversalMeasure;
2018-10-23 09:08:43 -02:00
/**
2022-07-04 14:51:36 +01:00
* Specifies the minimum distance to be maintained between the table and the bottom edge of text in the paragraph
2018-10-23 09:08:43 -02:00
* above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/
2022-12-29 12:12:53 +00:00
readonly topFromText?: number | PositiveUniversalMeasure;
2018-10-23 09:08:43 -02:00
/**
2022-07-04 14:51:36 +01:00
* Specifies the minimum distance to be maintained between the table and the edge of text in the paragraph
2018-10-23 09:08:43 -02:00
* to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/
2022-12-29 12:12:53 +00:00
readonly leftFromText?: number | PositiveUniversalMeasure;
2018-10-23 09:08:43 -02:00
/**
2022-07-04 14:51:36 +01:00
* Specifies the minimum distance to be maintained between the table and the edge of text in the paragraph
2018-10-23 09:08:43 -02:00
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/
2022-12-29 12:12:53 +00:00
readonly rightFromText?: number | PositiveUniversalMeasure;
readonly overlap?: (typeof OverlapType)[keyof typeof OverlapType];
2023-02-04 22:11:47 +00:00
};
2018-10-23 09:08:43 -02:00
// <xsd:complexType name="CT_TblPPr">
// <xsd:attribute name="leftFromText" type="s:ST_TwipsMeasure"/>
// <xsd:attribute name="rightFromText" type="s:ST_TwipsMeasure"/>
// <xsd:attribute name="topFromText" type="s:ST_TwipsMeasure"/>
// <xsd:attribute name="bottomFromText" type="s:ST_TwipsMeasure"/>
// <xsd:attribute name="vertAnchor" type="ST_VAnchor"/>
// <xsd:attribute name="horzAnchor" type="ST_HAnchor"/>
// <xsd:attribute name="tblpXSpec" type="s:ST_XAlign"/>
// <xsd:attribute name="tblpX" type="ST_SignedTwipsMeasure"/>
// <xsd:attribute name="tblpYSpec" type="s:ST_YAlign"/>
// <xsd:attribute name="tblpY" type="ST_SignedTwipsMeasure"/>
// </xsd:complexType>
2018-10-23 09:08:43 -02:00
export class TableFloatProperties extends XmlComponent {
2022-08-31 07:52:27 +01:00
public constructor({
2023-02-04 22:11:47 +00:00
horizontalAnchor,
verticalAnchor,
absoluteHorizontalPosition,
2023-02-04 22:11:47 +00:00
relativeHorizontalPosition,
absoluteVerticalPosition,
2023-02-04 22:11:47 +00:00
relativeVerticalPosition,
bottomFromText,
topFromText,
leftFromText,
rightFromText,
overlap,
}: ITableFloatOptions) {
2018-10-23 09:08:43 -02:00
super("w:tblpPr");
this.root.push(
2023-02-04 22:11:47 +00:00
new NextAttributeComponent<Omit<ITableFloatOptions, "overlap">>({
leftFromText: {
key: "w:leftFromText",
value: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText),
},
2023-02-04 22:11:47 +00:00
rightFromText: {
key: "w:rightFromText",
value: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText),
},
topFromText: {
key: "w:topFromText",
value: topFromText === undefined ? undefined : twipsMeasureValue(topFromText),
},
2023-02-04 22:11:47 +00:00
bottomFromText: {
key: "w:bottomFromText",
value: bottomFromText === undefined ? undefined : twipsMeasureValue(bottomFromText),
},
absoluteHorizontalPosition: {
key: "w:tblpX",
value: absoluteHorizontalPosition === undefined ? undefined : signedTwipsMeasureValue(absoluteHorizontalPosition),
},
absoluteVerticalPosition: {
key: "w:tblpY",
value: absoluteVerticalPosition === undefined ? undefined : signedTwipsMeasureValue(absoluteVerticalPosition),
},
horizontalAnchor: {
key: "w:horzAnchor",
value: horizontalAnchor === undefined ? undefined : horizontalAnchor,
},
relativeHorizontalPosition: {
key: "w:tblpXSpec",
value: relativeHorizontalPosition,
},
relativeVerticalPosition: {
key: "w:tblpYSpec",
value: relativeVerticalPosition,
},
verticalAnchor: {
key: "w:vertAnchor",
value: verticalAnchor,
},
}),
);
2019-11-24 03:22:50 +00:00
2023-02-04 22:11:47 +00:00
if (overlap) {
2022-11-03 00:30:16 +00:00
// <xsd:complexType name="CT_TblOverlap">
// <xsd:attribute name="val" type="ST_TblOverlap" use="required"/>
// </xsd:complexType>
this.root.push(new StringEnumValueElement<(typeof OverlapType)[keyof typeof OverlapType]>("w:tblOverlap", overlap));
2019-11-24 03:22:50 +00:00
}
2018-10-23 09:08:43 -02:00
}
}