Files
docx-js/src/file/numbering/num.ts

93 lines
2.8 KiB
TypeScript
Raw Normal View History

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<{
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
}
// <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({
numId: decimalNumber(options.numId),
2018-01-23 01:33:12 +00: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));
}
}
}
class LevelOverrideAttributes extends XmlAttributeComponent<{ readonly ilvl: number }> {
protected readonly xmlKeys = { ilvl: "w:ilvl" };
}
export class LevelOverride extends XmlComponent {
2022-08-31 07:52:27 +01:00
public constructor(levelNum: number, start?: number) {
super("w:lvlOverride");
2018-01-23 01:33:12 +00:00
this.root.push(new LevelOverrideAttributes({ ilvl: levelNum }));
if (start !== undefined) {
this.root.push(new StartOverride(start));
}
}
}
class StartOverrideAttributes extends XmlAttributeComponent<{ readonly val: number }> {
protected readonly xmlKeys = { val: "w:val" };
}
class StartOverride extends XmlComponent {
2022-08-31 07:52:27 +01:00
public constructor(start: number) {
super("w:startOverride");
2018-01-23 01:33:12 +00:00
this.root.push(new StartOverrideAttributes({ val: start }));
}
2017-03-08 17:16:51 +01:00
}