// http://officeopenxml.com/WPnumbering-numFmt.php
// http://www.datypic.com/sc/ooxml/a-w_val-57.html
import { Attributes, NumberValueElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { decimalNumber } from "@util/values";
import { AlignmentType } from "../paragraph/formatting";
import { ILevelParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";
// TODO: Breaking change - consolidate with number-format
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
export enum LevelFormat {
DECIMAL = "decimal",
UPPER_ROMAN = "upperRoman",
LOWER_ROMAN = "lowerRoman",
UPPER_LETTER = "upperLetter",
LOWER_LETTER = "lowerLetter",
ORDINAL = "ordinal",
CARDINAL_TEXT = "cardinalText",
ORDINAL_TEXT = "ordinalText",
HEX = "hex",
CHICAGO = "chicago",
IDEOGRAPH__DIGITAL = "ideographDigital",
JAPANESE_COUNTING = "japaneseCounting",
AIUEO = "aiueo",
IROHA = "iroha",
DECIMAL_FULL_WIDTH = "decimalFullWidth",
DECIMAL_HALF_WIDTH = "decimalHalfWidth",
JAPANESE_LEGAL = "japaneseLegal",
JAPANESE_DIGITAL_TEN_THOUSAND = "japaneseDigitalTenThousand",
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle",
DECIMAL_FULL_WIDTH2 = "decimalFullWidth2",
AIUEO_FULL_WIDTH = "aiueoFullWidth",
IROHA_FULL_WIDTH = "irohaFullWidth",
DECIMAL_ZERO = "decimalZero",
BULLET = "bullet",
GANADA = "ganada",
CHOSUNG = "chosung",
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop",
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen",
DECIMAL_ENCLOSED_CIRCLE_CHINESE = "decimalEnclosedCircleChinese",
IDEOGRAPH_ENCLOSED_CIRCLE = "ideographEnclosedCircle",
IDEOGRAPH_TRADITIONAL = "ideographTraditional",
IDEOGRAPH_ZODIAC = "ideographZodiac",
IDEOGRAPH_ZODIAC_TRADITIONAL = "ideographZodiacTraditional",
TAIWANESE_COUNTING = "taiwaneseCounting",
IDEOGRAPH_LEGAL_TRADITIONAL = "ideographLegalTraditional",
TAIWANESE_COUNTING_THOUSAND = "taiwaneseCountingThousand",
TAIWANESE_DIGITAL = "taiwaneseDigital",
CHINESE_COUNTING = "chineseCounting",
CHINESE_LEGAL_SIMPLIFIED = "chineseLegalSimplified",
CHINESE_COUNTING_THOUSAND = "chineseCountingThousand",
KOREAN_DIGITAL = "koreanDigital",
KOREAN_COUNTING = "koreanCounting",
KOREAN_LEGAL = "koreanLegal",
KOREAN_DIGITAL2 = "koreanDigital2",
VIETNAMESE_COUNTING = "vietnameseCounting",
RUSSIAN_LOWER = "russianLower",
RUSSIAN_UPPER = "russianUpper",
NONE = "none",
NUMBER_IN_DASH = "numberInDash",
HEBREW1 = "hebrew1",
HEBREW2 = "hebrew2",
ARABIC_ALPHA = "arabicAlpha",
ARABIC_ABJAD = "arabicAbjad",
HINDI_VOWELS = "hindiVowels",
HINDI_CONSONANTS = "hindiConsonants",
HINDI_NUMBERS = "hindiNumbers",
HINDI_COUNTING = "hindiCounting",
THAI_LETTERS = "thaiLetters",
THAI_NUMBERS = "thaiNumbers",
THAI_COUNTING = "thaiCounting",
BAHT_TEXT = "bahtText",
DOLLAR_TEXT = "dollarText",
CUSTOM = "custom",
}
class LevelAttributes extends XmlAttributeComponent<{
readonly ilvl?: number;
readonly tentative?: number;
}> {
protected readonly xmlKeys = {
ilvl: "w:ilvl",
tentative: "w15:tentative",
};
}
//
//
//
//
class NumberFormat extends XmlComponent {
public constructor(value: string) {
super("w:numFmt");
this.root.push(
new Attributes({
val: value,
}),
);
}
}
//
//
//
//
class LevelText extends XmlComponent {
public constructor(value: string) {
super("w:lvlText");
this.root.push(
new Attributes({
val: value,
}),
);
}
}
class LevelJc extends XmlComponent {
public constructor(value: AlignmentType) {
super("w:lvlJc");
this.root.push(
new Attributes({
val: value,
}),
);
}
}
export enum LevelSuffix {
NOTHING = "nothing",
SPACE = "space",
TAB = "tab",
}
export interface ILevelsOptions {
readonly level: number;
readonly format?: LevelFormat;
readonly text?: string;
readonly alignment?: AlignmentType;
readonly start?: number;
readonly suffix?: LevelSuffix;
readonly isLegalNumberingStyle?: boolean;
readonly style?: {
readonly run?: IRunStylePropertiesOptions;
readonly paragraph?: ILevelParagraphStylePropertiesOptions;
};
}
//
//
//
//
//
//
//
//
//
//
class Suffix extends XmlComponent {
public constructor(value: LevelSuffix) {
super("w:suff");
this.root.push(
new Attributes({
val: value,
}),
);
}
}
// http://officeopenxml.com/WPnumbering-isLgl.php
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.islegalnumberingstyle?view=openxml-2.8.1
class IsLegalNumberingStyle extends XmlComponent {
public constructor() {
super("w:isLgl");
}
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
export class LevelBase extends XmlComponent {
private readonly paragraphProperties: ParagraphProperties;
private readonly runProperties: RunProperties;
public constructor({
level,
format,
text,
alignment = AlignmentType.START,
start = 1,
style,
suffix,
isLegalNumberingStyle,
}: ILevelsOptions) {
super("w:lvl");
this.root.push(new NumberValueElement("w:start", decimalNumber(start)));
if (format) {
this.root.push(new NumberFormat(format));
}
if (suffix) {
this.root.push(new Suffix(suffix));
}
if (isLegalNumberingStyle) {
this.root.push(new IsLegalNumberingStyle());
}
if (text) {
this.root.push(new LevelText(text));
}
this.root.push(new LevelJc(alignment));
this.paragraphProperties = new ParagraphProperties(style && style.paragraph);
this.runProperties = new RunProperties(style && style.run);
this.root.push(this.paragraphProperties);
this.root.push(this.runProperties);
if (level > 9) {
throw new Error(
"Level cannot be greater than 9. Read more here: https://answers.microsoft.com/en-us/msoffice/forum/all/does-word-support-more-than-9-list-levels/d130fdcd-1781-446d-8c84-c6c79124e4d7",
);
}
this.root.push(
new LevelAttributes({
ilvl: decimalNumber(level),
tentative: 1,
}),
);
}
}
export class Level extends LevelBase {
// This is the level that sits under abstractNum. We make a
// handful of properties required
}
export class LevelForOverride extends LevelBase {}