2020-12-24 04:26:45 +00:00
// http://officeopenxml.com/WPnumbering-numFmt.php
2022-11-25 01:36:59 +00:00
// http://www.datypic.com/sc/ooxml/a-w_val-57.html
2022-06-26 23:26:42 +01:00
import { Attributes , NumberValueElement , XmlAttributeComponent , XmlComponent } from "@file/xml-components" ;
import { decimalNumber } from "@util/values" ;
2020-07-11 17:01:32 +08:00
import { AlignmentType } from "../paragraph/formatting" ;
2021-09-20 21:58:07 +03:00
import { ILevelParagraphStylePropertiesOptions , ParagraphProperties } from "../paragraph/properties" ;
2020-07-11 17:01:32 +08:00
import { IRunStylePropertiesOptions , RunProperties } from "../paragraph/run/properties" ;
2016-05-19 22:42:23 +01:00
2022-11-25 01:36:59 +00:00
// TODO: Breaking change - consolidate with number-format
// <xsd:simpleType name="ST_NumberFormat">
// <xsd:restriction base="xsd:string">
// <xsd:enumeration value="decimal"/>
// <xsd:enumeration value="upperRoman"/>
// <xsd:enumeration value="lowerRoman"/>
// <xsd:enumeration value="upperLetter"/>
// <xsd:enumeration value="lowerLetter"/>
// <xsd:enumeration value="ordinal"/>
// <xsd:enumeration value="cardinalText"/>
// <xsd:enumeration value="ordinalText"/>
// <xsd:enumeration value="hex"/>
// <xsd:enumeration value="chicago"/>
// <xsd:enumeration value="ideographDigital"/>
// <xsd:enumeration value="japaneseCounting"/>
// <xsd:enumeration value="aiueo"/>
// <xsd:enumeration value="iroha"/>
// <xsd:enumeration value="decimalFullWidth"/>
// <xsd:enumeration value="decimalHalfWidth"/>
// <xsd:enumeration value="japaneseLegal"/>
// <xsd:enumeration value="japaneseDigitalTenThousand"/>
// <xsd:enumeration value="decimalEnclosedCircle"/>
// <xsd:enumeration value="decimalFullWidth2"/>
// <xsd:enumeration value="aiueoFullWidth"/>
// <xsd:enumeration value="irohaFullWidth"/>
// <xsd:enumeration value="decimalZero"/>
// <xsd:enumeration value="bullet"/>
// <xsd:enumeration value="ganada"/>
// <xsd:enumeration value="chosung"/>
// <xsd:enumeration value="decimalEnclosedFullstop"/>
// <xsd:enumeration value="decimalEnclosedParen"/>
// <xsd:enumeration value="decimalEnclosedCircleChinese"/>
// <xsd:enumeration value="ideographEnclosedCircle"/>
// <xsd:enumeration value="ideographTraditional"/>
// <xsd:enumeration value="ideographZodiac"/>
// <xsd:enumeration value="ideographZodiacTraditional"/>
// <xsd:enumeration value="taiwaneseCounting"/>
// <xsd:enumeration value="ideographLegalTraditional"/>
// <xsd:enumeration value="taiwaneseCountingThousand"/>
// <xsd:enumeration value="taiwaneseDigital"/>
// <xsd:enumeration value="chineseCounting"/>
// <xsd:enumeration value="chineseLegalSimplified"/>
// <xsd:enumeration value="chineseCountingThousand"/>
// <xsd:enumeration value="koreanDigital"/>
// <xsd:enumeration value="koreanCounting"/>
// <xsd:enumeration value="koreanLegal"/>
// <xsd:enumeration value="koreanDigital2"/>
// <xsd:enumeration value="vietnameseCounting"/>
// <xsd:enumeration value="russianLower"/>
// <xsd:enumeration value="russianUpper"/>
// <xsd:enumeration value="none"/>
// <xsd:enumeration value="numberInDash"/>
// <xsd:enumeration value="hebrew1"/>
// <xsd:enumeration value="hebrew2"/>
// <xsd:enumeration value="arabicAlpha"/>
// <xsd:enumeration value="arabicAbjad"/>
// <xsd:enumeration value="hindiVowels"/>
// <xsd:enumeration value="hindiConsonants"/>
// <xsd:enumeration value="hindiNumbers"/>
// <xsd:enumeration value="hindiCounting"/>
// <xsd:enumeration value="thaiLetters"/>
// <xsd:enumeration value="thaiNumbers"/>
// <xsd:enumeration value="thaiCounting"/>
// <xsd:enumeration value="bahtText"/>
// <xsd:enumeration value="dollarText"/>
// <xsd:enumeration value="custom"/>
// </xsd:restriction>
// </xsd:simpleType>
2020-12-24 04:26:45 +00:00
export enum LevelFormat {
2022-11-25 01:36:59 +00:00
DECIMAL = "decimal" ,
UPPER_ROMAN = "upperRoman" ,
LOWER_ROMAN = "lowerRoman" ,
UPPER_LETTER = "upperLetter" ,
LOWER_LETTER = "lowerLetter" ,
ORDINAL = "ordinal" ,
2020-12-24 04:26:45 +00:00
CARDINAL_TEXT = "cardinalText" ,
2022-11-25 01:36:59 +00:00
ORDINAL_TEXT = "ordinalText" ,
HEX = "hex" ,
2020-12-24 04:26:45 +00:00
CHICAGO = "chicago" ,
2022-11-25 01:36:59 +00:00
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" ,
2020-12-24 04:26:45 +00:00
DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle" ,
2022-11-25 01:36:59 +00:00
DECIMAL_FULL_WIDTH2 = "decimalFullWidth2" ,
AIUEO_FULL_WIDTH = "aiueoFullWidth" ,
IROHA_FULL_WIDTH = "irohaFullWidth" ,
DECIMAL_ZERO = "decimalZero" ,
BULLET = "bullet" ,
GANADA = "ganada" ,
CHOSUNG = "chosung" ,
2020-12-24 04:26:45 +00:00
DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop" ,
DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen" ,
2022-11-25 01:36:59 +00:00
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" ,
2020-12-24 04:26:45 +00:00
NONE = "none" ,
2022-11-25 01:36:59 +00:00
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" ,
2020-12-24 04:26:45 +00:00
}
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 {
2022-08-31 07:52:27 +01:00
public constructor ( value : string ) {
2016-05-19 22:42:23 +01:00
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 {
2022-08-31 07:52:27 +01:00
public constructor ( value : string ) {
2016-05-19 22:42:23 +01:00
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 {
2022-08-31 07:52:27 +01:00
public 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 ;
2022-09-15 13:08:49 +01:00
readonly isLegalNumberingStyle? : boolean ;
2019-11-01 01:57:01 +00:00
readonly style ? : {
2020-07-11 17:01:32 +08:00
readonly run? : IRunStylePropertiesOptions ;
2021-09-20 21:58:07 +03:00
readonly paragraph? : ILevelParagraphStylePropertiesOptions ;
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 {
2022-08-31 07:52:27 +01:00
public constructor ( value : LevelSuffix ) {
2018-07-06 18:54:30 +02:00
super ( "w:suff" ) ;
this . root . push (
new Attributes ( {
val : value ,
} ) ,
) ;
}
}
2022-09-15 13:08:49 +01:00
// 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 {
2022-09-15 20:00:50 +01:00
public constructor ( ) {
2022-09-15 13:08:49 +01:00
super ( "w:isLgl" ) ;
}
}
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
2022-09-15 18:04:48 +01:00
public constructor ( {
level ,
format ,
text ,
alignment = AlignmentType . START ,
start = 1 ,
style ,
suffix ,
isLegalNumberingStyle ,
} : 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 ) ) ;
}
2022-09-15 13:08:49 +01:00
if ( isLegalNumberingStyle ) {
this . root . push ( new IsLegalNumberingStyle ( ) ) ;
}
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-12-18 15:42:35 +00:00
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" ,
) ;
}
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
}
2017-04-12 15:54:14 +02:00
export class LevelForOverride extends LevelBase { }