2020-12-24 04:26:45 +00:00
|
|
|
// http://officeopenxml.com/WPnumbering-numFmt.php
|
2021-05-24 21:04:38 +03:00
|
|
|
import { decimalNumber } from "file/values";
|
|
|
|
import { Attributes, NumberValueElement, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
2020-07-11 17:01:32 +08:00
|
|
|
import { AlignmentType } from "../paragraph/formatting";
|
|
|
|
import { IParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
|
|
|
|
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
|
2016-05-19 22:42:23 +01:00
|
|
|
|
2020-12-24 04:26:45 +00:00
|
|
|
export enum LevelFormat {
|
|
|
|
BULLET = "bullet",
|
|
|
|
CARDINAL_TEXT = "cardinalText",
|
|
|
|
CHICAGO = "chicago",
|
|
|
|
DECIMAL = "decimal",
|
|
|
|
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
|
|
|
|
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
|
|
|
|
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
|
|
|
|
DECIMAL_ZERO = "decimalZero",
|
|
|
|
LOWER_LETTER = "lowerLetter",
|
|
|
|
LOWER_ROMAN = "lowerRoman",
|
|
|
|
NONE = "none",
|
|
|
|
ORDINAL_TEXT = "ordinalText",
|
|
|
|
UPPER_LETTER = "upperLetter",
|
|
|
|
UPPER_ROMAN = "upperRoman",
|
|
|
|
}
|
|
|
|
|
2021-03-15 00:11:39 +00:00
|
|
|
class LevelAttributes extends XmlAttributeComponent<{
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly ilvl?: number;
|
|
|
|
readonly tentative?: number;
|
2021-03-15 00:11:39 +00:00
|
|
|
}> {
|
2018-11-02 02:51:57 +00:00
|
|
|
protected readonly xmlKeys = {
|
2017-03-10 10:42:24 +01:00
|
|
|
ilvl: "w:ilvl",
|
|
|
|
tentative: "w15:tentative",
|
|
|
|
};
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
|
2021-05-24 21:04:38 +03:00
|
|
|
// <xsd:complexType name="CT_NumFmt">
|
|
|
|
// <xsd:attribute name="val" type="ST_NumberFormat" use="required"/>
|
|
|
|
// <xsd:attribute name="format" type="s:ST_String" use="optional"/>
|
|
|
|
// </xsd:complexType>
|
2016-05-19 22:42:23 +01:00
|
|
|
class NumberFormat extends XmlComponent {
|
|
|
|
constructor(value: string) {
|
|
|
|
super("w:numFmt");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(
|
|
|
|
new Attributes({
|
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:04:38 +03:00
|
|
|
// <xsd:complexType name="CT_LevelText">
|
|
|
|
// <xsd:attribute name="val" type="s:ST_String" use="optional"/>
|
|
|
|
// <xsd:attribute name="null" type="s:ST_OnOff" use="optional"/>
|
|
|
|
// </xsd:complexType>
|
2016-05-19 22:42:23 +01:00
|
|
|
class LevelText extends XmlComponent {
|
|
|
|
constructor(value: string) {
|
|
|
|
super("w:lvlText");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(
|
|
|
|
new Attributes({
|
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LevelJc extends XmlComponent {
|
2019-11-01 01:57:01 +00:00
|
|
|
constructor(value: AlignmentType) {
|
2016-05-19 22:42:23 +01:00
|
|
|
super("w:lvlJc");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(
|
|
|
|
new Attributes({
|
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
2016-05-19 22:42:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 18:54:30 +02:00
|
|
|
export enum LevelSuffix {
|
|
|
|
NOTHING = "nothing",
|
|
|
|
SPACE = "space",
|
|
|
|
TAB = "tab",
|
|
|
|
}
|
|
|
|
|
2019-11-01 01:57:01 +00:00
|
|
|
export interface ILevelsOptions {
|
|
|
|
readonly level: number;
|
2020-12-24 04:26:45 +00:00
|
|
|
readonly format?: LevelFormat;
|
2019-11-06 20:54:39 +00:00
|
|
|
readonly text?: string;
|
2019-11-01 01:57:01 +00:00
|
|
|
readonly alignment?: AlignmentType;
|
|
|
|
readonly start?: number;
|
|
|
|
readonly suffix?: LevelSuffix;
|
|
|
|
readonly style?: {
|
2020-07-11 17:01:32 +08:00
|
|
|
readonly run?: IRunStylePropertiesOptions;
|
|
|
|
readonly paragraph?: IParagraphStylePropertiesOptions;
|
2019-11-01 01:57:01 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:04:38 +03:00
|
|
|
// <xsd:complexType name="CT_LevelSuffix">
|
|
|
|
// <xsd:attribute name="val" type="ST_LevelSuffix" use="required"/>
|
|
|
|
// </xsd:complexType>
|
|
|
|
// <xsd:simpleType name="ST_LevelSuffix">
|
|
|
|
// <xsd:restriction base="xsd:string">
|
|
|
|
// <xsd:enumeration value="tab"/>
|
|
|
|
// <xsd:enumeration value="space"/>
|
|
|
|
// <xsd:enumeration value="nothing"/>
|
|
|
|
// </xsd:restriction>
|
|
|
|
// </xsd:simpleType>
|
2018-07-06 18:54:30 +02:00
|
|
|
class Suffix extends XmlComponent {
|
|
|
|
constructor(value: LevelSuffix) {
|
|
|
|
super("w:suff");
|
|
|
|
this.root.push(
|
|
|
|
new Attributes({
|
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:04:38 +03:00
|
|
|
// <xsd:complexType name="CT_Lvl">
|
|
|
|
// <xsd:sequence>
|
|
|
|
// <xsd:element name="start" type="CT_DecimalNumber" minOccurs="0"/>
|
|
|
|
// <xsd:element name="numFmt" type="CT_NumFmt" minOccurs="0"/>
|
|
|
|
// <xsd:element name="lvlRestart" type="CT_DecimalNumber" minOccurs="0"/>
|
|
|
|
// <xsd:element name="pStyle" type="CT_String" minOccurs="0"/>
|
|
|
|
// <xsd:element name="isLgl" type="CT_OnOff" minOccurs="0"/>
|
|
|
|
// <xsd:element name="suff" type="CT_LevelSuffix" minOccurs="0"/>
|
|
|
|
// <xsd:element name="lvlText" type="CT_LevelText" minOccurs="0"/>
|
|
|
|
// <xsd:element name="lvlPicBulletId" type="CT_DecimalNumber" minOccurs="0"/>
|
|
|
|
// <xsd:element name="legacy" type="CT_LvlLegacy" minOccurs="0"/>
|
|
|
|
// <xsd:element name="lvlJc" type="CT_Jc" minOccurs="0"/>
|
|
|
|
// <xsd:element name="pPr" type="CT_PPrGeneral" minOccurs="0"/>
|
|
|
|
// <xsd:element name="rPr" type="CT_RPr" minOccurs="0"/>
|
|
|
|
// </xsd:sequence>
|
|
|
|
// <xsd:attribute name="ilvl" type="ST_DecimalNumber" use="required"/>
|
|
|
|
// <xsd:attribute name="tplc" type="ST_LongHexNumber" use="optional"/>
|
|
|
|
// <xsd:attribute name="tentative" type="s:ST_OnOff" use="optional"/>
|
|
|
|
// </xsd:complexType>
|
2017-07-07 14:31:08 +01:00
|
|
|
export class LevelBase extends XmlComponent {
|
2018-01-29 01:55:25 +00:00
|
|
|
private readonly paragraphProperties: ParagraphProperties;
|
|
|
|
private readonly runProperties: RunProperties;
|
2016-05-19 22:42:23 +01:00
|
|
|
|
2019-11-01 01:57:01 +00:00
|
|
|
constructor({ level, format, text, alignment = AlignmentType.START, start = 1, style, suffix }: ILevelsOptions) {
|
2016-05-19 22:42:23 +01:00
|
|
|
super("w:lvl");
|
|
|
|
|
2021-05-24 21:04:38 +03:00
|
|
|
this.root.push(new NumberValueElement("w:start", decimalNumber(start)));
|
2016-05-19 22:42:23 +01:00
|
|
|
|
2019-11-06 20:54:39 +00:00
|
|
|
if (format) {
|
|
|
|
this.root.push(new NumberFormat(format));
|
|
|
|
}
|
|
|
|
|
2021-05-20 04:20:14 +03:00
|
|
|
if (suffix) {
|
|
|
|
this.root.push(new Suffix(suffix));
|
|
|
|
}
|
|
|
|
|
2019-11-06 20:54:39 +00:00
|
|
|
if (text) {
|
|
|
|
this.root.push(new LevelText(text));
|
|
|
|
}
|
|
|
|
|
2021-05-20 04:20:14 +03:00
|
|
|
this.root.push(new LevelJc(alignment));
|
|
|
|
|
2020-07-11 17:01:32 +08:00
|
|
|
this.paragraphProperties = new ParagraphProperties(style && style.paragraph);
|
|
|
|
this.runProperties = new RunProperties(style && style.run);
|
2016-05-19 22:42:23 +01:00
|
|
|
|
|
|
|
this.root.push(this.paragraphProperties);
|
|
|
|
this.root.push(this.runProperties);
|
|
|
|
|
2021-05-20 04:20:14 +03:00
|
|
|
this.root.push(
|
|
|
|
new LevelAttributes({
|
2021-05-24 21:04:38 +03:00
|
|
|
ilvl: decimalNumber(level),
|
2021-05-20 04:20:14 +03:00
|
|
|
tentative: 1,
|
|
|
|
}),
|
|
|
|
);
|
2017-04-14 21:13:11 +02:00
|
|
|
}
|
2017-03-08 17:13:27 +01:00
|
|
|
}
|
2017-04-12 15:53:35 +02:00
|
|
|
|
|
|
|
export class Level extends LevelBase {
|
|
|
|
// This is the level that sits under abstractNum. We make a
|
|
|
|
// handful of properties required
|
2019-11-01 01:57:01 +00:00
|
|
|
constructor(options: ILevelsOptions) {
|
|
|
|
super(options);
|
2017-04-12 15:53:35 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-12 15:54:14 +02:00
|
|
|
|
|
|
|
export class LevelForOverride extends LevelBase {}
|