progress on clean up file/paragraph

This commit is contained in:
Tom Hunkapiller
2021-05-24 17:12:10 +03:00
parent 4466145d00
commit 7bfe8f26f0
8 changed files with 80 additions and 396 deletions

View File

@ -1,29 +1,57 @@
// http://officeopenxml.com/WPindentation.php
import { signedTwipsMeasureValue, twipsMeasureValue } from "file/values";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export interface IIndentAttributesProperties {
readonly left?: number;
readonly hanging?: number;
readonly firstLine?: number;
readonly start?: number;
readonly end?: number;
readonly right?: number;
readonly start?: number | string;
readonly end?: number | string;
readonly left?: number | string;
readonly right?: number | string;
readonly hanging?: number | string;
readonly firstLine?: number | string;
}
// <xsd:complexType name="CT_Ind">
// <xsd:attribute name="start" type="ST_SignedTwipsMeasure" use="optional"/>
// <xsd:attribute name="startChars" type="ST_DecimalNumber" use="optional"/>
// <xsd:attribute name="end" type="ST_SignedTwipsMeasure" use="optional"/>
// <xsd:attribute name="endChars" type="ST_DecimalNumber" use="optional"/>
// <xsd:attribute name="left" type="ST_SignedTwipsMeasure" use="optional"/>
// <xsd:attribute name="leftChars" type="ST_DecimalNumber" use="optional"/>
// <xsd:attribute name="right" type="ST_SignedTwipsMeasure" use="optional"/>
// <xsd:attribute name="rightChars" type="ST_DecimalNumber" use="optional"/>
// <xsd:attribute name="hanging" type="s:ST_TwipsMeasure" use="optional"/>
// <xsd:attribute name="hangingChars" type="ST_DecimalNumber" use="optional"/>
// <xsd:attribute name="firstLine" type="s:ST_TwipsMeasure" use="optional"/>
// <xsd:attribute name="firstLineChars" type="ST_DecimalNumber" use="optional"/>
// </xsd:complexType>
class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties> {
protected readonly xmlKeys = {
left: "w:left",
hanging: "w:hanging",
firstLine: "w:firstLine",
start: "w:start",
end: "w:end",
right: "w:end", // alias
left: "w:left",
right: "w:right",
hanging: "w:hanging",
firstLine: "w:firstLine",
};
}
// <xsd:complexType name="CT_PPrBase">
// <xsd:sequence>
// ...
// <xsd:element name="ind" type="CT_Ind" minOccurs="0"/>
export class Indent extends XmlComponent {
constructor(attrs: IIndentAttributesProperties) {
constructor({ start, end, left, right, hanging, firstLine }: IIndentAttributesProperties) {
super("w:ind");
this.root.push(new IndentAttributes(attrs));
this.root.push(
new IndentAttributes({
start: start === undefined ? undefined : signedTwipsMeasureValue(start),
end: end === undefined ? undefined : signedTwipsMeasureValue(end),
left: left === undefined ? undefined : signedTwipsMeasureValue(left),
right: right === undefined ? undefined : signedTwipsMeasureValue(right),
hanging: hanging === undefined ? undefined : twipsMeasureValue(hanging),
firstLine: firstLine === undefined ? undefined : twipsMeasureValue(firstLine),
}),
);
}
}