/
table-float-properties.ts
209 lines (192 loc) · 9.76 KB
/
table-float-properties.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import { NextAttributeComponent, StringEnumValueElement, XmlComponent } from "@file/xml-components";
import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values";
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;
// <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;
export type ITableFloatOptions = {
/* cSpell:disable */
/**
* 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.
*/
/* cSpell:enable */
readonly horizontalAnchor?: (typeof TableAnchorType)[keyof typeof TableAnchorType];
/**
* 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.
*/
readonly absoluteHorizontalPosition?: number | UniversalMeasure;
/**
* 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];
/**
* 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];
/**
* 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.
*/
readonly absoluteVerticalPosition?: number | UniversalMeasure;
/**
* 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];
/**
* Specifies the minimum distance to be maintained between the table and the top of text in the paragraph
* below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/
readonly bottomFromText?: number | PositiveUniversalMeasure;
/**
* Specifies the minimum distance to be maintained between the table and the bottom edge of text in the paragraph
* above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/
readonly topFromText?: number | PositiveUniversalMeasure;
/**
* Specifies the minimum distance to be maintained between the table and the edge of text in the paragraph
* to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/
readonly leftFromText?: number | PositiveUniversalMeasure;
/**
* Specifies the minimum distance to be maintained between the table and the edge of text in the paragraph
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/
readonly rightFromText?: number | PositiveUniversalMeasure;
readonly overlap?: (typeof OverlapType)[keyof typeof OverlapType];
};
// <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>
export class TableFloatProperties extends XmlComponent {
public constructor({
horizontalAnchor,
verticalAnchor,
absoluteHorizontalPosition,
relativeHorizontalPosition,
absoluteVerticalPosition,
relativeVerticalPosition,
bottomFromText,
topFromText,
leftFromText,
rightFromText,
overlap,
}: ITableFloatOptions) {
super("w:tblpPr");
this.root.push(
new NextAttributeComponent<Omit<ITableFloatOptions, "overlap">>({
leftFromText: {
key: "w:leftFromText",
value: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText),
},
rightFromText: {
key: "w:rightFromText",
value: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText),
},
topFromText: {
key: "w:topFromText",
value: topFromText === undefined ? undefined : twipsMeasureValue(topFromText),
},
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,
},
}),
);
if (overlap) {
// <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));
}
}
}