2022-06-26 23:26:42 +01:00
|
|
|
import { Attributes, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
|
|
|
import { decimalNumber } from "@util/values";
|
2016-05-21 00:02:46 +01:00
|
|
|
|
|
|
|
class AbstractNumId extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(value: number) {
|
2016-05-21 00:02:46 +01:00
|
|
|
super("w:abstractNumId");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(
|
|
|
|
new Attributes({
|
|
|
|
val: value,
|
|
|
|
}),
|
|
|
|
);
|
2016-05-21 00:02:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 03:58:05 +00:00
|
|
|
class NumAttributes extends XmlAttributeComponent<{
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly numId: number;
|
2021-03-12 03:58:05 +00:00
|
|
|
}> {
|
|
|
|
protected readonly xmlKeys = { numId: "w:numId" };
|
2016-05-21 00:02:46 +01:00
|
|
|
}
|
|
|
|
|
2021-03-12 03:58:05 +00:00
|
|
|
export interface IConcreteNumberingOptions {
|
|
|
|
readonly numId: number;
|
|
|
|
readonly abstractNumId: number;
|
|
|
|
readonly reference: string;
|
|
|
|
readonly instance: number;
|
|
|
|
readonly overrideLevel?: {
|
|
|
|
readonly num: number;
|
|
|
|
readonly start?: number;
|
|
|
|
};
|
2016-05-21 00:02:46 +01:00
|
|
|
}
|
|
|
|
|
2021-05-24 21:04:38 +03:00
|
|
|
// <xsd:complexType name="CT_Numbering">
|
|
|
|
// ...
|
|
|
|
// <xsd:element name="num" type="CT_Num" minOccurs="0" maxOccurs="unbounded"/>
|
|
|
|
|
|
|
|
// <xsd:complexType name="CT_Num">
|
|
|
|
// <xsd:sequence>
|
|
|
|
// <xsd:element name="abstractNumId" type="CT_DecimalNumber" minOccurs="1"/>
|
|
|
|
// <xsd:element name="lvlOverride" type="CT_NumLvl" minOccurs="0" maxOccurs="9"/>
|
|
|
|
// </xsd:sequence>
|
|
|
|
// <xsd:attribute name="numId" type="ST_DecimalNumber" use="required"/>
|
|
|
|
// </xsd:complexType>
|
2019-11-01 01:57:01 +00:00
|
|
|
export class ConcreteNumbering extends XmlComponent {
|
2021-03-12 03:58:05 +00:00
|
|
|
public readonly numId: number;
|
|
|
|
public readonly reference: string;
|
|
|
|
public readonly instance: number;
|
2016-05-26 15:08:34 +01:00
|
|
|
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(options: IConcreteNumberingOptions) {
|
2016-05-21 00:02:46 +01:00
|
|
|
super("w:num");
|
2021-03-12 03:58:05 +00:00
|
|
|
|
|
|
|
this.numId = options.numId;
|
|
|
|
this.reference = options.reference;
|
|
|
|
this.instance = options.instance;
|
|
|
|
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(
|
|
|
|
new NumAttributes({
|
2021-05-24 21:04:38 +03:00
|
|
|
numId: decimalNumber(options.numId),
|
2018-01-23 01:33:12 +00:00
|
|
|
}),
|
|
|
|
);
|
2017-04-12 15:54:14 +02:00
|
|
|
|
2021-05-24 21:04:38 +03:00
|
|
|
this.root.push(new AbstractNumId(decimalNumber(options.abstractNumId)));
|
2021-03-12 03:58:05 +00:00
|
|
|
|
|
|
|
if (options.overrideLevel) {
|
|
|
|
this.root.push(new LevelOverride(options.overrideLevel.num, options.overrideLevel.start));
|
|
|
|
}
|
2017-04-12 15:54:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-02 02:51:57 +00:00
|
|
|
class LevelOverrideAttributes extends XmlAttributeComponent<{ readonly ilvl: number }> {
|
|
|
|
protected readonly xmlKeys = { ilvl: "w:ilvl" };
|
2017-04-12 15:54:14 +02:00
|
|
|
}
|
|
|
|
|
2017-07-07 14:31:08 +01:00
|
|
|
export class LevelOverride extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(levelNum: number, start?: number) {
|
2017-04-12 15:54:14 +02:00
|
|
|
super("w:lvlOverride");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(new LevelOverrideAttributes({ ilvl: levelNum }));
|
2017-04-12 15:54:14 +02:00
|
|
|
if (start !== undefined) {
|
|
|
|
this.root.push(new StartOverride(start));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-02 02:51:57 +00:00
|
|
|
class StartOverrideAttributes extends XmlAttributeComponent<{ readonly val: number }> {
|
|
|
|
protected readonly xmlKeys = { val: "w:val" };
|
2017-04-12 15:54:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class StartOverride extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(start: number) {
|
2017-04-12 15:54:14 +02:00
|
|
|
super("w:startOverride");
|
2018-01-23 01:33:12 +00:00
|
|
|
this.root.push(new StartOverrideAttributes({ val: start }));
|
2017-04-12 15:54:14 +02:00
|
|
|
}
|
2017-03-08 17:16:51 +01:00
|
|
|
}
|