Merge pull request #190 from dolanmiu/feat/more-tests

Introduce some functional programming techniques
This commit is contained in:
Dolan
2018-11-02 03:12:28 +00:00
committed by GitHub
108 changed files with 749 additions and 659 deletions

8
.nycrc
View File

@ -1,9 +1,9 @@
{ {
"check-coverage": true, "check-coverage": true,
"lines": 87.39, "lines": 87.54,
"functions": 83.54, "functions": 83.61,
"branches": 71.95, "branches": 72.57,
"statements": 87.17, "statements": 87.32,
"include": [ "include": [
"src/**/*.ts" "src/**/*.ts"
], ],

View File

@ -81,6 +81,7 @@
"sinon": "^5.0.7", "sinon": "^5.0.7",
"ts-node": "^7.0.1", "ts-node": "^7.0.1",
"tslint": "^5.11.0", "tslint": "^5.11.0",
"tslint-immutable": "^4.9.0",
"typedoc": "^0.11.1", "typedoc": "^0.11.1",
"typescript": "2.9.2", "typescript": "2.9.2",
"webpack": "^3.10.0" "webpack": "^3.10.0"

View File

@ -5,25 +5,25 @@ import { File } from "file";
import { Formatter } from "../formatter"; import { Formatter } from "../formatter";
interface IXmlifyedFile { interface IXmlifyedFile {
data: string; readonly data: string;
path: string; readonly path: string;
} }
interface IXmlifyedFileMapping { interface IXmlifyedFileMapping {
Document: IXmlifyedFile; readonly Document: IXmlifyedFile;
Styles: IXmlifyedFile; readonly Styles: IXmlifyedFile;
Properties: IXmlifyedFile; readonly Properties: IXmlifyedFile;
Numbering: IXmlifyedFile; readonly Numbering: IXmlifyedFile;
Relationships: IXmlifyedFile; readonly Relationships: IXmlifyedFile;
FileRelationships: IXmlifyedFile; readonly FileRelationships: IXmlifyedFile;
Headers: IXmlifyedFile[]; readonly Headers: IXmlifyedFile[];
Footers: IXmlifyedFile[]; readonly Footers: IXmlifyedFile[];
HeaderRelationships: IXmlifyedFile[]; readonly HeaderRelationships: IXmlifyedFile[];
FooterRelationships: IXmlifyedFile[]; readonly FooterRelationships: IXmlifyedFile[];
ContentTypes: IXmlifyedFile; readonly ContentTypes: IXmlifyedFile;
AppProperties: IXmlifyedFile; readonly AppProperties: IXmlifyedFile;
FootNotes: IXmlifyedFile; readonly FootNotes: IXmlifyedFile;
Settings: IXmlifyedFile; readonly Settings: IXmlifyedFile;
} }
export class Compiler { export class Compiler {

View File

@ -1,12 +1,12 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IAppPropertiesAttributes { export interface IAppPropertiesAttributes {
xmlns: string; readonly xmlns: string;
vt: string; readonly vt: string;
} }
export class AppPropertiesAttributes extends XmlAttributeComponent<IAppPropertiesAttributes> { export class AppPropertiesAttributes extends XmlAttributeComponent<IAppPropertiesAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
xmlns: "xmlns", xmlns: "xmlns",
vt: "xmlns:vt", vt: "xmlns:vt",
}; };

View File

@ -1,11 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IContentTypeAttributes { export interface IContentTypeAttributes {
xmlns?: string; readonly xmlns?: string;
} }
export class ContentTypeAttributes extends XmlAttributeComponent<IContentTypeAttributes> { export class ContentTypeAttributes extends XmlAttributeComponent<IContentTypeAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
xmlns: "xmlns", xmlns: "xmlns",
}; };
} }

View File

@ -1,12 +1,12 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IDefaultAttributes { export interface IDefaultAttributes {
contentType: string; readonly contentType: string;
extension?: string; readonly extension?: string;
} }
export class DefaultAttributes extends XmlAttributeComponent<IDefaultAttributes> { export class DefaultAttributes extends XmlAttributeComponent<IDefaultAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
contentType: "ContentType", contentType: "ContentType",
extension: "Extension", extension: "Extension",
}; };

View File

@ -1,12 +1,12 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IOverrideAttributes { export interface IOverrideAttributes {
contentType: string; readonly contentType: string;
partName?: string; readonly partName?: string;
} }
export class OverrideAttributes extends XmlAttributeComponent<IOverrideAttributes> { export class OverrideAttributes extends XmlAttributeComponent<IOverrideAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
contentType: "ContentType", contentType: "ContentType",
partName: "PartName", partName: "PartName",
}; };

View File

@ -3,14 +3,14 @@ import { DocumentAttributes } from "../document/document-attributes";
import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components"; import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components";
export interface IPropertiesOptions { export interface IPropertiesOptions {
title?: string; readonly title?: string;
subject?: string; readonly subject?: string;
creator?: string; readonly creator?: string;
keywords?: string; readonly keywords?: string;
description?: string; readonly description?: string;
lastModifiedBy?: string; readonly lastModifiedBy?: string;
revision?: string; readonly revision?: string;
externalStyles?: string; readonly externalStyles?: string;
} }
export class CoreProperties extends XmlComponent { export class CoreProperties extends XmlComponent {

View File

@ -1,11 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IColumnsAttributes { export interface IColumnsAttributes {
space?: number; readonly space?: number;
} }
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> { export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
space: "w:space", space: "w:space",
}; };
} }

View File

@ -1,11 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IDocGridAttributesProperties { export interface IDocGridAttributesProperties {
linePitch?: number; readonly linePitch?: number;
} }
export class DocGridAttributes extends XmlAttributeComponent<IDocGridAttributesProperties> { export class DocGridAttributes extends XmlAttributeComponent<IDocGridAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
linePitch: "w:linePitch", linePitch: "w:linePitch",
}; };
} }

View File

@ -7,12 +7,12 @@ export enum FooterReferenceType {
} }
export interface IFooterReferenceAttributes { export interface IFooterReferenceAttributes {
type: string; readonly type: string;
id: string; readonly id: string;
} }
export class FooterReferenceAttributes extends XmlAttributeComponent<IFooterReferenceAttributes> { export class FooterReferenceAttributes extends XmlAttributeComponent<IFooterReferenceAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
type: "w:type", type: "w:type",
id: "r:id", id: "r:id",
}; };

View File

@ -2,8 +2,8 @@ import { XmlComponent } from "file/xml-components";
import { FooterReferenceAttributes, FooterReferenceType } from "./footer-reference-attributes"; import { FooterReferenceAttributes, FooterReferenceType } from "./footer-reference-attributes";
export interface IFooterOptions { export interface IFooterOptions {
footerType?: FooterReferenceType; readonly footerType?: FooterReferenceType;
footerId?: number; readonly footerId?: number;
} }
export class FooterReference extends XmlComponent { export class FooterReference extends XmlComponent {

View File

@ -7,12 +7,12 @@ export enum HeaderReferenceType {
} }
export interface IHeaderReferenceAttributes { export interface IHeaderReferenceAttributes {
type: string; readonly type: string;
id: string; readonly id: string;
} }
export class HeaderReferenceAttributes extends XmlAttributeComponent<IHeaderReferenceAttributes> { export class HeaderReferenceAttributes extends XmlAttributeComponent<IHeaderReferenceAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
type: "w:type", type: "w:type",
id: "r:id", id: "r:id",
}; };

View File

@ -2,8 +2,8 @@ import { XmlComponent } from "file/xml-components";
import { HeaderReferenceAttributes, HeaderReferenceType } from "./header-reference-attributes"; import { HeaderReferenceAttributes, HeaderReferenceType } from "./header-reference-attributes";
export interface IHeaderOptions { export interface IHeaderOptions {
headerType?: HeaderReferenceType; readonly headerType?: HeaderReferenceType;
headerId?: number; readonly headerId?: number;
} }
export class HeaderReference extends XmlComponent { export class HeaderReference extends XmlComponent {

View File

@ -19,28 +19,28 @@ export enum PageBorderZOrder {
} }
export interface IPageBorderAttributes { export interface IPageBorderAttributes {
display?: PageBorderDisplay; readonly display?: PageBorderDisplay;
offsetFrom?: PageBorderOffsetFrom; readonly offsetFrom?: PageBorderOffsetFrom;
zOrder?: PageBorderZOrder; readonly zOrder?: PageBorderZOrder;
} }
export interface IPageBorderConfiguration { export interface IPageBorderConfiguration {
style?: BorderStyle; readonly style?: BorderStyle;
size?: number; readonly size?: number;
color?: string; readonly color?: string;
space?: number; readonly space?: number;
} }
export interface IPageBordersOptions { export interface IPageBordersOptions {
pageBorders?: IPageBorderAttributes; readonly pageBorders?: IPageBorderAttributes;
pageBorderTop?: IPageBorderConfiguration; readonly pageBorderTop?: IPageBorderConfiguration;
pageBorderRight?: IPageBorderConfiguration; readonly pageBorderRight?: IPageBorderConfiguration;
pageBorderBottom?: IPageBorderConfiguration; readonly pageBorderBottom?: IPageBorderConfiguration;
pageBorderLeft?: IPageBorderConfiguration; readonly pageBorderLeft?: IPageBorderConfiguration;
} }
class PageBordeAttributes extends XmlAttributeComponent<IPageBorderConfiguration> { class PageBordeAttributes extends XmlAttributeComponent<IPageBorderConfiguration> {
protected xmlKeys = { protected readonly xmlKeys = {
style: "w:val", style: "w:val",
size: "w:size", size: "w:size",
color: "w:color", color: "w:color",
@ -57,7 +57,7 @@ class PageBorder extends XmlComponent {
} }
class PageBordersAttributes extends XmlAttributeComponent<IPageBorderAttributes> { class PageBordersAttributes extends XmlAttributeComponent<IPageBorderAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
display: "w:display", display: "w:display",
offsetFrom: "w:offsetFrom", offsetFrom: "w:offsetFrom",
zOrder: "w:zOrder", zOrder: "w:zOrder",

View File

@ -1,18 +1,18 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IPageMarginAttributes { export interface IPageMarginAttributes {
top?: number; readonly top?: number;
right?: number; readonly right?: number;
bottom?: number; readonly bottom?: number;
left?: number; readonly left?: number;
header?: number; readonly header?: number;
footer?: number; readonly footer?: number;
gutter?: number; readonly gutter?: number;
mirror?: boolean; readonly mirror?: boolean;
} }
export class PageMarginAttributes extends XmlAttributeComponent<IPageMarginAttributes> { export class PageMarginAttributes extends XmlAttributeComponent<IPageMarginAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
top: "w:top", top: "w:top",
right: "w:right", right: "w:right",
bottom: "w:bottom", bottom: "w:bottom",

View File

@ -17,12 +17,12 @@ export enum PageNumberFormat {
} }
export interface IPageNumberTypeAttributes { export interface IPageNumberTypeAttributes {
pageNumberStart?: number; readonly pageNumberStart?: number;
pageNumberFormatType?: PageNumberFormat; readonly pageNumberFormatType?: PageNumberFormat;
} }
export class PageNumberTypeAttributes extends XmlAttributeComponent<IPageNumberTypeAttributes> { export class PageNumberTypeAttributes extends XmlAttributeComponent<IPageNumberTypeAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
pageNumberStart: "w:start", pageNumberStart: "w:start",
pageNumberFormatType: "w:fmt", pageNumberFormatType: "w:fmt",
}; };

View File

@ -6,13 +6,13 @@ export enum PageOrientation {
} }
export interface IPageSizeAttributes { export interface IPageSizeAttributes {
width?: number; readonly width?: number;
height?: number; readonly height?: number;
orientation?: PageOrientation; readonly orientation?: PageOrientation;
} }
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> { export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
width: "w:w", width: "w:w",
height: "w:h", height: "w:h",
orientation: "w:orient", orientation: "w:orient",

View File

@ -20,21 +20,21 @@ import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attr
import { TitlePage } from "./title-page/title-page"; import { TitlePage } from "./title-page/title-page";
export interface IHeaderFooterGroup<T> { export interface IHeaderFooterGroup<T> {
default?: T; readonly default?: T;
first?: T; readonly first?: T;
even?: T; readonly even?: T;
} }
interface IHeadersOptions { interface IHeadersOptions {
headers?: IHeaderFooterGroup<HeaderWrapper>; readonly headers?: IHeaderFooterGroup<HeaderWrapper>;
} }
interface IFootersOptions { interface IFootersOptions {
footers?: IHeaderFooterGroup<FooterWrapper>; readonly footers?: IHeaderFooterGroup<FooterWrapper>;
} }
interface ITitlePageOptions { interface ITitlePageOptions {
titlePage?: boolean; readonly titlePage?: boolean;
} }
export type SectionPropertiesOptions = IPageSizeAttributes & export type SectionPropertiesOptions = IPageSizeAttributes &

View File

@ -1,11 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IHeaderReferenceAttributes { export interface IHeaderReferenceAttributes {
value: string; readonly value: string;
} }
export class TitlePageAttributes extends XmlAttributeComponent<IHeaderReferenceAttributes> { export class TitlePageAttributes extends XmlAttributeComponent<IHeaderReferenceAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
value: "w:val", value: "w:val",
}; };
} }

View File

@ -1,33 +1,33 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IDocumentAttributesProperties { export interface IDocumentAttributesProperties {
wpc?: string; readonly wpc?: string;
mc?: string; readonly mc?: string;
o?: string; readonly o?: string;
r?: string; readonly r?: string;
m?: string; readonly m?: string;
v?: string; readonly v?: string;
wp14?: string; readonly wp14?: string;
wp?: string; readonly wp?: string;
w10?: string; readonly w10?: string;
w?: string; readonly w?: string;
w14?: string; readonly w14?: string;
w15?: string; readonly w15?: string;
wpg?: string; readonly wpg?: string;
wpi?: string; readonly wpi?: string;
wne?: string; readonly wne?: string;
wps?: string; readonly wps?: string;
Ignorable?: string; readonly Ignorable?: string;
cp?: string; readonly cp?: string;
dc?: string; readonly dc?: string;
dcterms?: string; readonly dcterms?: string;
dcmitype?: string; readonly dcmitype?: string;
xsi?: string; readonly xsi?: string;
type?: string; readonly type?: string;
} }
export class DocumentAttributes extends XmlAttributeComponent<IDocumentAttributesProperties> { export class DocumentAttributes extends XmlAttributeComponent<IDocumentAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
wpc: "xmlns:wpc", wpc: "xmlns:wpc",
mc: "xmlns:mc", mc: "xmlns:mc",
o: "xmlns:o", o: "xmlns:o",

View File

@ -2,16 +2,16 @@ import { XmlAttributeComponent } from "file/xml-components";
import { IDistance } from "../drawing"; import { IDistance } from "../drawing";
export interface IAnchorAttributes extends IDistance { export interface IAnchorAttributes extends IDistance {
allowOverlap?: "0" | "1"; readonly allowOverlap?: "0" | "1";
behindDoc?: "0" | "1"; readonly behindDoc?: "0" | "1";
layoutInCell?: "0" | "1"; readonly layoutInCell?: "0" | "1";
locked?: "0" | "1"; readonly locked?: "0" | "1";
relativeHeight?: number; readonly relativeHeight?: number;
simplePos?: "0" | "1"; readonly simplePos?: "0" | "1";
} }
export class AnchorAttributes extends XmlAttributeComponent<IAnchorAttributes> { export class AnchorAttributes extends XmlAttributeComponent<IAnchorAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
distT: "distT", distT: "distT",
distB: "distB", distB: "distB",
distL: "distL", distL: "distL",

View File

@ -1,13 +1,13 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IDocPropertiesAttributes { export interface IDocPropertiesAttributes {
id?: number; readonly id?: number;
name?: string; readonly name?: string;
descr?: string; readonly descr?: string;
} }
export class DocPropertiesAttributes extends XmlAttributeComponent<IDocPropertiesAttributes> { export class DocPropertiesAttributes extends XmlAttributeComponent<IDocPropertiesAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
id: "id", id: "id",
name: "name", name: "name",
descr: "descr", descr: "descr",

View File

@ -11,16 +11,16 @@ export enum PlacementPosition {
} }
export interface IDistance { export interface IDistance {
distT?: number; readonly distT?: number;
distB?: number; readonly distB?: number;
distL?: number; readonly distL?: number;
distR?: number; readonly distR?: number;
} }
export interface IDrawingOptions { export interface IDrawingOptions {
position?: PlacementPosition; readonly position?: PlacementPosition;
textWrapping?: ITextWrapping; readonly textWrapping?: ITextWrapping;
floating?: IFloating; readonly floating?: IFloating;
} }
const defaultDrawingOptions: IDrawingOptions = { const defaultDrawingOptions: IDrawingOptions = {

View File

@ -1,14 +1,14 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IEffectExtentAttributes { export interface IEffectExtentAttributes {
b?: number; readonly b?: number;
l?: number; readonly l?: number;
r?: number; readonly r?: number;
t?: number; readonly t?: number;
} }
export class EffectExtentAttributes extends XmlAttributeComponent<IEffectExtentAttributes> { export class EffectExtentAttributes extends XmlAttributeComponent<IEffectExtentAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
b: "b", b: "b",
l: "l", l: "l",
r: "r", r: "r",

View File

@ -1,12 +1,12 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IExtentAttributes { export interface IExtentAttributes {
cx?: number; readonly cx?: number;
cy?: number; readonly cy?: number;
} }
export class ExtentAttributes extends XmlAttributeComponent<IExtentAttributes> { export class ExtentAttributes extends XmlAttributeComponent<IExtentAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
cx: "cx", cx: "cx",
cy: "cy", cy: "cy",
}; };

View File

@ -39,22 +39,22 @@ export enum VerticalPositionAlign {
} }
export interface IHorizontalPositionOptions { export interface IHorizontalPositionOptions {
relative: HorizontalPositionRelativeFrom; readonly relative: HorizontalPositionRelativeFrom;
align?: HorizontalPositionAlign; readonly align?: HorizontalPositionAlign;
offset?: number; readonly offset?: number;
} }
export interface IVerticalPositionOptions { export interface IVerticalPositionOptions {
relative: VerticalPositionRelativeFrom; readonly relative: VerticalPositionRelativeFrom;
align?: VerticalPositionAlign; readonly align?: VerticalPositionAlign;
offset?: number; readonly offset?: number;
} }
export interface IFloating { export interface IFloating {
horizontalPosition: IHorizontalPositionOptions; readonly horizontalPosition: IHorizontalPositionOptions;
verticalPosition: IVerticalPositionOptions; readonly verticalPosition: IVerticalPositionOptions;
allowOverlap?: boolean; readonly allowOverlap?: boolean;
lockAnchor?: boolean; readonly lockAnchor?: boolean;
behindDocument?: boolean; readonly behindDocument?: boolean;
layoutInCell?: boolean; readonly layoutInCell?: boolean;
} }

View File

@ -5,11 +5,11 @@ import { HorizontalPositionRelativeFrom, IHorizontalPositionOptions } from "./fl
import { PositionOffset } from "./position-offset"; import { PositionOffset } from "./position-offset";
interface IHorizontalPositionAttributes { interface IHorizontalPositionAttributes {
relativeFrom: HorizontalPositionRelativeFrom; readonly relativeFrom: HorizontalPositionRelativeFrom;
} }
class HorizontalPositionAttributes extends XmlAttributeComponent<IHorizontalPositionAttributes> { class HorizontalPositionAttributes extends XmlAttributeComponent<IHorizontalPositionAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
relativeFrom: "relativeFrom", relativeFrom: "relativeFrom",
}; };
} }

View File

@ -2,12 +2,12 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
interface ISimplePosAttributes { interface ISimplePosAttributes {
x: number; readonly x: number;
y: number; readonly y: number;
} }
class SimplePosAttributes extends XmlAttributeComponent<ISimplePosAttributes> { class SimplePosAttributes extends XmlAttributeComponent<ISimplePosAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
x: "x", x: "x",
y: "y", y: "y",
}; };

View File

@ -5,11 +5,11 @@ import { IVerticalPositionOptions, VerticalPositionRelativeFrom } from "./floati
import { PositionOffset } from "./position-offset"; import { PositionOffset } from "./position-offset";
interface IVerticalPositionAttributes { interface IVerticalPositionAttributes {
relativeFrom: VerticalPositionRelativeFrom; readonly relativeFrom: VerticalPositionRelativeFrom;
} }
class VerticalPositionAttributes extends XmlAttributeComponent<IVerticalPositionAttributes> { class VerticalPositionAttributes extends XmlAttributeComponent<IVerticalPositionAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
relativeFrom: "relativeFrom", relativeFrom: "relativeFrom",
}; };
} }

View File

@ -1,12 +1,12 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IGraphicFrameLockAttributes { export interface IGraphicFrameLockAttributes {
xmlns?: string; readonly xmlns?: string;
noChangeAspect?: number; readonly noChangeAspect?: number;
} }
export class GraphicFrameLockAttributes extends XmlAttributeComponent<IGraphicFrameLockAttributes> { export class GraphicFrameLockAttributes extends XmlAttributeComponent<IGraphicFrameLockAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
xmlns: "xmlns:a", xmlns: "xmlns:a",
noChangeAspect: "noChangeAspect", noChangeAspect: "noChangeAspect",
}; };

View File

@ -1,11 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IGraphicDataAttributes { export interface IGraphicDataAttributes {
uri?: string; readonly uri?: string;
} }
export class GraphicDataAttributes extends XmlAttributeComponent<IGraphicDataAttributes> { export class GraphicDataAttributes extends XmlAttributeComponent<IGraphicDataAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
uri: "uri", uri: "uri",
}; };
} }

View File

@ -1,12 +1,12 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
interface IBlipProperties { interface IBlipProperties {
embed: string; readonly embed: string;
cstate: string; readonly cstate: string;
} }
class BlipAttributes extends XmlAttributeComponent<IBlipProperties> { class BlipAttributes extends XmlAttributeComponent<IBlipProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
embed: "r:embed", embed: "r:embed",
cstate: "cstate", cstate: "cstate",
}; };

View File

@ -1,12 +1,12 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IPicLocksAttributes { export interface IPicLocksAttributes {
noChangeAspect?: number; readonly noChangeAspect?: number;
noChangeArrowheads?: number; readonly noChangeArrowheads?: number;
} }
export class PicLocksAttributes extends XmlAttributeComponent<IPicLocksAttributes> { export class PicLocksAttributes extends XmlAttributeComponent<IPicLocksAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
noChangeAspect: "noChangeAspect", noChangeAspect: "noChangeAspect",
noChangeArrowheads: "noChangeArrowheads", noChangeArrowheads: "noChangeArrowheads",
}; };

View File

@ -1,13 +1,13 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface INonVisualPropertiesAttributes { export interface INonVisualPropertiesAttributes {
id?: number; readonly id?: number;
name?: string; readonly name?: string;
descr?: string; readonly descr?: string;
} }
export class NonVisualPropertiesAttributes extends XmlAttributeComponent<INonVisualPropertiesAttributes> { export class NonVisualPropertiesAttributes extends XmlAttributeComponent<INonVisualPropertiesAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
id: "id", id: "id",
name: "name", name: "name",
descr: "desc", descr: "desc",

View File

@ -1,11 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IPicAttributes { export interface IPicAttributes {
xmlns?: string; readonly xmlns?: string;
} }
export class PicAttributes extends XmlAttributeComponent<IPicAttributes> { export class PicAttributes extends XmlAttributeComponent<IPicAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
xmlns: "xmlns:pic", xmlns: "xmlns:pic",
}; };
} }

View File

@ -1,12 +1,12 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IExtentsAttributes { export interface IExtentsAttributes {
cx?: number; readonly cx?: number;
cy?: number; readonly cy?: number;
} }
export class ExtentsAttributes extends XmlAttributeComponent<IExtentsAttributes> { export class ExtentsAttributes extends XmlAttributeComponent<IExtentsAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
cx: "cx", cx: "cx",
cy: "cy", cy: "cy",
}; };

View File

@ -1,12 +1,12 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IOffsetAttributes { export interface IOffsetAttributes {
x?: number; readonly x?: number;
y?: number; readonly y?: number;
} }
export class OffsetAttributes extends XmlAttributeComponent<IOffsetAttributes> { export class OffsetAttributes extends XmlAttributeComponent<IOffsetAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
x: "x", x: "x",
y: "y", y: "y",
}; };

View File

@ -1,11 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IPresetGeometryAttributes { export interface IPresetGeometryAttributes {
prst?: string; readonly prst?: string;
} }
export class PresetGeometryAttributes extends XmlAttributeComponent<IPresetGeometryAttributes> { export class PresetGeometryAttributes extends XmlAttributeComponent<IPresetGeometryAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
prst: "prst", prst: "prst",
}; };
} }

View File

@ -1,11 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IShapePropertiesAttributes { export interface IShapePropertiesAttributes {
bwMode?: string; readonly bwMode?: string;
} }
export class ShapePropertiesAttributes extends XmlAttributeComponent<IShapePropertiesAttributes> { export class ShapePropertiesAttributes extends XmlAttributeComponent<IShapePropertiesAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
bwMode: "bwMode", bwMode: "bwMode",
}; };
} }

View File

@ -2,11 +2,11 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { GraphicData } from "./graphic-data"; import { GraphicData } from "./graphic-data";
interface IGraphicProperties { interface IGraphicProperties {
a: string; readonly a: string;
} }
class GraphicAttributes extends XmlAttributeComponent<IGraphicProperties> { class GraphicAttributes extends XmlAttributeComponent<IGraphicProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
a: "xmlns:a", a: "xmlns:a",
}; };
} }

View File

@ -5,7 +5,7 @@ import { IDistance } from "../drawing";
export interface IInlineAttributes extends IDistance {} export interface IInlineAttributes extends IDistance {}
export class InlineAttributes extends XmlAttributeComponent<IInlineAttributes> { export class InlineAttributes extends XmlAttributeComponent<IInlineAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
distT: "distT", distT: "distT",
distB: "distB", distB: "distB",
distL: "distL", distL: "distL",

View File

@ -16,7 +16,7 @@ export enum WrapTextOption {
} }
export interface ITextWrapping { export interface ITextWrapping {
textWrapStyle: TextWrapStyle; readonly textWrapStyle: TextWrapStyle;
wrapTextOption?: WrapTextOption; readonly wrapTextOption?: WrapTextOption;
distanceFromText?: IDistance; readonly distanceFromText?: IDistance;
} }

View File

@ -4,11 +4,11 @@ import { ITextWrapping, WrapTextOption } from ".";
import { IDistance } from "../drawing"; import { IDistance } from "../drawing";
interface IWrapSquareAttributes extends IDistance { interface IWrapSquareAttributes extends IDistance {
wrapText?: WrapTextOption; readonly wrapText?: WrapTextOption;
} }
class WrapSquareAttributes extends XmlAttributeComponent<IWrapSquareAttributes> { class WrapSquareAttributes extends XmlAttributeComponent<IWrapSquareAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
distT: "distT", distT: "distT",
distB: "distB", distB: "distB",
distL: "distL", distL: "distL",

View File

@ -3,25 +3,25 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { IDistance } from "../drawing"; import { IDistance } from "../drawing";
interface IWrapTightAttributes { interface IWrapTightAttributes {
distT?: number; readonly distT?: number;
distB?: number; readonly distB?: number;
} }
class WrapTightAttributes extends XmlAttributeComponent<IWrapTightAttributes> { class WrapTightAttributes extends XmlAttributeComponent<IWrapTightAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
distT: "distT", distT: "distT",
distB: "distB", distB: "distB",
}; };
} }
export class WrapTight extends XmlComponent { export class WrapTight extends XmlComponent {
constructor(distanceFromText?: IDistance) { constructor(
super("wp:wrapTight"); distanceFromText: IDistance = {
distanceFromText = distanceFromText || {
distT: 0, distT: 0,
distB: 0, distB: 0,
}; },
) {
super("wp:wrapTight");
this.root.push( this.root.push(
new WrapTightAttributes({ new WrapTightAttributes({

View File

@ -3,25 +3,25 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { IDistance } from "../drawing"; import { IDistance } from "../drawing";
interface IWrapTopAndBottomAttributes { interface IWrapTopAndBottomAttributes {
distT?: number; readonly distT?: number;
distB?: number; readonly distB?: number;
} }
class WrapTopAndBottomAttributes extends XmlAttributeComponent<IWrapTopAndBottomAttributes> { class WrapTopAndBottomAttributes extends XmlAttributeComponent<IWrapTopAndBottomAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
distT: "distT", distT: "distT",
distB: "distB", distB: "distB",
}; };
} }
export class WrapTopAndBottom extends XmlComponent { export class WrapTopAndBottom extends XmlComponent {
constructor(distanceFromText?: IDistance) { constructor(
super("wp:wrapTopAndBottom"); distanceFromText: IDistance = {
distanceFromText = distanceFromText || {
distT: 0, distT: 0,
distB: 0, distB: 0,
}; },
) {
super("wp:wrapTopAndBottom");
this.root.push( this.root.push(
new WrapTopAndBottomAttributes({ new WrapTopAndBottomAttributes({

View File

@ -1,7 +1,7 @@
import { IDocumentTemplate } from "../import-dotx"; import { IDocumentTemplate } from "../import-dotx";
export interface IFileProperties { export interface IFileProperties {
template?: IDocumentTemplate; readonly template?: IDocumentTemplate;
} }
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432 // Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432

View File

@ -25,6 +25,7 @@ import { Table } from "./table";
import { TableOfContents } from "./table-of-contents"; import { TableOfContents } from "./table-of-contents";
export class File { export class File {
// tslint:disable-next-line:readonly-keyword
private currentRelationshipId: number = 1; private currentRelationshipId: number = 1;
private readonly document: Document; private readonly document: Document;
@ -39,6 +40,7 @@ export class File {
private readonly settings: Settings; private readonly settings: Settings;
private readonly contentTypes: ContentTypes; private readonly contentTypes: ContentTypes;
private readonly appProperties: AppProperties; private readonly appProperties: AppProperties;
// tslint:disable-next-line:readonly-keyword
private styles: Styles; private styles: Styles;
constructor( constructor(
@ -95,13 +97,13 @@ export class File {
this.createFooter(); this.createFooter();
} }
sectionPropertiesOptions = { const newSectionPropertiesOptions = {
...sectionPropertiesOptions, ...sectionPropertiesOptions,
headers: this.groupHeaders(this.headers, sectionPropertiesOptions.headers), headers: this.groupHeaders(this.headers, sectionPropertiesOptions.headers),
footers: this.groupFooters(this.footers, sectionPropertiesOptions.footers), footers: this.groupFooters(this.footers, sectionPropertiesOptions.footers),
}; };
this.document = new Document(sectionPropertiesOptions); this.document = new Document(newSectionPropertiesOptions);
this.settings = new Settings(); this.settings = new Settings();
} }
@ -139,8 +141,8 @@ export class File {
} }
public createHyperlink(link: string, text?: string): Hyperlink { public createHyperlink(link: string, text?: string): Hyperlink {
text = text === undefined ? link : text; const newText = text === undefined ? link : text;
const hyperlink = new Hyperlink(text, this.docRelationships.RelationshipCount); const hyperlink = new Hyperlink(newText, this.docRelationships.RelationshipCount);
this.docRelationships.createRelationship( this.docRelationships.createRelationship(
hyperlink.linkId, hyperlink.linkId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
@ -151,16 +153,16 @@ export class File {
} }
public createInternalHyperLink(anchor: string, text?: string): Hyperlink { public createInternalHyperLink(anchor: string, text?: string): Hyperlink {
text = text === undefined ? anchor : text; const newText = text === undefined ? anchor : text;
const hyperlink = new Hyperlink(text, this.docRelationships.RelationshipCount, anchor); const hyperlink = new Hyperlink(newText, this.docRelationships.RelationshipCount, anchor);
// NOTE: unlike File#createHyperlink(), since the link is to an internal bookmark // NOTE: unlike File#createHyperlink(), since the link is to an internal bookmark
// we don't need to create a new relationship. // we don't need to create a new relationship.
return hyperlink; return hyperlink;
} }
public createBookmark(name: string, text?: string): Bookmark { public createBookmark(name: string, text?: string): Bookmark {
text = text === undefined ? name : text; const newText = text === undefined ? name : text;
const bookmark = new Bookmark(name, text, this.docRelationships.RelationshipCount); const bookmark = new Bookmark(name, newText, this.docRelationships.RelationshipCount);
return bookmark; return bookmark;
} }

View File

@ -8,8 +8,8 @@ import { Relationships } from "./relationships";
import { Table } from "./table"; import { Table } from "./table";
export interface IDocumentFooter { export interface IDocumentFooter {
footer: FooterWrapper; readonly footer: FooterWrapper;
type: FooterReferenceType; readonly type: FooterReferenceType;
} }
export class FooterWrapper { export class FooterWrapper {

View File

@ -1,32 +1,32 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IFooterAttributesProperties { export interface IFooterAttributesProperties {
wpc?: string; readonly wpc?: string;
mc?: string; readonly mc?: string;
o?: string; readonly o?: string;
r?: string; readonly r?: string;
m?: string; readonly m?: string;
v?: string; readonly v?: string;
wp14?: string; readonly wp14?: string;
wp?: string; readonly wp?: string;
w10?: string; readonly w10?: string;
w?: string; readonly w?: string;
w14?: string; readonly w14?: string;
w15?: string; readonly w15?: string;
wpg?: string; readonly wpg?: string;
wpi?: string; readonly wpi?: string;
wne?: string; readonly wne?: string;
wps?: string; readonly wps?: string;
cp?: string; readonly cp?: string;
dc?: string; readonly dc?: string;
dcterms?: string; readonly dcterms?: string;
dcmitype?: string; readonly dcmitype?: string;
xsi?: string; readonly xsi?: string;
type?: string; readonly type?: string;
} }
export class FooterAttributes extends XmlAttributeComponent<IFooterAttributesProperties> { export class FooterAttributes extends XmlAttributeComponent<IFooterAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
wpc: "xmlns:wpc", wpc: "xmlns:wpc",
mc: "xmlns:mc", mc: "xmlns:mc",
o: "xmlns:o", o: "xmlns:o",

View File

@ -1,12 +1,12 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IFootnoteAttributesProperties { export interface IFootnoteAttributesProperties {
type?: string; readonly type?: string;
id: number; readonly id: number;
} }
export class FootnoteAttributes extends XmlAttributeComponent<IFootnoteAttributesProperties> { export class FootnoteAttributes extends XmlAttributeComponent<IFootnoteAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
type: "w:type", type: "w:type",
id: "w:id", id: "w:id",
}; };

View File

@ -3,11 +3,11 @@ import { Style } from "file/paragraph/run/style";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export interface IFootNoteReferenceRunAttributesProperties { export interface IFootNoteReferenceRunAttributesProperties {
id: number; readonly id: number;
} }
export class FootNoteReferenceRunAttributes extends XmlAttributeComponent<IFootNoteReferenceRunAttributesProperties> { export class FootNoteReferenceRunAttributes extends XmlAttributeComponent<IFootNoteReferenceRunAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
id: "w:id", id: "w:id",
}; };
} }

View File

@ -1,27 +1,27 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IFootnotesAttributesProperties { export interface IFootnotesAttributesProperties {
wpc?: string; readonly wpc?: string;
mc?: string; readonly mc?: string;
o?: string; readonly o?: string;
r?: string; readonly r?: string;
m?: string; readonly m?: string;
v?: string; readonly v?: string;
wp14?: string; readonly wp14?: string;
wp?: string; readonly wp?: string;
w10?: string; readonly w10?: string;
w?: string; readonly w?: string;
w14?: string; readonly w14?: string;
w15?: string; readonly w15?: string;
wpg?: string; readonly wpg?: string;
wpi?: string; readonly wpi?: string;
wne?: string; readonly wne?: string;
wps?: string; readonly wps?: string;
Ignorable?: string; readonly Ignorable?: string;
} }
export class FootnotesAttributes extends XmlAttributeComponent<IFootnotesAttributesProperties> { export class FootnotesAttributes extends XmlAttributeComponent<IFootnotesAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
wpc: "xmlns:wpc", wpc: "xmlns:wpc",
mc: "xmlns:mc", mc: "xmlns:mc",
o: "xmlns:o", o: "xmlns:o",

View File

@ -6,12 +6,13 @@ import { SeperatorRun } from "./footnote/run/seperator-run";
import { FootnotesAttributes } from "./footnotes-attributes"; import { FootnotesAttributes } from "./footnotes-attributes";
export class FootNotes extends XmlComponent { export class FootNotes extends XmlComponent {
private counter: number; // tslint:disable-next-line:readonly-keyword
private currentId: number;
constructor() { constructor() {
super("w:footnotes"); super("w:footnotes");
this.counter = 1; this.currentId = 1;
this.root.push( this.root.push(
new FootnotesAttributes({ new FootnotesAttributes({
@ -61,10 +62,10 @@ export class FootNotes extends XmlComponent {
} }
public createFootNote(paragraph: Paragraph): void { public createFootNote(paragraph: Paragraph): void {
const footnote = new Footnote(this.counter); const footnote = new Footnote(this.currentId);
footnote.addParagraph(paragraph); footnote.addParagraph(paragraph);
this.root.push(footnote); this.root.push(footnote);
this.counter++; this.currentId++;
} }
} }

View File

@ -8,8 +8,8 @@ import { Relationships } from "./relationships";
import { Table } from "./table"; import { Table } from "./table";
export interface IDocumentHeader { export interface IDocumentHeader {
header: HeaderWrapper; readonly header: HeaderWrapper;
type: HeaderReferenceType; readonly type: HeaderReferenceType;
} }
export class HeaderWrapper { export class HeaderWrapper {

View File

@ -1,43 +1,43 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IHeaderAttributesProperties { export interface IHeaderAttributesProperties {
wpc?: string; readonly wpc?: string;
mc?: string; readonly mc?: string;
o?: string; readonly o?: string;
r?: string; readonly r?: string;
m?: string; readonly m?: string;
v?: string; readonly v?: string;
wp14?: string; readonly wp14?: string;
wp?: string; readonly wp?: string;
w10?: string; readonly w10?: string;
w?: string; readonly w?: string;
w14?: string; readonly w14?: string;
w15?: string; readonly w15?: string;
wpg?: string; readonly wpg?: string;
wpi?: string; readonly wpi?: string;
wne?: string; readonly wne?: string;
wps?: string; readonly wps?: string;
cp?: string; readonly cp?: string;
dc?: string; readonly dc?: string;
dcterms?: string; readonly dcterms?: string;
dcmitype?: string; readonly dcmitype?: string;
xsi?: string; readonly xsi?: string;
type?: string; readonly type?: string;
cx?: string; readonly cx?: string;
cx1?: string; readonly cx1?: string;
cx2?: string; readonly cx2?: string;
cx3?: string; readonly cx3?: string;
cx4?: string; readonly cx4?: string;
cx5?: string; readonly cx5?: string;
cx6?: string; readonly cx6?: string;
cx7?: string; readonly cx7?: string;
cx8?: string; readonly cx8?: string;
w16cid: string; readonly w16cid: string;
w16se: string; readonly w16se: string;
} }
export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesProperties> { export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
wpc: "xmlns:wpc", wpc: "xmlns:wpc",
mc: "xmlns:mc", mc: "xmlns:mc",
o: "xmlns:o", o: "xmlns:o",

View File

@ -1,20 +1,20 @@
export interface IMediaDataDimensions { export interface IMediaDataDimensions {
pixels: { readonly pixels: {
x: number; readonly x: number;
y: number; readonly y: number;
}; };
emus: { readonly emus: {
x: number; readonly x: number;
y: number; readonly y: number;
}; };
} }
export interface IMediaData { export interface IMediaData {
referenceId: number; readonly referenceId: number;
stream: Buffer | Uint8Array | ArrayBuffer; readonly stream: Buffer | Uint8Array | ArrayBuffer;
path?: string; readonly path?: string;
fileName: string; readonly fileName: string;
dimensions: IMediaDataDimensions; readonly dimensions: IMediaDataDimensions;
} }
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432 // Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432

View File

@ -5,6 +5,7 @@ import { IMediaData } from "./data";
import { Image } from "./image"; import { Image } from "./image";
interface IHackedFile { interface IHackedFile {
// tslint:disable-next-line:readonly-keyword
currentRelationshipId: number; currentRelationshipId: number;
} }
@ -78,17 +79,15 @@ export class Media {
private createMedia( private createMedia(
key: string, key: string,
relationshipsCount: number, relationshipsCount: number,
dimensions: { width: number; height: number }, dimensions: { readonly width: number; readonly height: number },
data: Buffer | string | Uint8Array | ArrayBuffer, data: Buffer | string | Uint8Array | ArrayBuffer,
filePath?: string, filePath?: string,
): IMediaData { ): IMediaData {
if (typeof data === "string") { const newData = typeof data === "string" ? this.convertDataURIToBinary(data) : data;
data = this.convertDataURIToBinary(data);
}
const imageData = { const imageData: IMediaData = {
referenceId: relationshipsCount, referenceId: relationshipsCount,
stream: data, stream: newData,
path: filePath, path: filePath,
fileName: key, fileName: key,
dimensions: { dimensions: {

View File

@ -3,19 +3,19 @@ import { Level } from "./level";
import { MultiLevelType } from "./multi-level-type"; import { MultiLevelType } from "./multi-level-type";
interface IAbstractNumberingAttributesProperties { interface IAbstractNumberingAttributesProperties {
abstractNumId?: number; readonly abstractNumId?: number;
restartNumberingAfterBreak?: number; readonly restartNumberingAfterBreak?: number;
} }
class AbstractNumberingAttributes extends XmlAttributeComponent<IAbstractNumberingAttributesProperties> { class AbstractNumberingAttributes extends XmlAttributeComponent<IAbstractNumberingAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
abstractNumId: "w:abstractNumId", abstractNumId: "w:abstractNumId",
restartNumberingAfterBreak: "w15:restartNumberingAfterBreak", restartNumberingAfterBreak: "w15:restartNumberingAfterBreak",
}; };
} }
export class AbstractNumbering extends XmlComponent { export class AbstractNumbering extends XmlComponent {
public id: number; public readonly id: number;
constructor(id: number) { constructor(id: number) {
super("w:abstractNum"); super("w:abstractNum");

View File

@ -1,16 +1,27 @@
import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
import * as paragraph from "../paragraph/formatting"; import {
Alignment,
AlignmentOptions,
Indent,
ISpacingProperties,
KeepLines,
KeepNext,
LeftTabStop,
MaxRightTabStop,
Spacing,
ThematicBreak,
} from "../paragraph/formatting";
import { ParagraphProperties } from "../paragraph/properties"; import { ParagraphProperties } from "../paragraph/properties";
import * as formatting from "../paragraph/run/formatting"; import * as formatting from "../paragraph/run/formatting";
import { RunProperties } from "../paragraph/run/properties"; import { RunProperties } from "../paragraph/run/properties";
interface ILevelAttributesProperties { interface ILevelAttributesProperties {
ilvl?: number; readonly ilvl?: number;
tentative?: number; readonly tentative?: number;
} }
class LevelAttributes extends XmlAttributeComponent<ILevelAttributesProperties> { class LevelAttributes extends XmlAttributeComponent<ILevelAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
ilvl: "w:ilvl", ilvl: "w:ilvl",
tentative: "w15:tentative", tentative: "w15:tentative",
}; };
@ -190,57 +201,57 @@ export class LevelBase extends XmlComponent {
// --------------------- Paragraph formatting ------------------------ // // --------------------- Paragraph formatting ------------------------ //
public center(): Level { public center(): Level {
this.addParagraphProperty(new paragraph.Alignment("center")); this.addParagraphProperty(new Alignment(AlignmentOptions.CENTER));
return this; return this;
} }
public left(): Level { public left(): Level {
this.addParagraphProperty(new paragraph.Alignment("left")); this.addParagraphProperty(new Alignment(AlignmentOptions.LEFT));
return this; return this;
} }
public right(): Level { public right(): Level {
this.addParagraphProperty(new paragraph.Alignment("right")); this.addParagraphProperty(new Alignment(AlignmentOptions.RIGHT));
return this; return this;
} }
public justified(): Level { public justified(): Level {
this.addParagraphProperty(new paragraph.Alignment("both")); this.addParagraphProperty(new Alignment(AlignmentOptions.BOTH));
return this; return this;
} }
public thematicBreak(): Level { public thematicBreak(): Level {
this.addParagraphProperty(new paragraph.ThematicBreak()); this.addParagraphProperty(new ThematicBreak());
return this; return this;
} }
public maxRightTabStop(): Level { public maxRightTabStop(): Level {
this.addParagraphProperty(new paragraph.MaxRightTabStop()); this.addParagraphProperty(new MaxRightTabStop());
return this; return this;
} }
public leftTabStop(position: number): Level { public leftTabStop(position: number): Level {
this.addParagraphProperty(new paragraph.LeftTabStop(position)); this.addParagraphProperty(new LeftTabStop(position));
return this; return this;
} }
public indent(attrs: object): Level { public indent(attrs: object): Level {
this.addParagraphProperty(new paragraph.Indent(attrs)); this.addParagraphProperty(new Indent(attrs));
return this; return this;
} }
public spacing(params: paragraph.ISpacingProperties): Level { public spacing(params: ISpacingProperties): Level {
this.addParagraphProperty(new paragraph.Spacing(params)); this.addParagraphProperty(new Spacing(params));
return this; return this;
} }
public keepNext(): Level { public keepNext(): Level {
this.addParagraphProperty(new paragraph.KeepNext()); this.addParagraphProperty(new KeepNext());
return this; return this;
} }
public keepLines(): Level { public keepLines(): Level {
this.addParagraphProperty(new paragraph.KeepLines()); this.addParagraphProperty(new KeepLines());
return this; return this;
} }
} }

View File

@ -13,15 +13,15 @@ class AbstractNumId extends XmlComponent {
} }
interface INumAttributesProperties { interface INumAttributesProperties {
numId: number; readonly numId: number;
} }
class NumAttributes extends XmlAttributeComponent<INumAttributesProperties> { class NumAttributes extends XmlAttributeComponent<INumAttributesProperties> {
protected xmlKeys = { numId: "w:numId" }; protected readonly xmlKeys = { numId: "w:numId" };
} }
export class Num extends XmlComponent { export class Num extends XmlComponent {
public id: number; public readonly id: number;
constructor(numId: number, abstractNumId: number) { constructor(numId: number, abstractNumId: number) {
super("w:num"); super("w:num");
@ -41,12 +41,12 @@ export class Num extends XmlComponent {
} }
} }
class LevelOverrideAttributes extends XmlAttributeComponent<{ ilvl: number }> { class LevelOverrideAttributes extends XmlAttributeComponent<{ readonly ilvl: number }> {
protected xmlKeys = { ilvl: "w:ilvl" }; protected readonly xmlKeys = { ilvl: "w:ilvl" };
} }
export class LevelOverride extends XmlComponent { export class LevelOverride extends XmlComponent {
private lvl?: LevelForOverride; private readonly lvl: LevelForOverride;
constructor(private readonly levelNum: number, start?: number) { constructor(private readonly levelNum: number, start?: number) {
super("w:lvlOverride"); super("w:lvlOverride");
@ -54,23 +54,18 @@ export class LevelOverride extends XmlComponent {
if (start !== undefined) { if (start !== undefined) {
this.root.push(new StartOverride(start)); this.root.push(new StartOverride(start));
} }
this.lvl = new LevelForOverride(this.levelNum);
this.root.push(this.lvl);
} }
public get Level(): LevelForOverride { public get Level(): LevelForOverride {
let lvl: LevelForOverride; return this.lvl;
if (!this.lvl) {
lvl = new LevelForOverride(this.levelNum);
this.root.push(lvl);
this.lvl = lvl;
} else {
lvl = this.lvl;
}
return lvl;
} }
} }
class StartOverrideAttributes extends XmlAttributeComponent<{ val: number }> { class StartOverrideAttributes extends XmlAttributeComponent<{ readonly val: number }> {
protected xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
class StartOverride extends XmlComponent { class StartOverride extends XmlComponent {

View File

@ -378,14 +378,69 @@ describe("concrete numbering", () => {
it("sets a new override level for the given level number", () => { it("sets a new override level for the given level number", () => {
concreteNumbering.overrideLevel(3); concreteNumbering.overrideLevel(3);
const tree = new Formatter().format(concreteNumbering); const tree = new Formatter().format(concreteNumbering);
expect(tree["w:num"]).to.include({ "w:lvlOverride": [{ _attr: { "w:ilvl": 3 } }] }); expect(tree["w:num"]).to.include({
"w:lvlOverride": [
{
_attr: {
"w:ilvl": 3,
},
},
{
"w:lvl": [
{
_attr: {
"w:ilvl": 3,
"w15:tentative": 1,
},
},
{
"w:pPr": [],
},
{
"w:rPr": [],
},
],
},
],
});
}); });
it("sets the startOverride element if start is given", () => { it("sets the startOverride element if start is given", () => {
concreteNumbering.overrideLevel(1, 9); concreteNumbering.overrideLevel(1, 9);
const tree = new Formatter().format(concreteNumbering); const tree = new Formatter().format(concreteNumbering);
expect(tree["w:num"]).to.include({ expect(tree["w:num"]).to.include({
"w:lvlOverride": [{ _attr: { "w:ilvl": 1 } }, { "w:startOverride": [{ _attr: { "w:val": 9 } }] }], "w:lvlOverride": [
{
_attr: {
"w:ilvl": 1,
},
},
{
"w:startOverride": [
{
_attr: {
"w:val": 9,
},
},
],
},
{
"w:lvl": [
{
_attr: {
"w:ilvl": 1,
"w15:tentative": 1,
},
},
{
"w:pPr": [],
},
{
"w:rPr": [],
},
],
},
],
}); });
}); });

View File

@ -5,6 +5,7 @@ import { AbstractNumbering } from "./abstract-numbering";
import { Num } from "./num"; import { Num } from "./num";
export class Numbering extends XmlComponent { export class Numbering extends XmlComponent {
// tslint:disable-next-line:readonly-keyword
private nextId: number; private nextId: number;
private readonly abstractNumbering: XmlComponent[] = []; private readonly abstractNumbering: XmlComponent[] = [];

View File

@ -1,10 +1,18 @@
// http://officeopenxml.com/WPalignment.php // http://officeopenxml.com/WPalignment.php
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export type AlignmentOptions = "start" | "end" | "center" | "both" | "distribute" | "left" | "right"; export enum AlignmentOptions {
START = "start",
END = "end",
CENTER = "center",
BOTH = "both",
DISTRIBUTE = "distribute",
LEFT = "left",
RIGHT = "right",
}
export class AlignmentAttributes extends XmlAttributeComponent<{ val: AlignmentOptions }> { export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentOptions }> {
protected xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
export class Alignment extends XmlComponent { export class Alignment extends XmlComponent {

View File

@ -2,15 +2,15 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export interface IIndentAttributesProperties { export interface IIndentAttributesProperties {
left?: number; readonly left?: number;
hanging?: number; readonly hanging?: number;
firstLine?: number; readonly firstLine?: number;
start?: number; readonly start?: number;
end?: number; readonly end?: number;
} }
class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties> { class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
left: "w:left", left: "w:left",
hanging: "w:hanging", hanging: "w:hanging",
firstLine: "w:firstLine", firstLine: "w:firstLine",

View File

@ -2,14 +2,14 @@
import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
export interface ISpacingProperties { export interface ISpacingProperties {
after?: number; readonly after?: number;
before?: number; readonly before?: number;
line?: number; readonly line?: number;
lineRule?: string; readonly lineRule?: string;
} }
class SpacingAttributes extends XmlAttributeComponent<ISpacingProperties> { class SpacingAttributes extends XmlAttributeComponent<ISpacingProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
after: "w:after", after: "w:after",
before: "w:before", before: "w:before",
line: "w:line", line: "w:line",

View File

@ -2,7 +2,7 @@ import { assert } from "chai";
import { Utility } from "tests/utility"; import { Utility } from "tests/utility";
import { LeftTabStop, MaxRightTabStop, RightTabStop } from "./tab-stop"; import { LeaderType, LeftTabStop, MaxRightTabStop, RightTabStop } from "./tab-stop";
describe("LeftTabStop", () => { describe("LeftTabStop", () => {
let tabStop: LeftTabStop; let tabStop: LeftTabStop;
@ -32,7 +32,7 @@ describe("RightTabStop", () => {
let tabStop: RightTabStop; let tabStop: RightTabStop;
beforeEach(() => { beforeEach(() => {
tabStop = new RightTabStop(100, "dot"); tabStop = new RightTabStop(100, LeaderType.DOT);
}); });
describe("#constructor()", () => { describe("#constructor()", () => {

View File

@ -8,11 +8,32 @@ export class TabStop extends XmlComponent {
} }
} }
export type TabValue = "left" | "right" | "center" | "bar" | "clear" | "decimal" | "end" | "num" | "start"; export enum TabValue {
export type LeaderType = "dot" | "hyphen" | "middleDot" | "none" | "underscore"; LEFT = "left",
RIGHT = "right",
CENTER = "center",
BAR = "bar",
CLEAR = "clear",
DECIMAL = "decimal",
END = "end",
NUM = "num",
START = "start",
}
export class TabAttributes extends XmlAttributeComponent<{ val: TabValue; pos: string | number; leader?: LeaderType }> { export enum LeaderType {
protected xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" }; DOT = "dot",
HYPHEN = "hyphen",
MIDDLE_DOT = "middleDot",
NONE = "none",
UNDERSCORE = "underscore",
}
export class TabAttributes extends XmlAttributeComponent<{
readonly val: TabValue;
readonly pos: string | number;
readonly leader?: LeaderType;
}> {
protected readonly xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" };
} }
export class TabStopItem extends XmlComponent { export class TabStopItem extends XmlComponent {
@ -30,24 +51,24 @@ export class TabStopItem extends XmlComponent {
export class MaxRightTabStop extends TabStop { export class MaxRightTabStop extends TabStop {
constructor(leader?: LeaderType) { constructor(leader?: LeaderType) {
super(new TabStopItem("right", 9026, leader)); super(new TabStopItem(TabValue.RIGHT, 9026, leader));
} }
} }
export class LeftTabStop extends TabStop { export class LeftTabStop extends TabStop {
constructor(position: number, leader?: LeaderType) { constructor(position: number, leader?: LeaderType) {
super(new TabStopItem("left", position, leader)); super(new TabStopItem(TabValue.LEFT, position, leader));
} }
} }
export class RightTabStop extends TabStop { export class RightTabStop extends TabStop {
constructor(position: number, leader?: LeaderType) { constructor(position: number, leader?: LeaderType) {
super(new TabStopItem("right", position, leader)); super(new TabStopItem(TabValue.RIGHT, position, leader));
} }
} }
export class CenterTabStop extends TabStop { export class CenterTabStop extends TabStop {
constructor(position: number, leader?: LeaderType) { constructor(position: number, leader?: LeaderType) {
super(new TabStopItem("center", position, leader)); super(new TabStopItem(TabValue.CENTER, position, leader));
} }
} }

View File

@ -1,23 +1,23 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IBookmarkStartAttributesProperties { export interface IBookmarkStartAttributesProperties {
id: string; readonly id: string;
name: string; readonly name: string;
} }
export class BookmarkStartAttributes extends XmlAttributeComponent<IBookmarkStartAttributesProperties> { export class BookmarkStartAttributes extends XmlAttributeComponent<IBookmarkStartAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
id: "w:id", id: "w:id",
name: "w:name", name: "w:name",
}; };
} }
export interface IBookmarkEndAttributesProperties { export interface IBookmarkEndAttributesProperties {
id: string; readonly id: string;
} }
export class BookmarkEndAttributes extends XmlAttributeComponent<IBookmarkEndAttributesProperties> { export class BookmarkEndAttributes extends XmlAttributeComponent<IBookmarkEndAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
id: "w:id", id: "w:id",
}; };
} }

View File

@ -1,16 +1,12 @@
// http://officeopenxml.com/WPbookmark.php // http://officeopenxml.com/WPbookmark.php
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
import { TextRun } from "../run"; import { TextRun } from "../run";
import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attributes"; import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attributes";
export class Bookmark { export class Bookmark {
public linkId: number; public readonly linkId: number;
public readonly start: BookmarkStart; public readonly start: BookmarkStart;
public readonly text: TextRun; public readonly text: TextRun;
public readonly end: BookmarkEnd; public readonly end: BookmarkEnd;
constructor(name: string, text: string, relationshipsCount: number) { constructor(name: string, text: string, relationshipsCount: number) {
@ -23,7 +19,7 @@ export class Bookmark {
} }
export class BookmarkStart extends XmlComponent { export class BookmarkStart extends XmlComponent {
public linkId: number; public readonly linkId: number;
constructor(name: string, relationshipsCount: number) { constructor(name: string, relationshipsCount: number) {
super("w:bookmarkStart"); super("w:bookmarkStart");
@ -39,7 +35,7 @@ export class BookmarkStart extends XmlComponent {
} }
export class BookmarkEnd extends XmlComponent { export class BookmarkEnd extends XmlComponent {
public linkId: number; public readonly linkId: number;
constructor(relationshipsCount: number) { constructor(relationshipsCount: number) {
super("w:bookmarkEnd"); super("w:bookmarkEnd");

View File

@ -1,13 +1,13 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IHyperlinkAttributesProperties { export interface IHyperlinkAttributesProperties {
id?: string; readonly id?: string;
anchor?: string; readonly anchor?: string;
history: number; readonly history: number;
} }
export class HyperlinkAttributes extends XmlAttributeComponent<IHyperlinkAttributesProperties> { export class HyperlinkAttributes extends XmlAttributeComponent<IHyperlinkAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
id: "r:id", id: "r:id",
history: "w:history", history: "w:history",
anchor: "w:anchor", anchor: "w:anchor",

View File

@ -1,11 +1,10 @@
// http://officeopenxml.com/WPhyperlink.php // http://officeopenxml.com/WPhyperlink.php
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
import { TextRun } from "../run"; import { TextRun } from "../run";
import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes"; import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes";
export class Hyperlink extends XmlComponent { export class Hyperlink extends XmlComponent {
public linkId: number; public readonly linkId: number;
constructor(text: string, relationshipsCount: number, anchor?: string) { constructor(text: string, relationshipsCount: number, anchor?: string) {
super("w:hyperlink"); super("w:hyperlink");
@ -14,14 +13,10 @@ export class Hyperlink extends XmlComponent {
const props: IHyperlinkAttributesProperties = { const props: IHyperlinkAttributesProperties = {
history: 1, history: 1,
anchor: anchor ? anchor : undefined,
id: !anchor ? `rId${this.linkId}` : undefined,
}; };
if (anchor) {
props.anchor = anchor;
} else {
props.id = `rId${this.linkId}`;
}
const attributes = new HyperlinkAttributes(props); const attributes = new HyperlinkAttributes(props);
this.root.push(attributes); this.root.push(attributes);
this.root.push(new TextRun(text).style("Hyperlink")); this.root.push(new TextRun(text).style("Hyperlink"));

View File

@ -4,7 +4,7 @@ import { Image } from "file/media";
import { Num } from "file/numbering/num"; import { Num } from "file/numbering/num";
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
import { Alignment } from "./formatting/alignment"; import { Alignment, AlignmentOptions } from "./formatting/alignment";
import { Bidirectional } from "./formatting/bidirectional"; import { Bidirectional } from "./formatting/bidirectional";
import { Border, ThematicBreak } from "./formatting/border"; import { Border, ThematicBreak } from "./formatting/border";
import { IIndentAttributesProperties, Indent } from "./formatting/indent"; import { IIndentAttributesProperties, Indent } from "./formatting/indent";
@ -110,37 +110,37 @@ export class Paragraph extends XmlComponent {
} }
public center(): Paragraph { public center(): Paragraph {
this.properties.push(new Alignment("center")); this.properties.push(new Alignment(AlignmentOptions.CENTER));
return this; return this;
} }
public left(): Paragraph { public left(): Paragraph {
this.properties.push(new Alignment("left")); this.properties.push(new Alignment(AlignmentOptions.LEFT));
return this; return this;
} }
public right(): Paragraph { public right(): Paragraph {
this.properties.push(new Alignment("right")); this.properties.push(new Alignment(AlignmentOptions.RIGHT));
return this; return this;
} }
public start(): Paragraph { public start(): Paragraph {
this.properties.push(new Alignment("start")); this.properties.push(new Alignment(AlignmentOptions.START));
return this; return this;
} }
public end(): Paragraph { public end(): Paragraph {
this.properties.push(new Alignment("end")); this.properties.push(new Alignment(AlignmentOptions.END));
return this; return this;
} }
public distribute(): Paragraph { public distribute(): Paragraph {
this.properties.push(new Alignment("distribute")); this.properties.push(new Alignment(AlignmentOptions.DISTRIBUTE));
return this; return this;
} }
public justified(): Paragraph { public justified(): Paragraph {
this.properties.push(new Alignment("both")); this.properties.push(new Alignment(AlignmentOptions.BOTH));
return this; return this;
} }

View File

@ -3,7 +3,7 @@ import { XmlComponent } from "file/xml-components";
import { Border } from "./formatting/border"; import { Border } from "./formatting/border";
export class ParagraphProperties extends XmlComponent { export class ParagraphProperties extends XmlComponent {
public paragraphBorder: Border; public readonly paragraphBorder: Border;
constructor() { constructor() {
super("w:pPr"); super("w:pPr");

View File

@ -1,26 +1,32 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
class FidCharAttrs extends XmlAttributeComponent<{ type: "begin" | "end" | "separate"; dirty?: boolean }> { enum FieldCharacterType {
protected xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" }; BEGIN = "begin",
END = "end",
SEPARATE = "separate",
}
class FidCharAttrs extends XmlAttributeComponent<{ readonly type: FieldCharacterType; readonly dirty?: boolean }> {
protected readonly xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" };
} }
export class Begin extends XmlComponent { export class Begin extends XmlComponent {
constructor(dirty?: boolean) { constructor(dirty?: boolean) {
super("w:fldChar"); super("w:fldChar");
this.root.push(new FidCharAttrs({ type: "begin", dirty })); this.root.push(new FidCharAttrs({ type: FieldCharacterType.BEGIN, dirty }));
} }
} }
export class Separate extends XmlComponent { export class Separate extends XmlComponent {
constructor(dirty?: boolean) { constructor(dirty?: boolean) {
super("w:fldChar"); super("w:fldChar");
this.root.push(new FidCharAttrs({ type: "separate", dirty })); this.root.push(new FidCharAttrs({ type: FieldCharacterType.SEPARATE, dirty }));
} }
} }
export class End extends XmlComponent { export class End extends XmlComponent {
constructor(dirty?: boolean) { constructor(dirty?: boolean) {
super("w:fldChar"); super("w:fldChar");
this.root.push(new FidCharAttrs({ type: "end", dirty })); this.root.push(new FidCharAttrs({ type: FieldCharacterType.END, dirty }));
} }
} }

View File

@ -1,13 +1,14 @@
import { SpaceType } from "file/space-type";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> { class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
protected xmlKeys = { space: "xml:space" }; protected readonly xmlKeys = { space: "xml:space" };
} }
export class Page extends XmlComponent { export class Page extends XmlComponent {
constructor() { constructor() {
super("w:instrText"); super("w:instrText");
this.root.push(new TextAttributes({ space: "preserve" })); this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
this.root.push("PAGE"); this.root.push("PAGE");
} }
} }

View File

@ -18,15 +18,7 @@ export class PictureRun extends Run {
this.root.push(this.drawing); this.root.push(this.drawing);
} }
public scale(factorX: number, factorY?: number): void { public scale(factorX: number = 1, factorY: number = factorX): void {
if (!factorX) {
factorX = 1;
}
if (!factorY) {
factorY = factorX;
}
this.drawing.scale(factorX, factorY); this.drawing.scale(factorX, factorY);
} }
} }

View File

@ -1,13 +1,14 @@
import { SpaceType } from "file/space-type";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> { class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
protected xmlKeys = { space: "xml:space" }; protected readonly xmlKeys = { space: "xml:space" };
} }
export class Text extends XmlComponent { export class Text extends XmlComponent {
constructor(text: string) { constructor(text: string) {
super("w:t"); super("w:t");
this.root.push(new TextAttributes({ space: "preserve" })); this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
if (text) { if (text) {
this.root.push(text); this.root.push(text);
} }

View File

@ -1,15 +1,15 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
interface IRunFontAttributesProperties { interface IRunFontAttributesProperties {
ascii: string; readonly ascii: string;
cs: string; readonly cs: string;
eastAsia: string; readonly eastAsia: string;
hAnsi: string; readonly hAnsi: string;
hint?: string; readonly hint?: string;
} }
class RunFontAttributes extends XmlAttributeComponent<IRunFontAttributesProperties> { class RunFontAttributes extends XmlAttributeComponent<IRunFontAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
ascii: "w:ascii", ascii: "w:ascii",
cs: "w:cs", cs: "w:cs",
eastAsia: "w:eastAsia", eastAsia: "w:eastAsia",

View File

@ -25,7 +25,7 @@ import { Underline } from "./underline";
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class Run extends XmlComponent { export class Run extends XmlComponent {
protected properties: RunProperties; protected readonly properties: RunProperties;
constructor() { constructor() {
super("w:r"); super("w:r");

View File

@ -1,13 +1,9 @@
// http://officeopenxml.com/WPfieldInstructions.php // http://officeopenxml.com/WPfieldInstructions.php
import { SpaceType } from "file/space-type";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
enum SpaceType { class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
DEFAULT = "default", protected readonly xmlKeys = { space: "xml:space" };
PRESERVE = "preserve",
}
class TextAttributes extends XmlAttributeComponent<{ space: SpaceType }> {
protected xmlKeys = { space: "xml:space" };
} }
export class SequentialIdentifierInstruction extends XmlComponent { export class SequentialIdentifierInstruction extends XmlComponent {

View File

@ -1,7 +1,7 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
class StyleAttributes extends XmlAttributeComponent<{ val: string }> { class StyleAttributes extends XmlAttributeComponent<{ readonly val: string }> {
protected xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
export class Style extends XmlComponent { export class Style extends XmlComponent {

View File

@ -1,11 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IRelationshipsAttributesProperties { export interface IRelationshipsAttributesProperties {
xmlns: string; readonly xmlns: string;
} }
export class RelationshipsAttributes extends XmlAttributeComponent<IRelationshipsAttributesProperties> { export class RelationshipsAttributes extends XmlAttributeComponent<IRelationshipsAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
xmlns: "xmlns", xmlns: "xmlns",
}; };
} }

View File

@ -1,14 +1,14 @@
import { XmlAttributeComponent } from "file/xml-components"; import { XmlAttributeComponent } from "file/xml-components";
export interface IRelationshipAttributesProperties { export interface IRelationshipAttributesProperties {
id: string; readonly id: string;
type: string; readonly type: string;
target: string; readonly target: string;
targetMode?: string; readonly targetMode?: string;
} }
export class RelationshipAttributes extends XmlAttributeComponent<IRelationshipAttributesProperties> { export class RelationshipAttributes extends XmlAttributeComponent<IRelationshipAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
id: "Id", id: "Id",
type: "Type", type: "Type",
target: "Target", target: "Target",

View File

@ -1,26 +1,26 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { UpdateFields } from "./update-fields"; import { UpdateFields } from "./update-fields";
export interface ISettingsAttributesProperties { export interface ISettingsAttributesProperties {
wpc?: string; readonly wpc?: string;
mc?: string; readonly mc?: string;
o?: string; readonly o?: string;
r?: string; readonly r?: string;
m?: string; readonly m?: string;
v?: string; readonly v?: string;
wp14?: string; readonly wp14?: string;
wp?: string; readonly wp?: string;
w10?: string; readonly w10?: string;
w?: string; readonly w?: string;
w14?: string; readonly w14?: string;
w15?: string; readonly w15?: string;
wpg?: string; readonly wpg?: string;
wpi?: string; readonly wpi?: string;
wne?: string; readonly wne?: string;
wps?: string; readonly wps?: string;
Ignorable?: string; readonly Ignorable?: string;
} }
export class SettingsAttributes extends XmlAttributeComponent<ISettingsAttributesProperties> { export class SettingsAttributes extends XmlAttributeComponent<ISettingsAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
wpc: "xmlns:wpc", wpc: "xmlns:wpc",
mc: "xmlns:mc", mc: "xmlns:mc",
o: "xmlns:o", o: "xmlns:o",

View File

@ -1,9 +1,9 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export interface IUpdateFieldsAttributesProperties { export interface IUpdateFieldsAttributesProperties {
enabled: boolean; readonly enabled: boolean;
} }
export class UpdateFieldsAttributes extends XmlAttributeComponent<IUpdateFieldsAttributesProperties> { export class UpdateFieldsAttributes extends XmlAttributeComponent<IUpdateFieldsAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
enabled: "w:val", enabled: "w:val",
}; };
} }

4
src/file/space-type.ts Normal file
View File

@ -0,0 +1,4 @@
export enum SpaceType {
DEFAULT = "default",
PRESERVE = "preserve",
}

View File

@ -1,15 +1,15 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export interface ILatentStyleExceptionAttributesProperties { export interface ILatentStyleExceptionAttributesProperties {
name?: string; readonly name?: string;
uiPriority?: string; readonly uiPriority?: string;
qFormat?: string; readonly qFormat?: string;
semiHidden?: string; readonly semiHidden?: string;
unhideWhenUsed?: string; readonly unhideWhenUsed?: string;
} }
export class LatentStyleExceptionAttributes extends XmlAttributeComponent<ILatentStyleExceptionAttributesProperties> { export class LatentStyleExceptionAttributes extends XmlAttributeComponent<ILatentStyleExceptionAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
name: "w:name", name: "w:name",
uiPriority: "w:uiPriority", uiPriority: "w:uiPriority",
qFormat: "w:qFormat", qFormat: "w:qFormat",

View File

@ -1,11 +1,11 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
interface IComponentAttributes { interface IComponentAttributes {
val: string; readonly val: string;
} }
class ComponentAttributes extends XmlAttributeComponent<IComponentAttributes> { class ComponentAttributes extends XmlAttributeComponent<IComponentAttributes> {
protected xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
export class Name extends XmlComponent { export class Name extends XmlComponent {

View File

@ -1,4 +1,16 @@
import * as paragraph from "file/paragraph"; import {
Alignment,
AlignmentOptions,
Indent,
ISpacingProperties,
KeepLines,
KeepNext,
LeftTabStop,
MaxRightTabStop,
ParagraphProperties,
Spacing,
ThematicBreak,
} from "file/paragraph";
import * as formatting from "file/paragraph/run/formatting"; import * as formatting from "file/paragraph/run/formatting";
import { RunProperties } from "file/paragraph/run/properties"; import { RunProperties } from "file/paragraph/run/properties";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
@ -6,14 +18,14 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { BasedOn, Link, Name, Next, QuickFormat, SemiHidden, UiPriority, UnhideWhenUsed } from "./components"; import { BasedOn, Link, Name, Next, QuickFormat, SemiHidden, UiPriority, UnhideWhenUsed } from "./components";
export interface IStyleAttributes { export interface IStyleAttributes {
type?: string; readonly type?: string;
styleId?: string; readonly styleId?: string;
default?: boolean; readonly default?: boolean;
customStyle?: string; readonly customStyle?: string;
} }
class StyleAttributes extends XmlAttributeComponent<IStyleAttributes> { class StyleAttributes extends XmlAttributeComponent<IStyleAttributes> {
protected xmlKeys = { protected readonly xmlKeys = {
type: "w:type", type: "w:type",
styleId: "w:styleId", styleId: "w:styleId",
default: "w:default", default: "w:default",
@ -36,12 +48,12 @@ export class Style extends XmlComponent {
} }
export class ParagraphStyle extends Style { export class ParagraphStyle extends Style {
private readonly paragraphProperties: paragraph.ParagraphProperties; private readonly paragraphProperties: ParagraphProperties;
private readonly runProperties: RunProperties; private readonly runProperties: RunProperties;
constructor(styleId: string, name?: string) { constructor(styleId: string, name?: string) {
super({ type: "paragraph", styleId: styleId }, name); super({ type: "paragraph", styleId: styleId }, name);
this.paragraphProperties = new paragraph.ParagraphProperties(); this.paragraphProperties = new ParagraphProperties();
this.runProperties = new RunProperties(); this.runProperties = new RunProperties();
this.root.push(this.paragraphProperties); this.root.push(this.paragraphProperties);
this.root.push(this.runProperties); this.root.push(this.runProperties);
@ -129,47 +141,47 @@ export class ParagraphStyle extends Style {
// --------------------- Paragraph formatting ------------------------ // // --------------------- Paragraph formatting ------------------------ //
public center(): ParagraphStyle { public center(): ParagraphStyle {
return this.addParagraphProperty(new paragraph.Alignment("center")); return this.addParagraphProperty(new Alignment(AlignmentOptions.CENTER));
} }
public left(): ParagraphStyle { public left(): ParagraphStyle {
return this.addParagraphProperty(new paragraph.Alignment("left")); return this.addParagraphProperty(new Alignment(AlignmentOptions.LEFT));
} }
public right(): ParagraphStyle { public right(): ParagraphStyle {
return this.addParagraphProperty(new paragraph.Alignment("right")); return this.addParagraphProperty(new Alignment(AlignmentOptions.RIGHT));
} }
public justified(): ParagraphStyle { public justified(): ParagraphStyle {
return this.addParagraphProperty(new paragraph.Alignment("both")); return this.addParagraphProperty(new Alignment(AlignmentOptions.BOTH));
} }
public thematicBreak(): ParagraphStyle { public thematicBreak(): ParagraphStyle {
return this.addParagraphProperty(new paragraph.ThematicBreak()); return this.addParagraphProperty(new ThematicBreak());
} }
public maxRightTabStop(): ParagraphStyle { public maxRightTabStop(): ParagraphStyle {
return this.addParagraphProperty(new paragraph.MaxRightTabStop()); return this.addParagraphProperty(new MaxRightTabStop());
} }
public leftTabStop(position: number): ParagraphStyle { public leftTabStop(position: number): ParagraphStyle {
return this.addParagraphProperty(new paragraph.LeftTabStop(position)); return this.addParagraphProperty(new LeftTabStop(position));
} }
public indent(attrs: object): ParagraphStyle { public indent(attrs: object): ParagraphStyle {
return this.addParagraphProperty(new paragraph.Indent(attrs)); return this.addParagraphProperty(new Indent(attrs));
} }
public spacing(params: paragraph.ISpacingProperties): ParagraphStyle { public spacing(params: ISpacingProperties): ParagraphStyle {
return this.addParagraphProperty(new paragraph.Spacing(params)); return this.addParagraphProperty(new Spacing(params));
} }
public keepNext(): ParagraphStyle { public keepNext(): ParagraphStyle {
return this.addParagraphProperty(new paragraph.KeepNext()); return this.addParagraphProperty(new KeepNext());
} }
public keepLines(): ParagraphStyle { public keepLines(): ParagraphStyle {
return this.addParagraphProperty(new paragraph.KeepLines()); return this.addParagraphProperty(new KeepLines());
} }
} }

View File

@ -1,7 +1,7 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
class AliasAttributes extends XmlAttributeComponent<{ alias: string }> { class AliasAttributes extends XmlAttributeComponent<{ readonly alias: string }> {
protected xmlKeys = { alias: "w:val" }; protected readonly xmlKeys = { alias: "w:val" };
} }
export class Alias extends XmlComponent { export class Alias extends XmlComponent {

View File

@ -1,14 +1,10 @@
// http://officeopenxml.com/WPfieldInstructions.php // http://officeopenxml.com/WPfieldInstructions.php
import { SpaceType } from "file/space-type";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { ITableOfContentsOptions } from "./table-of-contents-properties"; import { ITableOfContentsOptions } from "./table-of-contents-properties";
enum SpaceType { class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
DEFAULT = "default", protected readonly xmlKeys = { space: "xml:space" };
PRESERVE = "preserve",
}
class TextAttributes extends XmlAttributeComponent<{ space: SpaceType }> {
protected xmlKeys = { space: "xml:space" };
} }
export class FieldInstruction extends XmlComponent { export class FieldInstruction extends XmlComponent {

View File

@ -1,6 +1,6 @@
export class StyleLevel { export class StyleLevel {
public styleName: string; public readonly styleName: string;
public level: number; public readonly level: number;
constructor(styleName: string, level: number) { constructor(styleName: string, level: number) {
this.styleName = styleName; this.styleName = styleName;
@ -22,13 +22,13 @@ export interface ITableOfContentsOptions {
* The identifier designated by text in this switch's field-argument corresponds to the caption label. * The identifier designated by text in this switch's field-argument corresponds to the caption label.
* Use captionLabelIncludingNumbers (\c) to build a table of captions with labels and numbers. * Use captionLabelIncludingNumbers (\c) to build a table of captions with labels and numbers.
*/ */
captionLabel?: string; readonly captionLabel?: string;
/** /**
* \b option - Includes entries only from the portion of the document marked by * \b option - Includes entries only from the portion of the document marked by
* the bookmark named by text in this switch's field-argument. * the bookmark named by text in this switch's field-argument.
*/ */
entriesFromBookmark?: string; readonly entriesFromBookmark?: string;
/** /**
* \c option - Includes figures, tables, charts, and other items that are numbered * \c option - Includes figures, tables, charts, and other items that are numbered
@ -36,24 +36,24 @@ export interface ITableOfContentsOptions {
* field-argument, which corresponds to the caption label, shall match the identifier in the * field-argument, which corresponds to the caption label, shall match the identifier in the
* corresponding SEQ field. * corresponding SEQ field.
*/ */
captionLabelIncludingNumbers?: string; readonly captionLabelIncludingNumbers?: string;
/** /**
* \d option - When used with \s, the text in this switch's field-argument defines * \d option - When used with \s, the text in this switch's field-argument defines
* the separator between sequence and page numbers. The default separator is a hyphen (-). * the separator between sequence and page numbers. The default separator is a hyphen (-).
*/ */
sequenceAndPageNumbersSeparator?: string; readonly sequenceAndPageNumbersSeparator?: string;
/** /**
* \f option - Includes only those TC fields whose identifier exactly matches the * \f option - Includes only those TC fields whose identifier exactly matches the
* text in this switch's field-argument (which is typically a letter). * text in this switch's field-argument (which is typically a letter).
*/ */
tcFieldIdentifier?: string; readonly tcFieldIdentifier?: string;
/** /**
* \h option - Makes the table of contents entries hyperlinks. * \h option - Makes the table of contents entries hyperlinks.
*/ */
hyperlink?: boolean; readonly hyperlink?: boolean;
/** /**
* \l option - Includes TC fields that assign entries to one of the levels specified * \l option - Includes TC fields that assign entries to one of the levels specified
@ -61,14 +61,14 @@ export interface ITableOfContentsOptions {
* where startLevel and endLevel are integers, and startLevel has a value equal-to or less-than endLevel. * where startLevel and endLevel are integers, and startLevel has a value equal-to or less-than endLevel.
* TC fields that assign entries to lower levels are skipped. * TC fields that assign entries to lower levels are skipped.
*/ */
tcFieldLevelRange?: string; readonly tcFieldLevelRange?: string;
/** /**
* \n option - Without field-argument, omits page numbers from the table of contents. * \n option - Without field-argument, omits page numbers from the table of contents.
* Page numbers are omitted from all levels unless a range of entry levels is specified by * Page numbers are omitted from all levels unless a range of entry levels is specified by
* text in this switch's field-argument. A range is specified as for \l. * text in this switch's field-argument. A range is specified as for \l.
*/ */
pageNumbersEntryLevelsRange?: string; readonly pageNumbersEntryLevelsRange?: string;
/** /**
* \o option - Uses paragraphs formatted with all or the specified range of builtin * \o option - Uses paragraphs formatted with all or the specified range of builtin
@ -77,20 +77,20 @@ export interface ITableOfContentsOptions {
* to the style with a style ID of HeadingX (e.g. 1 corresponds to Heading1). * to the style with a style ID of HeadingX (e.g. 1 corresponds to Heading1).
* If no heading range is specified, all heading levels used in the document are listed. * If no heading range is specified, all heading levels used in the document are listed.
*/ */
headingStyleRange?: string; readonly headingStyleRange?: string;
/** /**
* \p option - Text in this switch's field-argument specifies a sequence of characters * \p option - Text in this switch's field-argument specifies a sequence of characters
* that separate an entry and its page number. The default is a tab with leader dots. * that separate an entry and its page number. The default is a tab with leader dots.
*/ */
entryAndPageNumberSeparator?: string; readonly entryAndPageNumberSeparator?: string;
/** /**
* \s option - For entries numbered with a SEQ field (§17.16.5.56), adds a prefix to the page number. * \s option - For entries numbered with a SEQ field (§17.16.5.56), adds a prefix to the page number.
* The prefix depends on the type of entry. text in this switch's field-argument shall match the * The prefix depends on the type of entry. text in this switch's field-argument shall match the
* identifier in the SEQ field. * identifier in the SEQ field.
*/ */
seqFieldIdentifierForPrefix?: string; readonly seqFieldIdentifierForPrefix?: string;
/** /**
* \t field-argument Uses paragraphs formatted with styles other than the built-in heading styles. * \t field-argument Uses paragraphs formatted with styles other than the built-in heading styles.
@ -98,25 +98,25 @@ export interface ITableOfContentsOptions {
* with each doublet being a comma-separated set of style name and table of content level. * with each doublet being a comma-separated set of style name and table of content level.
* \t can be combined with \o. * \t can be combined with \o.
*/ */
stylesWithLevels?: StyleLevel[]; readonly stylesWithLevels?: StyleLevel[];
/** /**
* \u Uses the applied paragraph outline level. * \u Uses the applied paragraph outline level.
*/ */
useAppliedParagraphOutlineLevel?: boolean; readonly useAppliedParagraphOutlineLevel?: boolean;
/** /**
* \w Preserves tab entries within table entries. * \w Preserves tab entries within table entries.
*/ */
preserveTabInEntries?: boolean; readonly preserveTabInEntries?: boolean;
/** /**
* \x Preserves newline characters within table entries. * \x Preserves newline characters within table entries.
*/ */
preserveNewLineInEntries?: boolean; readonly preserveNewLineInEntries?: boolean;
/** /**
* \z Hides tab leader and page numbers in web page view (§17.18.102). * \z Hides tab leader and page numbers in web page view (§17.18.102).
*/ */
hideTabAndPageNumbersInWebView?: boolean; readonly hideTabAndPageNumbersInWebView?: boolean;
} }

View File

@ -3,7 +3,7 @@ import { expect } from "chai";
import { Formatter } from "export/formatter"; import { Formatter } from "export/formatter";
import { TableOfContents } from "./table-of-contents"; import { TableOfContents } from "./table-of-contents";
import { ITableOfContentsOptions, StyleLevel } from "./table-of-contents-properties"; import { StyleLevel } from "./table-of-contents-properties";
describe("Table of Contents", () => { describe("Table of Contents", () => {
describe("#constructor", () => { describe("#constructor", () => {
@ -14,28 +14,28 @@ describe("Table of Contents", () => {
}); });
it("should construct a TOC with all the options and alias", () => { it("should construct a TOC with all the options and alias", () => {
const props: ITableOfContentsOptions = {};
props.captionLabel = "A";
props.entriesFromBookmark = "B";
props.captionLabelIncludingNumbers = "C";
props.sequenceAndPageNumbersSeparator = "D";
props.tcFieldIdentifier = "F";
props.hyperlink = true;
props.tcFieldLevelRange = "L";
props.pageNumbersEntryLevelsRange = "N";
props.headingStyleRange = "O";
props.entryAndPageNumberSeparator = "P";
props.seqFieldIdentifierForPrefix = "S";
const styles = new Array<StyleLevel>(); const styles = new Array<StyleLevel>();
styles.push(new StyleLevel("SL", 1)); styles.push(new StyleLevel("SL", 1));
styles.push(new StyleLevel("SL", 2)); styles.push(new StyleLevel("SL", 2));
props.stylesWithLevels = styles;
props.useAppliedParagraphOutlineLevel = true; const props = {
props.preserveTabInEntries = true; captionLabel: "A",
props.preserveNewLineInEntries = true; entriesFromBookmark: "B",
props.hideTabAndPageNumbersInWebView = true; captionLabelIncludingNumbers: "C",
sequenceAndPageNumbersSeparator: "D",
tcFieldIdentifier: "F",
hyperlink: true,
tcFieldLevelRange: "L",
pageNumbersEntryLevelsRange: "N",
headingStyleRange: "O",
entryAndPageNumberSeparator: "P",
seqFieldIdentifierForPrefix: "S",
stylesWithLevels: styles,
useAppliedParagraphOutlineLevel: true,
preserveTabInEntries: true,
preserveNewLineInEntries: true,
hideTabAndPageNumbersInWebView: true,
};
const toc = new TableOfContents("Summary", props); const toc = new TableOfContents("Summary", props);
const tree = new Formatter().format(toc); const tree = new Formatter().format(toc);

View File

@ -8,8 +8,8 @@ export class TableGrid extends XmlComponent {
} }
} }
class GridColAttributes extends XmlAttributeComponent<{ w: number }> { class GridColAttributes extends XmlAttributeComponent<{ readonly w: number }> {
protected xmlKeys = { w: "w:w" }; protected readonly xmlKeys = { w: "w:w" };
} }
export class GridCol extends XmlComponent { export class GridCol extends XmlComponent {

View File

@ -2,13 +2,13 @@ import { BorderStyle } from "file/styles";
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components";
interface ICellBorder { interface ICellBorder {
style: BorderStyle; readonly style: BorderStyle;
size: number; readonly size: number;
color: string; readonly color: string;
} }
class CellBorderAttributes extends XmlAttributeComponent<ICellBorder> { class CellBorderAttributes extends XmlAttributeComponent<ICellBorder> {
protected xmlKeys = { style: "w:val", size: "w:sz", color: "w:color" }; protected readonly xmlKeys = { style: "w:val", size: "w:sz", color: "w:color" };
} }
class BaseTableCellBorder extends XmlComponent { class BaseTableCellBorder extends XmlComponent {
@ -71,8 +71,8 @@ export class TableCellBorders extends XmlComponent {
/** /**
* Attributes fot the GridSpan element. * Attributes fot the GridSpan element.
*/ */
class GridSpanAttributes extends XmlAttributeComponent<{ val: number }> { class GridSpanAttributes extends XmlAttributeComponent<{ readonly val: number }> {
protected xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
/** /**
@ -104,8 +104,8 @@ export enum VMergeType {
RESTART = "restart", RESTART = "restart",
} }
class VMergeAttributes extends XmlAttributeComponent<{ val: VMergeType }> { class VMergeAttributes extends XmlAttributeComponent<{ readonly val: VMergeType }> {
protected xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
/** /**
@ -129,8 +129,8 @@ export enum VerticalAlign {
TOP = "top", TOP = "top",
} }
class VAlignAttributes extends XmlAttributeComponent<{ val: VerticalAlign }> { class VAlignAttributes extends XmlAttributeComponent<{ readonly val: VerticalAlign }> {
protected xmlKeys = { val: "w:val" }; protected readonly xmlKeys = { val: "w:val" };
} }
/** /**
@ -159,8 +159,8 @@ export enum WidthType {
PERCENTAGE = "pct", PERCENTAGE = "pct",
} }
class TableCellWidthAttributes extends XmlAttributeComponent<{ type: WidthType; width: string | number }> { class TableCellWidthAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly width: string | number }> {
protected xmlKeys = { width: "w:w", type: "w:type" }; protected readonly xmlKeys = { width: "w:w", type: "w:type" };
} }
/** /**
@ -180,13 +180,13 @@ export class TableCellWidth extends XmlComponent {
} }
export interface ITableCellShadingAttributesProperties { export interface ITableCellShadingAttributesProperties {
fill?: string; readonly fill?: string;
color?: string; readonly color?: string;
val?: string; readonly val?: string;
} }
class TableCellShadingAttributes extends XmlAttributeComponent<ITableCellShadingAttributesProperties> { class TableCellShadingAttributes extends XmlAttributeComponent<ITableCellShadingAttributesProperties> {
protected xmlKeys = { protected readonly xmlKeys = {
fill: "w:fill", fill: "w:fill",
color: "w:color", color: "w:color",
val: "w:val", val: "w:val",

View File

@ -26,8 +26,13 @@ class TableBordersElement extends XmlComponent {
} }
} }
class TableBordersAttributes extends XmlAttributeComponent<{ value: string; size: number; space: number; color: string }> { class TableBordersAttributes extends XmlAttributeComponent<{
protected xmlKeys = { readonly value: string;
readonly size: number;
readonly space: number;
readonly color: string;
}> {
protected readonly xmlKeys = {
value: "w:val", value: "w:val",
size: "w:sz", size: "w:sz",
space: "w:space", space: "w:space",

View File

@ -2,8 +2,8 @@ import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-co
import { WidthType } from "../table-cell"; import { WidthType } from "../table-cell";
class TableCellMarginAttributes extends XmlAttributeComponent<{ type: WidthType; value: number }> { class TableCellMarginAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly value: number }> {
protected xmlKeys = { value: "w:w", type: "w:sz" }; protected readonly xmlKeys = { value: "w:w", type: "w:sz" };
} }
class BaseTableCellMargin extends XmlComponent { class BaseTableCellMargin extends XmlComponent {

View File

@ -32,7 +32,7 @@ export interface ITableFloatOptions {
* text - relative to the vertical edge of the text margin for the column in which the anchor paragraph is located * text - relative to the vertical edge of the text margin for the column in which the anchor paragraph is located
* If omitted, the value is assumed to be page. * If omitted, the value is assumed to be page.
*/ */
horizontalAnchor?: TableAnchorType; readonly horizontalAnchor?: TableAnchorType;
/** /**
* Specifies an absolute horizontal position for the table, relative to the horizontalAnchor. * Specifies an absolute horizontal position for the table, relative to the horizontalAnchor.
@ -41,7 +41,7 @@ export interface ITableFloatOptions {
* If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosition attribute is ignored. * If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosition attribute is ignored.
* If the attribute is omitted, the value is assumed to be zero. * If the attribute is omitted, the value is assumed to be zero.
*/ */
absoluteHorizontalPosition?: number; readonly absoluteHorizontalPosition?: number;
/** /**
* Specifies a relative horizontal position for the table, relative to the horizontalAnchor attribute. * Specifies a relative horizontal position for the table, relative to the horizontalAnchor attribute.
@ -53,7 +53,7 @@ export interface ITableFloatOptions {
* outside - the table should be outside of the anchor * outside - the table should be outside of the anchor
* right - the table should be right aligned with respect to the anchor * right - the table should be right aligned with respect to the anchor
*/ */
relativeHorizontalPosition?: RelativeHorizontalPosition; readonly relativeHorizontalPosition?: RelativeHorizontalPosition;
/** /**
* Specifies the vertical anchor or the base object from which the vertical positioning * Specifies the vertical anchor or the base object from which the vertical positioning
@ -63,7 +63,7 @@ export interface ITableFloatOptions {
* text - relative to the horizontal edge of the text margin for the column in which the anchor paragraph is located * text - relative to the horizontal edge of the text margin for the column in which the anchor paragraph is located
* If omitted, the value is assumed to be page. * If omitted, the value is assumed to be page.
*/ */
verticalAnchor?: TableAnchorType; readonly verticalAnchor?: TableAnchorType;
/** /**
* Specifies an absolute vertical position for the table, relative to the verticalAnchor anchor. * Specifies an absolute vertical position for the table, relative to the verticalAnchor anchor.
@ -72,7 +72,7 @@ export interface ITableFloatOptions {
* If relativeVerticalPosition is also specified, then the absoluteVerticalPosition attribute is ignored. * If relativeVerticalPosition is also specified, then the absoluteVerticalPosition attribute is ignored.
* If the attribute is omitted, the value is assumed to be zero. * If the attribute is omitted, the value is assumed to be zero.
*/ */
absoluteVerticalPosition?: number; readonly absoluteVerticalPosition?: number;
/** /**
* Specifies a relative vertical position for the table, relative to the verticalAnchor attribute. * Specifies a relative vertical position for the table, relative to the verticalAnchor attribute.
@ -84,35 +84,35 @@ export interface ITableFloatOptions {
* inline - the table should be vertically aligned in line with the surrounding text (so as to not allow any text wrapping around it) * inline - the table should be vertically aligned in line with the surrounding text (so as to not allow any text wrapping around it)
* top - the table should be vertically aligned to the top edge of the anchor * top - the table should be vertically aligned to the top edge of the anchor
*/ */
relativeVerticalPosition?: RelativeVerticalPosition; readonly relativeVerticalPosition?: RelativeVerticalPosition;
/** /**
* Specifies the minimun distance to be maintained between the table and the top of text in the paragraph * Specifies the minimun distance to be maintained between the table and the top of text in the paragraph
* below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero. * below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/ */
bottomFromText?: number; readonly bottomFromText?: number;
/** /**
* Specifies the minimun distance to be maintained between the table and the bottom edge of text in the paragraph * Specifies the minimun distance to be maintained between the table and the bottom edge of text in the paragraph
* above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero. * above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/ */
topFromText?: number; readonly topFromText?: number;
/** /**
* Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph * Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph
* to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero. * to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/ */
leftFromText?: number; readonly leftFromText?: number;
/** /**
* Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph * Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph
* to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero. * to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero.
*/ */
rightFromText?: number; readonly rightFromText?: number;
} }
export class TableFloatOptionsAttributes extends XmlAttributeComponent<ITableFloatOptions> { export class TableFloatOptionsAttributes extends XmlAttributeComponent<ITableFloatOptions> {
protected xmlKeys = { protected readonly xmlKeys = {
horizontalAnchor: "w:horzAnchor", horizontalAnchor: "w:horzAnchor",
verticalAnchor: "w:vertAnchor", verticalAnchor: "w:vertAnchor",
absoluteHorizontalPosition: "w:tblpX", absoluteHorizontalPosition: "w:tblpX",

View File

@ -5,8 +5,8 @@ export enum TableLayoutType {
FIXED = "fixed", FIXED = "fixed",
} }
class TableLayoutAttributes extends XmlAttributeComponent<{ type: TableLayoutType }> { class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: TableLayoutType }> {
protected xmlKeys = { type: "w:type" }; protected readonly xmlKeys = { type: "w:type" };
} }
export class TableLayout extends XmlComponent { export class TableLayout extends XmlComponent {

Some files were not shown because too many files have changed in this diff Show More