Documentation and Refactoring (#3028)
* Documentation and Refactoring * Documentation and Refactoring * Fix lint issues * Convert components to Builder style --------- Co-authored-by: Dolan Miu <dmiu@bloomberg.net>
This commit is contained in:
@ -1,34 +1,35 @@
|
||||
// http://officeopenxml.com/drwPicFloating-position.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { Align } from "./align";
|
||||
import { createAlign } from "./align";
|
||||
import { IVerticalPositionOptions, VerticalPositionRelativeFrom } from "./floating-position";
|
||||
import { PositionOffset } from "./position-offset";
|
||||
import { createPositionOffset } from "./position-offset";
|
||||
|
||||
class VerticalPositionAttributes extends XmlAttributeComponent<{
|
||||
readonly relativeFrom: (typeof VerticalPositionRelativeFrom)[keyof typeof VerticalPositionRelativeFrom];
|
||||
}> {
|
||||
protected readonly xmlKeys = {
|
||||
relativeFrom: "relativeFrom",
|
||||
};
|
||||
}
|
||||
|
||||
export class VerticalPosition extends XmlComponent {
|
||||
public constructor(verticalPosition: IVerticalPositionOptions) {
|
||||
super("wp:positionV");
|
||||
|
||||
this.root.push(
|
||||
new VerticalPositionAttributes({
|
||||
relativeFrom: verticalPosition.relative || VerticalPositionRelativeFrom.PAGE,
|
||||
}),
|
||||
);
|
||||
|
||||
if (verticalPosition.align) {
|
||||
this.root.push(new Align(verticalPosition.align));
|
||||
} else if (verticalPosition.offset !== undefined) {
|
||||
this.root.push(new PositionOffset(verticalPosition.offset));
|
||||
} else {
|
||||
throw new Error("There is no configuration provided for floating position (Align or offset)");
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Vertical Positioning
|
||||
*
|
||||
* This simple type specifies the possible values for the base from which the relative vertical positioning of an object shall be calculated.
|
||||
*
|
||||
* Reference: https://www.datypic.com/sc/ooxml/e-wp_positionV-1.html
|
||||
*/
|
||||
export const createVerticalPosition = ({ relative, align, offset }: IVerticalPositionOptions): XmlComponent =>
|
||||
new BuilderElement<{
|
||||
/** Vertical Position Relative Base */
|
||||
readonly relativeFrom: (typeof VerticalPositionRelativeFrom)[keyof typeof VerticalPositionRelativeFrom];
|
||||
}>({
|
||||
name: "wp:positionV",
|
||||
attributes: {
|
||||
relativeFrom: { key: "relativeFrom", value: relative ?? VerticalPositionRelativeFrom.PAGE },
|
||||
},
|
||||
children: [
|
||||
(() => {
|
||||
if (align) {
|
||||
return createAlign(align);
|
||||
} else if (offset !== undefined) {
|
||||
return createPositionOffset(offset);
|
||||
} else {
|
||||
throw new Error("There is no configuration provided for floating position (Align or offset)");
|
||||
}
|
||||
})(),
|
||||
],
|
||||
});
|
||||
|
Reference in New Issue
Block a user