Merge pull request #190 from dolanmiu/feat/more-tests
Introduce some functional programming techniques
This commit is contained in:
8
.nycrc
8
.nycrc
@ -1,9 +1,9 @@
|
||||
{
|
||||
"check-coverage": true,
|
||||
"lines": 87.39,
|
||||
"functions": 83.54,
|
||||
"branches": 71.95,
|
||||
"statements": 87.17,
|
||||
"lines": 87.54,
|
||||
"functions": 83.61,
|
||||
"branches": 72.57,
|
||||
"statements": 87.32,
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
|
@ -81,6 +81,7 @@
|
||||
"sinon": "^5.0.7",
|
||||
"ts-node": "^7.0.1",
|
||||
"tslint": "^5.11.0",
|
||||
"tslint-immutable": "^4.9.0",
|
||||
"typedoc": "^0.11.1",
|
||||
"typescript": "2.9.2",
|
||||
"webpack": "^3.10.0"
|
||||
|
@ -5,25 +5,25 @@ import { File } from "file";
|
||||
import { Formatter } from "../formatter";
|
||||
|
||||
interface IXmlifyedFile {
|
||||
data: string;
|
||||
path: string;
|
||||
readonly data: string;
|
||||
readonly path: string;
|
||||
}
|
||||
|
||||
interface IXmlifyedFileMapping {
|
||||
Document: IXmlifyedFile;
|
||||
Styles: IXmlifyedFile;
|
||||
Properties: IXmlifyedFile;
|
||||
Numbering: IXmlifyedFile;
|
||||
Relationships: IXmlifyedFile;
|
||||
FileRelationships: IXmlifyedFile;
|
||||
Headers: IXmlifyedFile[];
|
||||
Footers: IXmlifyedFile[];
|
||||
HeaderRelationships: IXmlifyedFile[];
|
||||
FooterRelationships: IXmlifyedFile[];
|
||||
ContentTypes: IXmlifyedFile;
|
||||
AppProperties: IXmlifyedFile;
|
||||
FootNotes: IXmlifyedFile;
|
||||
Settings: IXmlifyedFile;
|
||||
readonly Document: IXmlifyedFile;
|
||||
readonly Styles: IXmlifyedFile;
|
||||
readonly Properties: IXmlifyedFile;
|
||||
readonly Numbering: IXmlifyedFile;
|
||||
readonly Relationships: IXmlifyedFile;
|
||||
readonly FileRelationships: IXmlifyedFile;
|
||||
readonly Headers: IXmlifyedFile[];
|
||||
readonly Footers: IXmlifyedFile[];
|
||||
readonly HeaderRelationships: IXmlifyedFile[];
|
||||
readonly FooterRelationships: IXmlifyedFile[];
|
||||
readonly ContentTypes: IXmlifyedFile;
|
||||
readonly AppProperties: IXmlifyedFile;
|
||||
readonly FootNotes: IXmlifyedFile;
|
||||
readonly Settings: IXmlifyedFile;
|
||||
}
|
||||
|
||||
export class Compiler {
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IAppPropertiesAttributes {
|
||||
xmlns: string;
|
||||
vt: string;
|
||||
readonly xmlns: string;
|
||||
readonly vt: string;
|
||||
}
|
||||
|
||||
export class AppPropertiesAttributes extends XmlAttributeComponent<IAppPropertiesAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
xmlns: "xmlns",
|
||||
vt: "xmlns:vt",
|
||||
};
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IContentTypeAttributes {
|
||||
xmlns?: string;
|
||||
readonly xmlns?: string;
|
||||
}
|
||||
|
||||
export class ContentTypeAttributes extends XmlAttributeComponent<IContentTypeAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
xmlns: "xmlns",
|
||||
};
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IDefaultAttributes {
|
||||
contentType: string;
|
||||
extension?: string;
|
||||
readonly contentType: string;
|
||||
readonly extension?: string;
|
||||
}
|
||||
|
||||
export class DefaultAttributes extends XmlAttributeComponent<IDefaultAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
contentType: "ContentType",
|
||||
extension: "Extension",
|
||||
};
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IOverrideAttributes {
|
||||
contentType: string;
|
||||
partName?: string;
|
||||
readonly contentType: string;
|
||||
readonly partName?: string;
|
||||
}
|
||||
|
||||
export class OverrideAttributes extends XmlAttributeComponent<IOverrideAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
contentType: "ContentType",
|
||||
partName: "PartName",
|
||||
};
|
||||
|
@ -3,14 +3,14 @@ import { DocumentAttributes } from "../document/document-attributes";
|
||||
import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components";
|
||||
|
||||
export interface IPropertiesOptions {
|
||||
title?: string;
|
||||
subject?: string;
|
||||
creator?: string;
|
||||
keywords?: string;
|
||||
description?: string;
|
||||
lastModifiedBy?: string;
|
||||
revision?: string;
|
||||
externalStyles?: string;
|
||||
readonly title?: string;
|
||||
readonly subject?: string;
|
||||
readonly creator?: string;
|
||||
readonly keywords?: string;
|
||||
readonly description?: string;
|
||||
readonly lastModifiedBy?: string;
|
||||
readonly revision?: string;
|
||||
readonly externalStyles?: string;
|
||||
}
|
||||
|
||||
export class CoreProperties extends XmlComponent {
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IColumnsAttributes {
|
||||
space?: number;
|
||||
readonly space?: number;
|
||||
}
|
||||
|
||||
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
space: "w:space",
|
||||
};
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IDocGridAttributesProperties {
|
||||
linePitch?: number;
|
||||
readonly linePitch?: number;
|
||||
}
|
||||
|
||||
export class DocGridAttributes extends XmlAttributeComponent<IDocGridAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
linePitch: "w:linePitch",
|
||||
};
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ export enum FooterReferenceType {
|
||||
}
|
||||
|
||||
export interface IFooterReferenceAttributes {
|
||||
type: string;
|
||||
id: string;
|
||||
readonly type: string;
|
||||
readonly id: string;
|
||||
}
|
||||
|
||||
export class FooterReferenceAttributes extends XmlAttributeComponent<IFooterReferenceAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
type: "w:type",
|
||||
id: "r:id",
|
||||
};
|
||||
|
@ -2,8 +2,8 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { FooterReferenceAttributes, FooterReferenceType } from "./footer-reference-attributes";
|
||||
|
||||
export interface IFooterOptions {
|
||||
footerType?: FooterReferenceType;
|
||||
footerId?: number;
|
||||
readonly footerType?: FooterReferenceType;
|
||||
readonly footerId?: number;
|
||||
}
|
||||
|
||||
export class FooterReference extends XmlComponent {
|
||||
|
@ -7,12 +7,12 @@ export enum HeaderReferenceType {
|
||||
}
|
||||
|
||||
export interface IHeaderReferenceAttributes {
|
||||
type: string;
|
||||
id: string;
|
||||
readonly type: string;
|
||||
readonly id: string;
|
||||
}
|
||||
|
||||
export class HeaderReferenceAttributes extends XmlAttributeComponent<IHeaderReferenceAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
type: "w:type",
|
||||
id: "r:id",
|
||||
};
|
||||
|
@ -2,8 +2,8 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { HeaderReferenceAttributes, HeaderReferenceType } from "./header-reference-attributes";
|
||||
|
||||
export interface IHeaderOptions {
|
||||
headerType?: HeaderReferenceType;
|
||||
headerId?: number;
|
||||
readonly headerType?: HeaderReferenceType;
|
||||
readonly headerId?: number;
|
||||
}
|
||||
|
||||
export class HeaderReference extends XmlComponent {
|
||||
|
@ -19,28 +19,28 @@ export enum PageBorderZOrder {
|
||||
}
|
||||
|
||||
export interface IPageBorderAttributes {
|
||||
display?: PageBorderDisplay;
|
||||
offsetFrom?: PageBorderOffsetFrom;
|
||||
zOrder?: PageBorderZOrder;
|
||||
readonly display?: PageBorderDisplay;
|
||||
readonly offsetFrom?: PageBorderOffsetFrom;
|
||||
readonly zOrder?: PageBorderZOrder;
|
||||
}
|
||||
|
||||
export interface IPageBorderConfiguration {
|
||||
style?: BorderStyle;
|
||||
size?: number;
|
||||
color?: string;
|
||||
space?: number;
|
||||
readonly style?: BorderStyle;
|
||||
readonly size?: number;
|
||||
readonly color?: string;
|
||||
readonly space?: number;
|
||||
}
|
||||
|
||||
export interface IPageBordersOptions {
|
||||
pageBorders?: IPageBorderAttributes;
|
||||
pageBorderTop?: IPageBorderConfiguration;
|
||||
pageBorderRight?: IPageBorderConfiguration;
|
||||
pageBorderBottom?: IPageBorderConfiguration;
|
||||
pageBorderLeft?: IPageBorderConfiguration;
|
||||
readonly pageBorders?: IPageBorderAttributes;
|
||||
readonly pageBorderTop?: IPageBorderConfiguration;
|
||||
readonly pageBorderRight?: IPageBorderConfiguration;
|
||||
readonly pageBorderBottom?: IPageBorderConfiguration;
|
||||
readonly pageBorderLeft?: IPageBorderConfiguration;
|
||||
}
|
||||
|
||||
class PageBordeAttributes extends XmlAttributeComponent<IPageBorderConfiguration> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
style: "w:val",
|
||||
size: "w:size",
|
||||
color: "w:color",
|
||||
@ -57,7 +57,7 @@ class PageBorder extends XmlComponent {
|
||||
}
|
||||
|
||||
class PageBordersAttributes extends XmlAttributeComponent<IPageBorderAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
display: "w:display",
|
||||
offsetFrom: "w:offsetFrom",
|
||||
zOrder: "w:zOrder",
|
||||
|
@ -1,18 +1,18 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IPageMarginAttributes {
|
||||
top?: number;
|
||||
right?: number;
|
||||
bottom?: number;
|
||||
left?: number;
|
||||
header?: number;
|
||||
footer?: number;
|
||||
gutter?: number;
|
||||
mirror?: boolean;
|
||||
readonly top?: number;
|
||||
readonly right?: number;
|
||||
readonly bottom?: number;
|
||||
readonly left?: number;
|
||||
readonly header?: number;
|
||||
readonly footer?: number;
|
||||
readonly gutter?: number;
|
||||
readonly mirror?: boolean;
|
||||
}
|
||||
|
||||
export class PageMarginAttributes extends XmlAttributeComponent<IPageMarginAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
top: "w:top",
|
||||
right: "w:right",
|
||||
bottom: "w:bottom",
|
||||
|
@ -17,12 +17,12 @@ export enum PageNumberFormat {
|
||||
}
|
||||
|
||||
export interface IPageNumberTypeAttributes {
|
||||
pageNumberStart?: number;
|
||||
pageNumberFormatType?: PageNumberFormat;
|
||||
readonly pageNumberStart?: number;
|
||||
readonly pageNumberFormatType?: PageNumberFormat;
|
||||
}
|
||||
|
||||
export class PageNumberTypeAttributes extends XmlAttributeComponent<IPageNumberTypeAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
pageNumberStart: "w:start",
|
||||
pageNumberFormatType: "w:fmt",
|
||||
};
|
||||
|
@ -6,13 +6,13 @@ export enum PageOrientation {
|
||||
}
|
||||
|
||||
export interface IPageSizeAttributes {
|
||||
width?: number;
|
||||
height?: number;
|
||||
orientation?: PageOrientation;
|
||||
readonly width?: number;
|
||||
readonly height?: number;
|
||||
readonly orientation?: PageOrientation;
|
||||
}
|
||||
|
||||
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
width: "w:w",
|
||||
height: "w:h",
|
||||
orientation: "w:orient",
|
||||
|
@ -20,21 +20,21 @@ import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attr
|
||||
import { TitlePage } from "./title-page/title-page";
|
||||
|
||||
export interface IHeaderFooterGroup<T> {
|
||||
default?: T;
|
||||
first?: T;
|
||||
even?: T;
|
||||
readonly default?: T;
|
||||
readonly first?: T;
|
||||
readonly even?: T;
|
||||
}
|
||||
|
||||
interface IHeadersOptions {
|
||||
headers?: IHeaderFooterGroup<HeaderWrapper>;
|
||||
readonly headers?: IHeaderFooterGroup<HeaderWrapper>;
|
||||
}
|
||||
|
||||
interface IFootersOptions {
|
||||
footers?: IHeaderFooterGroup<FooterWrapper>;
|
||||
readonly footers?: IHeaderFooterGroup<FooterWrapper>;
|
||||
}
|
||||
|
||||
interface ITitlePageOptions {
|
||||
titlePage?: boolean;
|
||||
readonly titlePage?: boolean;
|
||||
}
|
||||
|
||||
export type SectionPropertiesOptions = IPageSizeAttributes &
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IHeaderReferenceAttributes {
|
||||
value: string;
|
||||
readonly value: string;
|
||||
}
|
||||
|
||||
export class TitlePageAttributes extends XmlAttributeComponent<IHeaderReferenceAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
value: "w:val",
|
||||
};
|
||||
}
|
||||
|
@ -1,33 +1,33 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IDocumentAttributesProperties {
|
||||
wpc?: string;
|
||||
mc?: string;
|
||||
o?: string;
|
||||
r?: string;
|
||||
m?: string;
|
||||
v?: string;
|
||||
wp14?: string;
|
||||
wp?: string;
|
||||
w10?: string;
|
||||
w?: string;
|
||||
w14?: string;
|
||||
w15?: string;
|
||||
wpg?: string;
|
||||
wpi?: string;
|
||||
wne?: string;
|
||||
wps?: string;
|
||||
Ignorable?: string;
|
||||
cp?: string;
|
||||
dc?: string;
|
||||
dcterms?: string;
|
||||
dcmitype?: string;
|
||||
xsi?: string;
|
||||
type?: string;
|
||||
readonly wpc?: string;
|
||||
readonly mc?: string;
|
||||
readonly o?: string;
|
||||
readonly r?: string;
|
||||
readonly m?: string;
|
||||
readonly v?: string;
|
||||
readonly wp14?: string;
|
||||
readonly wp?: string;
|
||||
readonly w10?: string;
|
||||
readonly w?: string;
|
||||
readonly w14?: string;
|
||||
readonly w15?: string;
|
||||
readonly wpg?: string;
|
||||
readonly wpi?: string;
|
||||
readonly wne?: string;
|
||||
readonly wps?: string;
|
||||
readonly Ignorable?: string;
|
||||
readonly cp?: string;
|
||||
readonly dc?: string;
|
||||
readonly dcterms?: string;
|
||||
readonly dcmitype?: string;
|
||||
readonly xsi?: string;
|
||||
readonly type?: string;
|
||||
}
|
||||
|
||||
export class DocumentAttributes extends XmlAttributeComponent<IDocumentAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
wpc: "xmlns:wpc",
|
||||
mc: "xmlns:mc",
|
||||
o: "xmlns:o",
|
||||
|
@ -2,16 +2,16 @@ import { XmlAttributeComponent } from "file/xml-components";
|
||||
import { IDistance } from "../drawing";
|
||||
|
||||
export interface IAnchorAttributes extends IDistance {
|
||||
allowOverlap?: "0" | "1";
|
||||
behindDoc?: "0" | "1";
|
||||
layoutInCell?: "0" | "1";
|
||||
locked?: "0" | "1";
|
||||
relativeHeight?: number;
|
||||
simplePos?: "0" | "1";
|
||||
readonly allowOverlap?: "0" | "1";
|
||||
readonly behindDoc?: "0" | "1";
|
||||
readonly layoutInCell?: "0" | "1";
|
||||
readonly locked?: "0" | "1";
|
||||
readonly relativeHeight?: number;
|
||||
readonly simplePos?: "0" | "1";
|
||||
}
|
||||
|
||||
export class AnchorAttributes extends XmlAttributeComponent<IAnchorAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
distT: "distT",
|
||||
distB: "distB",
|
||||
distL: "distL",
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IDocPropertiesAttributes {
|
||||
id?: number;
|
||||
name?: string;
|
||||
descr?: string;
|
||||
readonly id?: number;
|
||||
readonly name?: string;
|
||||
readonly descr?: string;
|
||||
}
|
||||
|
||||
export class DocPropertiesAttributes extends XmlAttributeComponent<IDocPropertiesAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
id: "id",
|
||||
name: "name",
|
||||
descr: "descr",
|
||||
|
@ -11,16 +11,16 @@ export enum PlacementPosition {
|
||||
}
|
||||
|
||||
export interface IDistance {
|
||||
distT?: number;
|
||||
distB?: number;
|
||||
distL?: number;
|
||||
distR?: number;
|
||||
readonly distT?: number;
|
||||
readonly distB?: number;
|
||||
readonly distL?: number;
|
||||
readonly distR?: number;
|
||||
}
|
||||
|
||||
export interface IDrawingOptions {
|
||||
position?: PlacementPosition;
|
||||
textWrapping?: ITextWrapping;
|
||||
floating?: IFloating;
|
||||
readonly position?: PlacementPosition;
|
||||
readonly textWrapping?: ITextWrapping;
|
||||
readonly floating?: IFloating;
|
||||
}
|
||||
|
||||
const defaultDrawingOptions: IDrawingOptions = {
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IEffectExtentAttributes {
|
||||
b?: number;
|
||||
l?: number;
|
||||
r?: number;
|
||||
t?: number;
|
||||
readonly b?: number;
|
||||
readonly l?: number;
|
||||
readonly r?: number;
|
||||
readonly t?: number;
|
||||
}
|
||||
|
||||
export class EffectExtentAttributes extends XmlAttributeComponent<IEffectExtentAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
b: "b",
|
||||
l: "l",
|
||||
r: "r",
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IExtentAttributes {
|
||||
cx?: number;
|
||||
cy?: number;
|
||||
readonly cx?: number;
|
||||
readonly cy?: number;
|
||||
}
|
||||
|
||||
export class ExtentAttributes extends XmlAttributeComponent<IExtentAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
cx: "cx",
|
||||
cy: "cy",
|
||||
};
|
||||
|
@ -39,22 +39,22 @@ export enum VerticalPositionAlign {
|
||||
}
|
||||
|
||||
export interface IHorizontalPositionOptions {
|
||||
relative: HorizontalPositionRelativeFrom;
|
||||
align?: HorizontalPositionAlign;
|
||||
offset?: number;
|
||||
readonly relative: HorizontalPositionRelativeFrom;
|
||||
readonly align?: HorizontalPositionAlign;
|
||||
readonly offset?: number;
|
||||
}
|
||||
|
||||
export interface IVerticalPositionOptions {
|
||||
relative: VerticalPositionRelativeFrom;
|
||||
align?: VerticalPositionAlign;
|
||||
offset?: number;
|
||||
readonly relative: VerticalPositionRelativeFrom;
|
||||
readonly align?: VerticalPositionAlign;
|
||||
readonly offset?: number;
|
||||
}
|
||||
|
||||
export interface IFloating {
|
||||
horizontalPosition: IHorizontalPositionOptions;
|
||||
verticalPosition: IVerticalPositionOptions;
|
||||
allowOverlap?: boolean;
|
||||
lockAnchor?: boolean;
|
||||
behindDocument?: boolean;
|
||||
layoutInCell?: boolean;
|
||||
readonly horizontalPosition: IHorizontalPositionOptions;
|
||||
readonly verticalPosition: IVerticalPositionOptions;
|
||||
readonly allowOverlap?: boolean;
|
||||
readonly lockAnchor?: boolean;
|
||||
readonly behindDocument?: boolean;
|
||||
readonly layoutInCell?: boolean;
|
||||
}
|
||||
|
@ -5,11 +5,11 @@ import { HorizontalPositionRelativeFrom, IHorizontalPositionOptions } from "./fl
|
||||
import { PositionOffset } from "./position-offset";
|
||||
|
||||
interface IHorizontalPositionAttributes {
|
||||
relativeFrom: HorizontalPositionRelativeFrom;
|
||||
readonly relativeFrom: HorizontalPositionRelativeFrom;
|
||||
}
|
||||
|
||||
class HorizontalPositionAttributes extends XmlAttributeComponent<IHorizontalPositionAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
relativeFrom: "relativeFrom",
|
||||
};
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
interface ISimplePosAttributes {
|
||||
x: number;
|
||||
y: number;
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
}
|
||||
|
||||
class SimplePosAttributes extends XmlAttributeComponent<ISimplePosAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
x: "x",
|
||||
y: "y",
|
||||
};
|
||||
|
@ -5,11 +5,11 @@ import { IVerticalPositionOptions, VerticalPositionRelativeFrom } from "./floati
|
||||
import { PositionOffset } from "./position-offset";
|
||||
|
||||
interface IVerticalPositionAttributes {
|
||||
relativeFrom: VerticalPositionRelativeFrom;
|
||||
readonly relativeFrom: VerticalPositionRelativeFrom;
|
||||
}
|
||||
|
||||
class VerticalPositionAttributes extends XmlAttributeComponent<IVerticalPositionAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
relativeFrom: "relativeFrom",
|
||||
};
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IGraphicFrameLockAttributes {
|
||||
xmlns?: string;
|
||||
noChangeAspect?: number;
|
||||
readonly xmlns?: string;
|
||||
readonly noChangeAspect?: number;
|
||||
}
|
||||
|
||||
export class GraphicFrameLockAttributes extends XmlAttributeComponent<IGraphicFrameLockAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
xmlns: "xmlns:a",
|
||||
noChangeAspect: "noChangeAspect",
|
||||
};
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IGraphicDataAttributes {
|
||||
uri?: string;
|
||||
readonly uri?: string;
|
||||
}
|
||||
|
||||
export class GraphicDataAttributes extends XmlAttributeComponent<IGraphicDataAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
uri: "uri",
|
||||
};
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
interface IBlipProperties {
|
||||
embed: string;
|
||||
cstate: string;
|
||||
readonly embed: string;
|
||||
readonly cstate: string;
|
||||
}
|
||||
|
||||
class BlipAttributes extends XmlAttributeComponent<IBlipProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
embed: "r:embed",
|
||||
cstate: "cstate",
|
||||
};
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IPicLocksAttributes {
|
||||
noChangeAspect?: number;
|
||||
noChangeArrowheads?: number;
|
||||
readonly noChangeAspect?: number;
|
||||
readonly noChangeArrowheads?: number;
|
||||
}
|
||||
|
||||
export class PicLocksAttributes extends XmlAttributeComponent<IPicLocksAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
noChangeAspect: "noChangeAspect",
|
||||
noChangeArrowheads: "noChangeArrowheads",
|
||||
};
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface INonVisualPropertiesAttributes {
|
||||
id?: number;
|
||||
name?: string;
|
||||
descr?: string;
|
||||
readonly id?: number;
|
||||
readonly name?: string;
|
||||
readonly descr?: string;
|
||||
}
|
||||
|
||||
export class NonVisualPropertiesAttributes extends XmlAttributeComponent<INonVisualPropertiesAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
id: "id",
|
||||
name: "name",
|
||||
descr: "desc",
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IPicAttributes {
|
||||
xmlns?: string;
|
||||
readonly xmlns?: string;
|
||||
}
|
||||
|
||||
export class PicAttributes extends XmlAttributeComponent<IPicAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
xmlns: "xmlns:pic",
|
||||
};
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IExtentsAttributes {
|
||||
cx?: number;
|
||||
cy?: number;
|
||||
readonly cx?: number;
|
||||
readonly cy?: number;
|
||||
}
|
||||
|
||||
export class ExtentsAttributes extends XmlAttributeComponent<IExtentsAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
cx: "cx",
|
||||
cy: "cy",
|
||||
};
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IOffsetAttributes {
|
||||
x?: number;
|
||||
y?: number;
|
||||
readonly x?: number;
|
||||
readonly y?: number;
|
||||
}
|
||||
|
||||
export class OffsetAttributes extends XmlAttributeComponent<IOffsetAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
x: "x",
|
||||
y: "y",
|
||||
};
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IPresetGeometryAttributes {
|
||||
prst?: string;
|
||||
readonly prst?: string;
|
||||
}
|
||||
|
||||
export class PresetGeometryAttributes extends XmlAttributeComponent<IPresetGeometryAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
prst: "prst",
|
||||
};
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IShapePropertiesAttributes {
|
||||
bwMode?: string;
|
||||
readonly bwMode?: string;
|
||||
}
|
||||
|
||||
export class ShapePropertiesAttributes extends XmlAttributeComponent<IShapePropertiesAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
bwMode: "bwMode",
|
||||
};
|
||||
}
|
||||
|
@ -2,11 +2,11 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { GraphicData } from "./graphic-data";
|
||||
|
||||
interface IGraphicProperties {
|
||||
a: string;
|
||||
readonly a: string;
|
||||
}
|
||||
|
||||
class GraphicAttributes extends XmlAttributeComponent<IGraphicProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
a: "xmlns:a",
|
||||
};
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import { IDistance } from "../drawing";
|
||||
export interface IInlineAttributes extends IDistance {}
|
||||
|
||||
export class InlineAttributes extends XmlAttributeComponent<IInlineAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
distT: "distT",
|
||||
distB: "distB",
|
||||
distL: "distL",
|
||||
|
@ -16,7 +16,7 @@ export enum WrapTextOption {
|
||||
}
|
||||
|
||||
export interface ITextWrapping {
|
||||
textWrapStyle: TextWrapStyle;
|
||||
wrapTextOption?: WrapTextOption;
|
||||
distanceFromText?: IDistance;
|
||||
readonly textWrapStyle: TextWrapStyle;
|
||||
readonly wrapTextOption?: WrapTextOption;
|
||||
readonly distanceFromText?: IDistance;
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ import { ITextWrapping, WrapTextOption } from ".";
|
||||
import { IDistance } from "../drawing";
|
||||
|
||||
interface IWrapSquareAttributes extends IDistance {
|
||||
wrapText?: WrapTextOption;
|
||||
readonly wrapText?: WrapTextOption;
|
||||
}
|
||||
|
||||
class WrapSquareAttributes extends XmlAttributeComponent<IWrapSquareAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
distT: "distT",
|
||||
distB: "distB",
|
||||
distL: "distL",
|
||||
|
@ -3,25 +3,25 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { IDistance } from "../drawing";
|
||||
|
||||
interface IWrapTightAttributes {
|
||||
distT?: number;
|
||||
distB?: number;
|
||||
readonly distT?: number;
|
||||
readonly distB?: number;
|
||||
}
|
||||
|
||||
class WrapTightAttributes extends XmlAttributeComponent<IWrapTightAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
distT: "distT",
|
||||
distB: "distB",
|
||||
};
|
||||
}
|
||||
|
||||
export class WrapTight extends XmlComponent {
|
||||
constructor(distanceFromText?: IDistance) {
|
||||
super("wp:wrapTight");
|
||||
|
||||
distanceFromText = distanceFromText || {
|
||||
constructor(
|
||||
distanceFromText: IDistance = {
|
||||
distT: 0,
|
||||
distB: 0,
|
||||
};
|
||||
},
|
||||
) {
|
||||
super("wp:wrapTight");
|
||||
|
||||
this.root.push(
|
||||
new WrapTightAttributes({
|
||||
|
@ -3,25 +3,25 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { IDistance } from "../drawing";
|
||||
|
||||
interface IWrapTopAndBottomAttributes {
|
||||
distT?: number;
|
||||
distB?: number;
|
||||
readonly distT?: number;
|
||||
readonly distB?: number;
|
||||
}
|
||||
|
||||
class WrapTopAndBottomAttributes extends XmlAttributeComponent<IWrapTopAndBottomAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
distT: "distT",
|
||||
distB: "distB",
|
||||
};
|
||||
}
|
||||
|
||||
export class WrapTopAndBottom extends XmlComponent {
|
||||
constructor(distanceFromText?: IDistance) {
|
||||
super("wp:wrapTopAndBottom");
|
||||
|
||||
distanceFromText = distanceFromText || {
|
||||
constructor(
|
||||
distanceFromText: IDistance = {
|
||||
distT: 0,
|
||||
distB: 0,
|
||||
};
|
||||
},
|
||||
) {
|
||||
super("wp:wrapTopAndBottom");
|
||||
|
||||
this.root.push(
|
||||
new WrapTopAndBottomAttributes({
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { IDocumentTemplate } from "../import-dotx";
|
||||
|
||||
export interface IFileProperties {
|
||||
template?: IDocumentTemplate;
|
||||
readonly template?: IDocumentTemplate;
|
||||
}
|
||||
|
||||
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432
|
||||
|
@ -25,6 +25,7 @@ import { Table } from "./table";
|
||||
import { TableOfContents } from "./table-of-contents";
|
||||
|
||||
export class File {
|
||||
// tslint:disable-next-line:readonly-keyword
|
||||
private currentRelationshipId: number = 1;
|
||||
|
||||
private readonly document: Document;
|
||||
@ -39,6 +40,7 @@ export class File {
|
||||
private readonly settings: Settings;
|
||||
private readonly contentTypes: ContentTypes;
|
||||
private readonly appProperties: AppProperties;
|
||||
// tslint:disable-next-line:readonly-keyword
|
||||
private styles: Styles;
|
||||
|
||||
constructor(
|
||||
@ -95,13 +97,13 @@ export class File {
|
||||
this.createFooter();
|
||||
}
|
||||
|
||||
sectionPropertiesOptions = {
|
||||
const newSectionPropertiesOptions = {
|
||||
...sectionPropertiesOptions,
|
||||
headers: this.groupHeaders(this.headers, sectionPropertiesOptions.headers),
|
||||
footers: this.groupFooters(this.footers, sectionPropertiesOptions.footers),
|
||||
};
|
||||
|
||||
this.document = new Document(sectionPropertiesOptions);
|
||||
this.document = new Document(newSectionPropertiesOptions);
|
||||
this.settings = new Settings();
|
||||
}
|
||||
|
||||
@ -139,8 +141,8 @@ export class File {
|
||||
}
|
||||
|
||||
public createHyperlink(link: string, text?: string): Hyperlink {
|
||||
text = text === undefined ? link : text;
|
||||
const hyperlink = new Hyperlink(text, this.docRelationships.RelationshipCount);
|
||||
const newText = text === undefined ? link : text;
|
||||
const hyperlink = new Hyperlink(newText, this.docRelationships.RelationshipCount);
|
||||
this.docRelationships.createRelationship(
|
||||
hyperlink.linkId,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
|
||||
@ -151,16 +153,16 @@ export class File {
|
||||
}
|
||||
|
||||
public createInternalHyperLink(anchor: string, text?: string): Hyperlink {
|
||||
text = text === undefined ? anchor : text;
|
||||
const hyperlink = new Hyperlink(text, this.docRelationships.RelationshipCount, anchor);
|
||||
const newText = text === undefined ? anchor : text;
|
||||
const hyperlink = new Hyperlink(newText, this.docRelationships.RelationshipCount, anchor);
|
||||
// NOTE: unlike File#createHyperlink(), since the link is to an internal bookmark
|
||||
// we don't need to create a new relationship.
|
||||
return hyperlink;
|
||||
}
|
||||
|
||||
public createBookmark(name: string, text?: string): Bookmark {
|
||||
text = text === undefined ? name : text;
|
||||
const bookmark = new Bookmark(name, text, this.docRelationships.RelationshipCount);
|
||||
const newText = text === undefined ? name : text;
|
||||
const bookmark = new Bookmark(name, newText, this.docRelationships.RelationshipCount);
|
||||
return bookmark;
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,8 @@ import { Relationships } from "./relationships";
|
||||
import { Table } from "./table";
|
||||
|
||||
export interface IDocumentFooter {
|
||||
footer: FooterWrapper;
|
||||
type: FooterReferenceType;
|
||||
readonly footer: FooterWrapper;
|
||||
readonly type: FooterReferenceType;
|
||||
}
|
||||
|
||||
export class FooterWrapper {
|
||||
|
@ -1,32 +1,32 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IFooterAttributesProperties {
|
||||
wpc?: string;
|
||||
mc?: string;
|
||||
o?: string;
|
||||
r?: string;
|
||||
m?: string;
|
||||
v?: string;
|
||||
wp14?: string;
|
||||
wp?: string;
|
||||
w10?: string;
|
||||
w?: string;
|
||||
w14?: string;
|
||||
w15?: string;
|
||||
wpg?: string;
|
||||
wpi?: string;
|
||||
wne?: string;
|
||||
wps?: string;
|
||||
cp?: string;
|
||||
dc?: string;
|
||||
dcterms?: string;
|
||||
dcmitype?: string;
|
||||
xsi?: string;
|
||||
type?: string;
|
||||
readonly wpc?: string;
|
||||
readonly mc?: string;
|
||||
readonly o?: string;
|
||||
readonly r?: string;
|
||||
readonly m?: string;
|
||||
readonly v?: string;
|
||||
readonly wp14?: string;
|
||||
readonly wp?: string;
|
||||
readonly w10?: string;
|
||||
readonly w?: string;
|
||||
readonly w14?: string;
|
||||
readonly w15?: string;
|
||||
readonly wpg?: string;
|
||||
readonly wpi?: string;
|
||||
readonly wne?: string;
|
||||
readonly wps?: string;
|
||||
readonly cp?: string;
|
||||
readonly dc?: string;
|
||||
readonly dcterms?: string;
|
||||
readonly dcmitype?: string;
|
||||
readonly xsi?: string;
|
||||
readonly type?: string;
|
||||
}
|
||||
|
||||
export class FooterAttributes extends XmlAttributeComponent<IFooterAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
wpc: "xmlns:wpc",
|
||||
mc: "xmlns:mc",
|
||||
o: "xmlns:o",
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IFootnoteAttributesProperties {
|
||||
type?: string;
|
||||
id: number;
|
||||
readonly type?: string;
|
||||
readonly id: number;
|
||||
}
|
||||
|
||||
export class FootnoteAttributes extends XmlAttributeComponent<IFootnoteAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
type: "w:type",
|
||||
id: "w:id",
|
||||
};
|
||||
|
@ -3,11 +3,11 @@ import { Style } from "file/paragraph/run/style";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export interface IFootNoteReferenceRunAttributesProperties {
|
||||
id: number;
|
||||
readonly id: number;
|
||||
}
|
||||
|
||||
export class FootNoteReferenceRunAttributes extends XmlAttributeComponent<IFootNoteReferenceRunAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
id: "w:id",
|
||||
};
|
||||
}
|
||||
|
@ -1,27 +1,27 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IFootnotesAttributesProperties {
|
||||
wpc?: string;
|
||||
mc?: string;
|
||||
o?: string;
|
||||
r?: string;
|
||||
m?: string;
|
||||
v?: string;
|
||||
wp14?: string;
|
||||
wp?: string;
|
||||
w10?: string;
|
||||
w?: string;
|
||||
w14?: string;
|
||||
w15?: string;
|
||||
wpg?: string;
|
||||
wpi?: string;
|
||||
wne?: string;
|
||||
wps?: string;
|
||||
Ignorable?: string;
|
||||
readonly wpc?: string;
|
||||
readonly mc?: string;
|
||||
readonly o?: string;
|
||||
readonly r?: string;
|
||||
readonly m?: string;
|
||||
readonly v?: string;
|
||||
readonly wp14?: string;
|
||||
readonly wp?: string;
|
||||
readonly w10?: string;
|
||||
readonly w?: string;
|
||||
readonly w14?: string;
|
||||
readonly w15?: string;
|
||||
readonly wpg?: string;
|
||||
readonly wpi?: string;
|
||||
readonly wne?: string;
|
||||
readonly wps?: string;
|
||||
readonly Ignorable?: string;
|
||||
}
|
||||
|
||||
export class FootnotesAttributes extends XmlAttributeComponent<IFootnotesAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
wpc: "xmlns:wpc",
|
||||
mc: "xmlns:mc",
|
||||
o: "xmlns:o",
|
||||
|
@ -6,12 +6,13 @@ import { SeperatorRun } from "./footnote/run/seperator-run";
|
||||
import { FootnotesAttributes } from "./footnotes-attributes";
|
||||
|
||||
export class FootNotes extends XmlComponent {
|
||||
private counter: number;
|
||||
// tslint:disable-next-line:readonly-keyword
|
||||
private currentId: number;
|
||||
|
||||
constructor() {
|
||||
super("w:footnotes");
|
||||
|
||||
this.counter = 1;
|
||||
this.currentId = 1;
|
||||
|
||||
this.root.push(
|
||||
new FootnotesAttributes({
|
||||
@ -61,10 +62,10 @@ export class FootNotes extends XmlComponent {
|
||||
}
|
||||
|
||||
public createFootNote(paragraph: Paragraph): void {
|
||||
const footnote = new Footnote(this.counter);
|
||||
const footnote = new Footnote(this.currentId);
|
||||
footnote.addParagraph(paragraph);
|
||||
this.root.push(footnote);
|
||||
|
||||
this.counter++;
|
||||
this.currentId++;
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ import { Relationships } from "./relationships";
|
||||
import { Table } from "./table";
|
||||
|
||||
export interface IDocumentHeader {
|
||||
header: HeaderWrapper;
|
||||
type: HeaderReferenceType;
|
||||
readonly header: HeaderWrapper;
|
||||
readonly type: HeaderReferenceType;
|
||||
}
|
||||
|
||||
export class HeaderWrapper {
|
||||
|
@ -1,43 +1,43 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IHeaderAttributesProperties {
|
||||
wpc?: string;
|
||||
mc?: string;
|
||||
o?: string;
|
||||
r?: string;
|
||||
m?: string;
|
||||
v?: string;
|
||||
wp14?: string;
|
||||
wp?: string;
|
||||
w10?: string;
|
||||
w?: string;
|
||||
w14?: string;
|
||||
w15?: string;
|
||||
wpg?: string;
|
||||
wpi?: string;
|
||||
wne?: string;
|
||||
wps?: string;
|
||||
cp?: string;
|
||||
dc?: string;
|
||||
dcterms?: string;
|
||||
dcmitype?: string;
|
||||
xsi?: string;
|
||||
type?: string;
|
||||
cx?: string;
|
||||
cx1?: string;
|
||||
cx2?: string;
|
||||
cx3?: string;
|
||||
cx4?: string;
|
||||
cx5?: string;
|
||||
cx6?: string;
|
||||
cx7?: string;
|
||||
cx8?: string;
|
||||
w16cid: string;
|
||||
w16se: string;
|
||||
readonly wpc?: string;
|
||||
readonly mc?: string;
|
||||
readonly o?: string;
|
||||
readonly r?: string;
|
||||
readonly m?: string;
|
||||
readonly v?: string;
|
||||
readonly wp14?: string;
|
||||
readonly wp?: string;
|
||||
readonly w10?: string;
|
||||
readonly w?: string;
|
||||
readonly w14?: string;
|
||||
readonly w15?: string;
|
||||
readonly wpg?: string;
|
||||
readonly wpi?: string;
|
||||
readonly wne?: string;
|
||||
readonly wps?: string;
|
||||
readonly cp?: string;
|
||||
readonly dc?: string;
|
||||
readonly dcterms?: string;
|
||||
readonly dcmitype?: string;
|
||||
readonly xsi?: string;
|
||||
readonly type?: string;
|
||||
readonly cx?: string;
|
||||
readonly cx1?: string;
|
||||
readonly cx2?: string;
|
||||
readonly cx3?: string;
|
||||
readonly cx4?: string;
|
||||
readonly cx5?: string;
|
||||
readonly cx6?: string;
|
||||
readonly cx7?: string;
|
||||
readonly cx8?: string;
|
||||
readonly w16cid: string;
|
||||
readonly w16se: string;
|
||||
}
|
||||
|
||||
export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
wpc: "xmlns:wpc",
|
||||
mc: "xmlns:mc",
|
||||
o: "xmlns:o",
|
||||
|
@ -1,20 +1,20 @@
|
||||
export interface IMediaDataDimensions {
|
||||
pixels: {
|
||||
x: number;
|
||||
y: number;
|
||||
readonly pixels: {
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
};
|
||||
emus: {
|
||||
x: number;
|
||||
y: number;
|
||||
readonly emus: {
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IMediaData {
|
||||
referenceId: number;
|
||||
stream: Buffer | Uint8Array | ArrayBuffer;
|
||||
path?: string;
|
||||
fileName: string;
|
||||
dimensions: IMediaDataDimensions;
|
||||
readonly referenceId: number;
|
||||
readonly stream: Buffer | Uint8Array | ArrayBuffer;
|
||||
readonly path?: string;
|
||||
readonly fileName: string;
|
||||
readonly dimensions: IMediaDataDimensions;
|
||||
}
|
||||
|
||||
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432
|
||||
|
@ -5,6 +5,7 @@ import { IMediaData } from "./data";
|
||||
import { Image } from "./image";
|
||||
|
||||
interface IHackedFile {
|
||||
// tslint:disable-next-line:readonly-keyword
|
||||
currentRelationshipId: number;
|
||||
}
|
||||
|
||||
@ -78,17 +79,15 @@ export class Media {
|
||||
private createMedia(
|
||||
key: string,
|
||||
relationshipsCount: number,
|
||||
dimensions: { width: number; height: number },
|
||||
dimensions: { readonly width: number; readonly height: number },
|
||||
data: Buffer | string | Uint8Array | ArrayBuffer,
|
||||
filePath?: string,
|
||||
): IMediaData {
|
||||
if (typeof data === "string") {
|
||||
data = this.convertDataURIToBinary(data);
|
||||
}
|
||||
const newData = typeof data === "string" ? this.convertDataURIToBinary(data) : data;
|
||||
|
||||
const imageData = {
|
||||
const imageData: IMediaData = {
|
||||
referenceId: relationshipsCount,
|
||||
stream: data,
|
||||
stream: newData,
|
||||
path: filePath,
|
||||
fileName: key,
|
||||
dimensions: {
|
||||
|
@ -3,19 +3,19 @@ import { Level } from "./level";
|
||||
import { MultiLevelType } from "./multi-level-type";
|
||||
|
||||
interface IAbstractNumberingAttributesProperties {
|
||||
abstractNumId?: number;
|
||||
restartNumberingAfterBreak?: number;
|
||||
readonly abstractNumId?: number;
|
||||
readonly restartNumberingAfterBreak?: number;
|
||||
}
|
||||
|
||||
class AbstractNumberingAttributes extends XmlAttributeComponent<IAbstractNumberingAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
abstractNumId: "w:abstractNumId",
|
||||
restartNumberingAfterBreak: "w15:restartNumberingAfterBreak",
|
||||
};
|
||||
}
|
||||
|
||||
export class AbstractNumbering extends XmlComponent {
|
||||
public id: number;
|
||||
public readonly id: number;
|
||||
|
||||
constructor(id: number) {
|
||||
super("w:abstractNum");
|
||||
|
@ -1,16 +1,27 @@
|
||||
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 * as formatting from "../paragraph/run/formatting";
|
||||
import { RunProperties } from "../paragraph/run/properties";
|
||||
|
||||
interface ILevelAttributesProperties {
|
||||
ilvl?: number;
|
||||
tentative?: number;
|
||||
readonly ilvl?: number;
|
||||
readonly tentative?: number;
|
||||
}
|
||||
|
||||
class LevelAttributes extends XmlAttributeComponent<ILevelAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
ilvl: "w:ilvl",
|
||||
tentative: "w15:tentative",
|
||||
};
|
||||
@ -190,57 +201,57 @@ export class LevelBase extends XmlComponent {
|
||||
// --------------------- Paragraph formatting ------------------------ //
|
||||
|
||||
public center(): Level {
|
||||
this.addParagraphProperty(new paragraph.Alignment("center"));
|
||||
this.addParagraphProperty(new Alignment(AlignmentOptions.CENTER));
|
||||
return this;
|
||||
}
|
||||
|
||||
public left(): Level {
|
||||
this.addParagraphProperty(new paragraph.Alignment("left"));
|
||||
this.addParagraphProperty(new Alignment(AlignmentOptions.LEFT));
|
||||
return this;
|
||||
}
|
||||
|
||||
public right(): Level {
|
||||
this.addParagraphProperty(new paragraph.Alignment("right"));
|
||||
this.addParagraphProperty(new Alignment(AlignmentOptions.RIGHT));
|
||||
return this;
|
||||
}
|
||||
|
||||
public justified(): Level {
|
||||
this.addParagraphProperty(new paragraph.Alignment("both"));
|
||||
this.addParagraphProperty(new Alignment(AlignmentOptions.BOTH));
|
||||
return this;
|
||||
}
|
||||
|
||||
public thematicBreak(): Level {
|
||||
this.addParagraphProperty(new paragraph.ThematicBreak());
|
||||
this.addParagraphProperty(new ThematicBreak());
|
||||
return this;
|
||||
}
|
||||
|
||||
public maxRightTabStop(): Level {
|
||||
this.addParagraphProperty(new paragraph.MaxRightTabStop());
|
||||
this.addParagraphProperty(new MaxRightTabStop());
|
||||
return this;
|
||||
}
|
||||
|
||||
public leftTabStop(position: number): Level {
|
||||
this.addParagraphProperty(new paragraph.LeftTabStop(position));
|
||||
this.addParagraphProperty(new LeftTabStop(position));
|
||||
return this;
|
||||
}
|
||||
|
||||
public indent(attrs: object): Level {
|
||||
this.addParagraphProperty(new paragraph.Indent(attrs));
|
||||
this.addParagraphProperty(new Indent(attrs));
|
||||
return this;
|
||||
}
|
||||
|
||||
public spacing(params: paragraph.ISpacingProperties): Level {
|
||||
this.addParagraphProperty(new paragraph.Spacing(params));
|
||||
public spacing(params: ISpacingProperties): Level {
|
||||
this.addParagraphProperty(new Spacing(params));
|
||||
return this;
|
||||
}
|
||||
|
||||
public keepNext(): Level {
|
||||
this.addParagraphProperty(new paragraph.KeepNext());
|
||||
this.addParagraphProperty(new KeepNext());
|
||||
return this;
|
||||
}
|
||||
|
||||
public keepLines(): Level {
|
||||
this.addParagraphProperty(new paragraph.KeepLines());
|
||||
this.addParagraphProperty(new KeepLines());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -13,15 +13,15 @@ class AbstractNumId extends XmlComponent {
|
||||
}
|
||||
|
||||
interface INumAttributesProperties {
|
||||
numId: number;
|
||||
readonly numId: number;
|
||||
}
|
||||
|
||||
class NumAttributes extends XmlAttributeComponent<INumAttributesProperties> {
|
||||
protected xmlKeys = { numId: "w:numId" };
|
||||
protected readonly xmlKeys = { numId: "w:numId" };
|
||||
}
|
||||
|
||||
export class Num extends XmlComponent {
|
||||
public id: number;
|
||||
public readonly id: number;
|
||||
|
||||
constructor(numId: number, abstractNumId: number) {
|
||||
super("w:num");
|
||||
@ -41,12 +41,12 @@ export class Num extends XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
class LevelOverrideAttributes extends XmlAttributeComponent<{ ilvl: number }> {
|
||||
protected xmlKeys = { ilvl: "w:ilvl" };
|
||||
class LevelOverrideAttributes extends XmlAttributeComponent<{ readonly ilvl: number }> {
|
||||
protected readonly xmlKeys = { ilvl: "w:ilvl" };
|
||||
}
|
||||
|
||||
export class LevelOverride extends XmlComponent {
|
||||
private lvl?: LevelForOverride;
|
||||
private readonly lvl: LevelForOverride;
|
||||
|
||||
constructor(private readonly levelNum: number, start?: number) {
|
||||
super("w:lvlOverride");
|
||||
@ -54,23 +54,18 @@ export class LevelOverride extends XmlComponent {
|
||||
if (start !== undefined) {
|
||||
this.root.push(new StartOverride(start));
|
||||
}
|
||||
|
||||
this.lvl = new LevelForOverride(this.levelNum);
|
||||
this.root.push(this.lvl);
|
||||
}
|
||||
|
||||
public get Level(): LevelForOverride {
|
||||
let lvl: LevelForOverride;
|
||||
if (!this.lvl) {
|
||||
lvl = new LevelForOverride(this.levelNum);
|
||||
this.root.push(lvl);
|
||||
this.lvl = lvl;
|
||||
} else {
|
||||
lvl = this.lvl;
|
||||
}
|
||||
return lvl;
|
||||
return this.lvl;
|
||||
}
|
||||
}
|
||||
|
||||
class StartOverrideAttributes extends XmlAttributeComponent<{ val: number }> {
|
||||
protected xmlKeys = { val: "w:val" };
|
||||
class StartOverrideAttributes extends XmlAttributeComponent<{ readonly val: number }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
class StartOverride extends XmlComponent {
|
||||
|
@ -378,14 +378,69 @@ describe("concrete numbering", () => {
|
||||
it("sets a new override level for the given level number", () => {
|
||||
concreteNumbering.overrideLevel(3);
|
||||
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", () => {
|
||||
concreteNumbering.overrideLevel(1, 9);
|
||||
const tree = new Formatter().format(concreteNumbering);
|
||||
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": [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -5,6 +5,7 @@ import { AbstractNumbering } from "./abstract-numbering";
|
||||
import { Num } from "./num";
|
||||
|
||||
export class Numbering extends XmlComponent {
|
||||
// tslint:disable-next-line:readonly-keyword
|
||||
private nextId: number;
|
||||
|
||||
private readonly abstractNumbering: XmlComponent[] = [];
|
||||
|
@ -1,10 +1,18 @@
|
||||
// http://officeopenxml.com/WPalignment.php
|
||||
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 }> {
|
||||
protected xmlKeys = { val: "w:val" };
|
||||
export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentOptions }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
export class Alignment extends XmlComponent {
|
||||
|
@ -2,15 +2,15 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export interface IIndentAttributesProperties {
|
||||
left?: number;
|
||||
hanging?: number;
|
||||
firstLine?: number;
|
||||
start?: number;
|
||||
end?: number;
|
||||
readonly left?: number;
|
||||
readonly hanging?: number;
|
||||
readonly firstLine?: number;
|
||||
readonly start?: number;
|
||||
readonly end?: number;
|
||||
}
|
||||
|
||||
class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
left: "w:left",
|
||||
hanging: "w:hanging",
|
||||
firstLine: "w:firstLine",
|
||||
|
@ -2,14 +2,14 @@
|
||||
import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export interface ISpacingProperties {
|
||||
after?: number;
|
||||
before?: number;
|
||||
line?: number;
|
||||
lineRule?: string;
|
||||
readonly after?: number;
|
||||
readonly before?: number;
|
||||
readonly line?: number;
|
||||
readonly lineRule?: string;
|
||||
}
|
||||
|
||||
class SpacingAttributes extends XmlAttributeComponent<ISpacingProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
after: "w:after",
|
||||
before: "w:before",
|
||||
line: "w:line",
|
||||
|
@ -2,7 +2,7 @@ import { assert } from "chai";
|
||||
|
||||
import { Utility } from "tests/utility";
|
||||
|
||||
import { LeftTabStop, MaxRightTabStop, RightTabStop } from "./tab-stop";
|
||||
import { LeaderType, LeftTabStop, MaxRightTabStop, RightTabStop } from "./tab-stop";
|
||||
|
||||
describe("LeftTabStop", () => {
|
||||
let tabStop: LeftTabStop;
|
||||
@ -32,7 +32,7 @@ describe("RightTabStop", () => {
|
||||
let tabStop: RightTabStop;
|
||||
|
||||
beforeEach(() => {
|
||||
tabStop = new RightTabStop(100, "dot");
|
||||
tabStop = new RightTabStop(100, LeaderType.DOT);
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
|
@ -8,11 +8,32 @@ export class TabStop extends XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
export type TabValue = "left" | "right" | "center" | "bar" | "clear" | "decimal" | "end" | "num" | "start";
|
||||
export type LeaderType = "dot" | "hyphen" | "middleDot" | "none" | "underscore";
|
||||
export enum TabValue {
|
||||
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 }> {
|
||||
protected xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" };
|
||||
export enum LeaderType {
|
||||
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 {
|
||||
@ -30,24 +51,24 @@ export class TabStopItem extends XmlComponent {
|
||||
|
||||
export class MaxRightTabStop extends TabStop {
|
||||
constructor(leader?: LeaderType) {
|
||||
super(new TabStopItem("right", 9026, leader));
|
||||
super(new TabStopItem(TabValue.RIGHT, 9026, leader));
|
||||
}
|
||||
}
|
||||
|
||||
export class LeftTabStop extends TabStop {
|
||||
constructor(position: number, leader?: LeaderType) {
|
||||
super(new TabStopItem("left", position, leader));
|
||||
super(new TabStopItem(TabValue.LEFT, position, leader));
|
||||
}
|
||||
}
|
||||
|
||||
export class RightTabStop extends TabStop {
|
||||
constructor(position: number, leader?: LeaderType) {
|
||||
super(new TabStopItem("right", position, leader));
|
||||
super(new TabStopItem(TabValue.RIGHT, position, leader));
|
||||
}
|
||||
}
|
||||
|
||||
export class CenterTabStop extends TabStop {
|
||||
constructor(position: number, leader?: LeaderType) {
|
||||
super(new TabStopItem("center", position, leader));
|
||||
super(new TabStopItem(TabValue.CENTER, position, leader));
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IBookmarkStartAttributesProperties {
|
||||
id: string;
|
||||
name: string;
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
export class BookmarkStartAttributes extends XmlAttributeComponent<IBookmarkStartAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
id: "w:id",
|
||||
name: "w:name",
|
||||
};
|
||||
}
|
||||
|
||||
export interface IBookmarkEndAttributesProperties {
|
||||
id: string;
|
||||
readonly id: string;
|
||||
}
|
||||
|
||||
export class BookmarkEndAttributes extends XmlAttributeComponent<IBookmarkEndAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
id: "w:id",
|
||||
};
|
||||
}
|
||||
|
@ -1,16 +1,12 @@
|
||||
// http://officeopenxml.com/WPbookmark.php
|
||||
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { TextRun } from "../run";
|
||||
import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attributes";
|
||||
|
||||
export class Bookmark {
|
||||
public linkId: number;
|
||||
|
||||
public readonly linkId: number;
|
||||
public readonly start: BookmarkStart;
|
||||
|
||||
public readonly text: TextRun;
|
||||
|
||||
public readonly end: BookmarkEnd;
|
||||
|
||||
constructor(name: string, text: string, relationshipsCount: number) {
|
||||
@ -23,7 +19,7 @@ export class Bookmark {
|
||||
}
|
||||
|
||||
export class BookmarkStart extends XmlComponent {
|
||||
public linkId: number;
|
||||
public readonly linkId: number;
|
||||
|
||||
constructor(name: string, relationshipsCount: number) {
|
||||
super("w:bookmarkStart");
|
||||
@ -39,7 +35,7 @@ export class BookmarkStart extends XmlComponent {
|
||||
}
|
||||
|
||||
export class BookmarkEnd extends XmlComponent {
|
||||
public linkId: number;
|
||||
public readonly linkId: number;
|
||||
|
||||
constructor(relationshipsCount: number) {
|
||||
super("w:bookmarkEnd");
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IHyperlinkAttributesProperties {
|
||||
id?: string;
|
||||
anchor?: string;
|
||||
history: number;
|
||||
readonly id?: string;
|
||||
readonly anchor?: string;
|
||||
readonly history: number;
|
||||
}
|
||||
|
||||
export class HyperlinkAttributes extends XmlAttributeComponent<IHyperlinkAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
id: "r:id",
|
||||
history: "w:history",
|
||||
anchor: "w:anchor",
|
||||
|
@ -1,11 +1,10 @@
|
||||
// http://officeopenxml.com/WPhyperlink.php
|
||||
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { TextRun } from "../run";
|
||||
import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes";
|
||||
|
||||
export class Hyperlink extends XmlComponent {
|
||||
public linkId: number;
|
||||
public readonly linkId: number;
|
||||
|
||||
constructor(text: string, relationshipsCount: number, anchor?: string) {
|
||||
super("w:hyperlink");
|
||||
@ -14,14 +13,10 @@ export class Hyperlink extends XmlComponent {
|
||||
|
||||
const props: IHyperlinkAttributesProperties = {
|
||||
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);
|
||||
this.root.push(attributes);
|
||||
this.root.push(new TextRun(text).style("Hyperlink"));
|
||||
|
@ -4,7 +4,7 @@ import { Image } from "file/media";
|
||||
import { Num } from "file/numbering/num";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { Alignment } from "./formatting/alignment";
|
||||
import { Alignment, AlignmentOptions } from "./formatting/alignment";
|
||||
import { Bidirectional } from "./formatting/bidirectional";
|
||||
import { Border, ThematicBreak } from "./formatting/border";
|
||||
import { IIndentAttributesProperties, Indent } from "./formatting/indent";
|
||||
@ -110,37 +110,37 @@ export class Paragraph extends XmlComponent {
|
||||
}
|
||||
|
||||
public center(): Paragraph {
|
||||
this.properties.push(new Alignment("center"));
|
||||
this.properties.push(new Alignment(AlignmentOptions.CENTER));
|
||||
return this;
|
||||
}
|
||||
|
||||
public left(): Paragraph {
|
||||
this.properties.push(new Alignment("left"));
|
||||
this.properties.push(new Alignment(AlignmentOptions.LEFT));
|
||||
return this;
|
||||
}
|
||||
|
||||
public right(): Paragraph {
|
||||
this.properties.push(new Alignment("right"));
|
||||
this.properties.push(new Alignment(AlignmentOptions.RIGHT));
|
||||
return this;
|
||||
}
|
||||
|
||||
public start(): Paragraph {
|
||||
this.properties.push(new Alignment("start"));
|
||||
this.properties.push(new Alignment(AlignmentOptions.START));
|
||||
return this;
|
||||
}
|
||||
|
||||
public end(): Paragraph {
|
||||
this.properties.push(new Alignment("end"));
|
||||
this.properties.push(new Alignment(AlignmentOptions.END));
|
||||
return this;
|
||||
}
|
||||
|
||||
public distribute(): Paragraph {
|
||||
this.properties.push(new Alignment("distribute"));
|
||||
this.properties.push(new Alignment(AlignmentOptions.DISTRIBUTE));
|
||||
return this;
|
||||
}
|
||||
|
||||
public justified(): Paragraph {
|
||||
this.properties.push(new Alignment("both"));
|
||||
this.properties.push(new Alignment(AlignmentOptions.BOTH));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { Border } from "./formatting/border";
|
||||
|
||||
export class ParagraphProperties extends XmlComponent {
|
||||
public paragraphBorder: Border;
|
||||
public readonly paragraphBorder: Border;
|
||||
|
||||
constructor() {
|
||||
super("w:pPr");
|
||||
|
@ -1,26 +1,32 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class FidCharAttrs extends XmlAttributeComponent<{ type: "begin" | "end" | "separate"; dirty?: boolean }> {
|
||||
protected xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" };
|
||||
enum FieldCharacterType {
|
||||
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 {
|
||||
constructor(dirty?: boolean) {
|
||||
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 {
|
||||
constructor(dirty?: boolean) {
|
||||
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 {
|
||||
constructor(dirty?: boolean) {
|
||||
super("w:fldChar");
|
||||
this.root.push(new FidCharAttrs({ type: "end", dirty }));
|
||||
this.root.push(new FidCharAttrs({ type: FieldCharacterType.END, dirty }));
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { SpaceType } from "file/space-type";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> {
|
||||
protected xmlKeys = { space: "xml:space" };
|
||||
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
|
||||
protected readonly xmlKeys = { space: "xml:space" };
|
||||
}
|
||||
|
||||
export class Page extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:instrText");
|
||||
this.root.push(new TextAttributes({ space: "preserve" }));
|
||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||
this.root.push("PAGE");
|
||||
}
|
||||
}
|
||||
|
@ -18,15 +18,7 @@ export class PictureRun extends Run {
|
||||
this.root.push(this.drawing);
|
||||
}
|
||||
|
||||
public scale(factorX: number, factorY?: number): void {
|
||||
if (!factorX) {
|
||||
factorX = 1;
|
||||
}
|
||||
|
||||
if (!factorY) {
|
||||
factorY = factorX;
|
||||
}
|
||||
|
||||
public scale(factorX: number = 1, factorY: number = factorX): void {
|
||||
this.drawing.scale(factorX, factorY);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { SpaceType } from "file/space-type";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> {
|
||||
protected xmlKeys = { space: "xml:space" };
|
||||
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
|
||||
protected readonly xmlKeys = { space: "xml:space" };
|
||||
}
|
||||
|
||||
export class Text extends XmlComponent {
|
||||
constructor(text: string) {
|
||||
super("w:t");
|
||||
this.root.push(new TextAttributes({ space: "preserve" }));
|
||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||
if (text) {
|
||||
this.root.push(text);
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
interface IRunFontAttributesProperties {
|
||||
ascii: string;
|
||||
cs: string;
|
||||
eastAsia: string;
|
||||
hAnsi: string;
|
||||
hint?: string;
|
||||
readonly ascii: string;
|
||||
readonly cs: string;
|
||||
readonly eastAsia: string;
|
||||
readonly hAnsi: string;
|
||||
readonly hint?: string;
|
||||
}
|
||||
|
||||
class RunFontAttributes extends XmlAttributeComponent<IRunFontAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
ascii: "w:ascii",
|
||||
cs: "w:cs",
|
||||
eastAsia: "w:eastAsia",
|
||||
|
@ -25,7 +25,7 @@ import { Underline } from "./underline";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
export class Run extends XmlComponent {
|
||||
protected properties: RunProperties;
|
||||
protected readonly properties: RunProperties;
|
||||
|
||||
constructor() {
|
||||
super("w:r");
|
||||
|
@ -1,13 +1,9 @@
|
||||
// http://officeopenxml.com/WPfieldInstructions.php
|
||||
import { SpaceType } from "file/space-type";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
enum SpaceType {
|
||||
DEFAULT = "default",
|
||||
PRESERVE = "preserve",
|
||||
}
|
||||
|
||||
class TextAttributes extends XmlAttributeComponent<{ space: SpaceType }> {
|
||||
protected xmlKeys = { space: "xml:space" };
|
||||
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
|
||||
protected readonly xmlKeys = { space: "xml:space" };
|
||||
}
|
||||
|
||||
export class SequentialIdentifierInstruction extends XmlComponent {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class StyleAttributes extends XmlAttributeComponent<{ val: string }> {
|
||||
protected xmlKeys = { val: "w:val" };
|
||||
class StyleAttributes extends XmlAttributeComponent<{ readonly val: string }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
export class Style extends XmlComponent {
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IRelationshipsAttributesProperties {
|
||||
xmlns: string;
|
||||
readonly xmlns: string;
|
||||
}
|
||||
|
||||
export class RelationshipsAttributes extends XmlAttributeComponent<IRelationshipsAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
xmlns: "xmlns",
|
||||
};
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IRelationshipAttributesProperties {
|
||||
id: string;
|
||||
type: string;
|
||||
target: string;
|
||||
targetMode?: string;
|
||||
readonly id: string;
|
||||
readonly type: string;
|
||||
readonly target: string;
|
||||
readonly targetMode?: string;
|
||||
}
|
||||
|
||||
export class RelationshipAttributes extends XmlAttributeComponent<IRelationshipAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
id: "Id",
|
||||
type: "Type",
|
||||
target: "Target",
|
||||
|
@ -1,26 +1,26 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { UpdateFields } from "./update-fields";
|
||||
export interface ISettingsAttributesProperties {
|
||||
wpc?: string;
|
||||
mc?: string;
|
||||
o?: string;
|
||||
r?: string;
|
||||
m?: string;
|
||||
v?: string;
|
||||
wp14?: string;
|
||||
wp?: string;
|
||||
w10?: string;
|
||||
w?: string;
|
||||
w14?: string;
|
||||
w15?: string;
|
||||
wpg?: string;
|
||||
wpi?: string;
|
||||
wne?: string;
|
||||
wps?: string;
|
||||
Ignorable?: string;
|
||||
readonly wpc?: string;
|
||||
readonly mc?: string;
|
||||
readonly o?: string;
|
||||
readonly r?: string;
|
||||
readonly m?: string;
|
||||
readonly v?: string;
|
||||
readonly wp14?: string;
|
||||
readonly wp?: string;
|
||||
readonly w10?: string;
|
||||
readonly w?: string;
|
||||
readonly w14?: string;
|
||||
readonly w15?: string;
|
||||
readonly wpg?: string;
|
||||
readonly wpi?: string;
|
||||
readonly wne?: string;
|
||||
readonly wps?: string;
|
||||
readonly Ignorable?: string;
|
||||
}
|
||||
export class SettingsAttributes extends XmlAttributeComponent<ISettingsAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
wpc: "xmlns:wpc",
|
||||
mc: "xmlns:mc",
|
||||
o: "xmlns:o",
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
export interface IUpdateFieldsAttributesProperties {
|
||||
enabled: boolean;
|
||||
readonly enabled: boolean;
|
||||
}
|
||||
export class UpdateFieldsAttributes extends XmlAttributeComponent<IUpdateFieldsAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
enabled: "w:val",
|
||||
};
|
||||
}
|
||||
|
4
src/file/space-type.ts
Normal file
4
src/file/space-type.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum SpaceType {
|
||||
DEFAULT = "default",
|
||||
PRESERVE = "preserve",
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export interface ILatentStyleExceptionAttributesProperties {
|
||||
name?: string;
|
||||
uiPriority?: string;
|
||||
qFormat?: string;
|
||||
semiHidden?: string;
|
||||
unhideWhenUsed?: string;
|
||||
readonly name?: string;
|
||||
readonly uiPriority?: string;
|
||||
readonly qFormat?: string;
|
||||
readonly semiHidden?: string;
|
||||
readonly unhideWhenUsed?: string;
|
||||
}
|
||||
|
||||
export class LatentStyleExceptionAttributes extends XmlAttributeComponent<ILatentStyleExceptionAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
name: "w:name",
|
||||
uiPriority: "w:uiPriority",
|
||||
qFormat: "w:qFormat",
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
interface IComponentAttributes {
|
||||
val: string;
|
||||
readonly val: string;
|
||||
}
|
||||
|
||||
class ComponentAttributes extends XmlAttributeComponent<IComponentAttributes> {
|
||||
protected xmlKeys = { val: "w:val" };
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
export class Name extends XmlComponent {
|
||||
|
@ -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 { RunProperties } from "file/paragraph/run/properties";
|
||||
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";
|
||||
|
||||
export interface IStyleAttributes {
|
||||
type?: string;
|
||||
styleId?: string;
|
||||
default?: boolean;
|
||||
customStyle?: string;
|
||||
readonly type?: string;
|
||||
readonly styleId?: string;
|
||||
readonly default?: boolean;
|
||||
readonly customStyle?: string;
|
||||
}
|
||||
|
||||
class StyleAttributes extends XmlAttributeComponent<IStyleAttributes> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
type: "w:type",
|
||||
styleId: "w:styleId",
|
||||
default: "w:default",
|
||||
@ -36,12 +48,12 @@ export class Style extends XmlComponent {
|
||||
}
|
||||
|
||||
export class ParagraphStyle extends Style {
|
||||
private readonly paragraphProperties: paragraph.ParagraphProperties;
|
||||
private readonly paragraphProperties: ParagraphProperties;
|
||||
private readonly runProperties: RunProperties;
|
||||
|
||||
constructor(styleId: string, name?: string) {
|
||||
super({ type: "paragraph", styleId: styleId }, name);
|
||||
this.paragraphProperties = new paragraph.ParagraphProperties();
|
||||
this.paragraphProperties = new ParagraphProperties();
|
||||
this.runProperties = new RunProperties();
|
||||
this.root.push(this.paragraphProperties);
|
||||
this.root.push(this.runProperties);
|
||||
@ -129,47 +141,47 @@ export class ParagraphStyle extends Style {
|
||||
// --------------------- Paragraph formatting ------------------------ //
|
||||
|
||||
public center(): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.Alignment("center"));
|
||||
return this.addParagraphProperty(new Alignment(AlignmentOptions.CENTER));
|
||||
}
|
||||
|
||||
public left(): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.Alignment("left"));
|
||||
return this.addParagraphProperty(new Alignment(AlignmentOptions.LEFT));
|
||||
}
|
||||
|
||||
public right(): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.Alignment("right"));
|
||||
return this.addParagraphProperty(new Alignment(AlignmentOptions.RIGHT));
|
||||
}
|
||||
|
||||
public justified(): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.Alignment("both"));
|
||||
return this.addParagraphProperty(new Alignment(AlignmentOptions.BOTH));
|
||||
}
|
||||
|
||||
public thematicBreak(): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.ThematicBreak());
|
||||
return this.addParagraphProperty(new ThematicBreak());
|
||||
}
|
||||
|
||||
public maxRightTabStop(): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.MaxRightTabStop());
|
||||
return this.addParagraphProperty(new MaxRightTabStop());
|
||||
}
|
||||
|
||||
public leftTabStop(position: number): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.LeftTabStop(position));
|
||||
return this.addParagraphProperty(new LeftTabStop(position));
|
||||
}
|
||||
|
||||
public indent(attrs: object): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.Indent(attrs));
|
||||
return this.addParagraphProperty(new Indent(attrs));
|
||||
}
|
||||
|
||||
public spacing(params: paragraph.ISpacingProperties): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.Spacing(params));
|
||||
public spacing(params: ISpacingProperties): ParagraphStyle {
|
||||
return this.addParagraphProperty(new Spacing(params));
|
||||
}
|
||||
|
||||
public keepNext(): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.KeepNext());
|
||||
return this.addParagraphProperty(new KeepNext());
|
||||
}
|
||||
|
||||
public keepLines(): ParagraphStyle {
|
||||
return this.addParagraphProperty(new paragraph.KeepLines());
|
||||
return this.addParagraphProperty(new KeepLines());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class AliasAttributes extends XmlAttributeComponent<{ alias: string }> {
|
||||
protected xmlKeys = { alias: "w:val" };
|
||||
class AliasAttributes extends XmlAttributeComponent<{ readonly alias: string }> {
|
||||
protected readonly xmlKeys = { alias: "w:val" };
|
||||
}
|
||||
|
||||
export class Alias extends XmlComponent {
|
||||
|
@ -1,14 +1,10 @@
|
||||
// http://officeopenxml.com/WPfieldInstructions.php
|
||||
import { SpaceType } from "file/space-type";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { ITableOfContentsOptions } from "./table-of-contents-properties";
|
||||
|
||||
enum SpaceType {
|
||||
DEFAULT = "default",
|
||||
PRESERVE = "preserve",
|
||||
}
|
||||
|
||||
class TextAttributes extends XmlAttributeComponent<{ space: SpaceType }> {
|
||||
protected xmlKeys = { space: "xml:space" };
|
||||
class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> {
|
||||
protected readonly xmlKeys = { space: "xml:space" };
|
||||
}
|
||||
|
||||
export class FieldInstruction extends XmlComponent {
|
||||
|
@ -1,6 +1,6 @@
|
||||
export class StyleLevel {
|
||||
public styleName: string;
|
||||
public level: number;
|
||||
public readonly styleName: string;
|
||||
public readonly level: number;
|
||||
|
||||
constructor(styleName: string, level: number) {
|
||||
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.
|
||||
* 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
|
||||
* 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
|
||||
@ -36,24 +36,24 @@ export interface ITableOfContentsOptions {
|
||||
* field-argument, which corresponds to the caption label, shall match the identifier in the
|
||||
* corresponding SEQ field.
|
||||
*/
|
||||
captionLabelIncludingNumbers?: string;
|
||||
readonly captionLabelIncludingNumbers?: string;
|
||||
|
||||
/**
|
||||
* \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 (-).
|
||||
*/
|
||||
sequenceAndPageNumbersSeparator?: string;
|
||||
readonly sequenceAndPageNumbersSeparator?: string;
|
||||
|
||||
/**
|
||||
* \f option - Includes only those TC fields whose identifier exactly matches the
|
||||
* 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.
|
||||
*/
|
||||
hyperlink?: boolean;
|
||||
readonly hyperlink?: boolean;
|
||||
|
||||
/**
|
||||
* \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.
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
pageNumbersEntryLevelsRange?: string;
|
||||
readonly pageNumbersEntryLevelsRange?: string;
|
||||
|
||||
/**
|
||||
* \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).
|
||||
* 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
|
||||
* 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.
|
||||
* The prefix depends on the type of entry. text in this switch's field-argument shall match the
|
||||
* 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.
|
||||
@ -98,25 +98,25 @@ export interface ITableOfContentsOptions {
|
||||
* with each doublet being a comma-separated set of style name and table of content level.
|
||||
* \t can be combined with \o.
|
||||
*/
|
||||
stylesWithLevels?: StyleLevel[];
|
||||
readonly stylesWithLevels?: StyleLevel[];
|
||||
|
||||
/**
|
||||
* \u Uses the applied paragraph outline level.
|
||||
*/
|
||||
useAppliedParagraphOutlineLevel?: boolean;
|
||||
readonly useAppliedParagraphOutlineLevel?: boolean;
|
||||
|
||||
/**
|
||||
* \w Preserves tab entries within table entries.
|
||||
*/
|
||||
preserveTabInEntries?: boolean;
|
||||
readonly preserveTabInEntries?: boolean;
|
||||
|
||||
/**
|
||||
* \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).
|
||||
*/
|
||||
hideTabAndPageNumbersInWebView?: boolean;
|
||||
readonly hideTabAndPageNumbersInWebView?: boolean;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { expect } from "chai";
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
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("#constructor", () => {
|
||||
@ -14,28 +14,28 @@ describe("Table of Contents", () => {
|
||||
});
|
||||
|
||||
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>();
|
||||
styles.push(new StyleLevel("SL", 1));
|
||||
styles.push(new StyleLevel("SL", 2));
|
||||
props.stylesWithLevels = styles;
|
||||
props.useAppliedParagraphOutlineLevel = true;
|
||||
props.preserveTabInEntries = true;
|
||||
props.preserveNewLineInEntries = true;
|
||||
props.hideTabAndPageNumbersInWebView = true;
|
||||
|
||||
const props = {
|
||||
captionLabel: "A",
|
||||
entriesFromBookmark: "B",
|
||||
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 tree = new Formatter().format(toc);
|
||||
|
@ -8,8 +8,8 @@ export class TableGrid extends XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
class GridColAttributes extends XmlAttributeComponent<{ w: number }> {
|
||||
protected xmlKeys = { w: "w:w" };
|
||||
class GridColAttributes extends XmlAttributeComponent<{ readonly w: number }> {
|
||||
protected readonly xmlKeys = { w: "w:w" };
|
||||
}
|
||||
|
||||
export class GridCol extends XmlComponent {
|
||||
|
@ -2,13 +2,13 @@ import { BorderStyle } from "file/styles";
|
||||
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
interface ICellBorder {
|
||||
style: BorderStyle;
|
||||
size: number;
|
||||
color: string;
|
||||
readonly style: BorderStyle;
|
||||
readonly size: number;
|
||||
readonly color: string;
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -71,8 +71,8 @@ export class TableCellBorders extends XmlComponent {
|
||||
/**
|
||||
* Attributes fot the GridSpan element.
|
||||
*/
|
||||
class GridSpanAttributes extends XmlAttributeComponent<{ val: number }> {
|
||||
protected xmlKeys = { val: "w:val" };
|
||||
class GridSpanAttributes extends XmlAttributeComponent<{ readonly val: number }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,8 +104,8 @@ export enum VMergeType {
|
||||
RESTART = "restart",
|
||||
}
|
||||
|
||||
class VMergeAttributes extends XmlAttributeComponent<{ val: VMergeType }> {
|
||||
protected xmlKeys = { val: "w:val" };
|
||||
class VMergeAttributes extends XmlAttributeComponent<{ readonly val: VMergeType }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,8 +129,8 @@ export enum VerticalAlign {
|
||||
TOP = "top",
|
||||
}
|
||||
|
||||
class VAlignAttributes extends XmlAttributeComponent<{ val: VerticalAlign }> {
|
||||
protected xmlKeys = { val: "w:val" };
|
||||
class VAlignAttributes extends XmlAttributeComponent<{ readonly val: VerticalAlign }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,8 +159,8 @@ export enum WidthType {
|
||||
PERCENTAGE = "pct",
|
||||
}
|
||||
|
||||
class TableCellWidthAttributes extends XmlAttributeComponent<{ type: WidthType; width: string | number }> {
|
||||
protected xmlKeys = { width: "w:w", type: "w:type" };
|
||||
class TableCellWidthAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly width: string | number }> {
|
||||
protected readonly xmlKeys = { width: "w:w", type: "w:type" };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,13 +180,13 @@ export class TableCellWidth extends XmlComponent {
|
||||
}
|
||||
|
||||
export interface ITableCellShadingAttributesProperties {
|
||||
fill?: string;
|
||||
color?: string;
|
||||
val?: string;
|
||||
readonly fill?: string;
|
||||
readonly color?: string;
|
||||
readonly val?: string;
|
||||
}
|
||||
|
||||
class TableCellShadingAttributes extends XmlAttributeComponent<ITableCellShadingAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
fill: "w:fill",
|
||||
color: "w:color",
|
||||
val: "w:val",
|
||||
|
@ -26,8 +26,13 @@ class TableBordersElement extends XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
class TableBordersAttributes extends XmlAttributeComponent<{ value: string; size: number; space: number; color: string }> {
|
||||
protected xmlKeys = {
|
||||
class TableBordersAttributes extends XmlAttributeComponent<{
|
||||
readonly value: string;
|
||||
readonly size: number;
|
||||
readonly space: number;
|
||||
readonly color: string;
|
||||
}> {
|
||||
protected readonly xmlKeys = {
|
||||
value: "w:val",
|
||||
size: "w:sz",
|
||||
space: "w:space",
|
||||
|
@ -2,8 +2,8 @@ import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-co
|
||||
|
||||
import { WidthType } from "../table-cell";
|
||||
|
||||
class TableCellMarginAttributes extends XmlAttributeComponent<{ type: WidthType; value: number }> {
|
||||
protected xmlKeys = { value: "w:w", type: "w:sz" };
|
||||
class TableCellMarginAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly value: number }> {
|
||||
protected readonly xmlKeys = { value: "w:w", type: "w:sz" };
|
||||
}
|
||||
|
||||
class BaseTableCellMargin extends XmlComponent {
|
||||
|
@ -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
|
||||
* 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.
|
||||
@ -41,7 +41,7 @@ export interface ITableFloatOptions {
|
||||
* If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosition attribute is ignored.
|
||||
* 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.
|
||||
@ -53,7 +53,7 @@ export interface ITableFloatOptions {
|
||||
* outside - the table should be outside of 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
|
||||
@ -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
|
||||
* 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.
|
||||
@ -72,7 +72,7 @@ export interface ITableFloatOptions {
|
||||
* If relativeVerticalPosition is also specified, then the absoluteVerticalPosition attribute is ignored.
|
||||
* 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.
|
||||
@ -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)
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
horizontalAnchor: "w:horzAnchor",
|
||||
verticalAnchor: "w:vertAnchor",
|
||||
absoluteHorizontalPosition: "w:tblpX",
|
||||
|
@ -5,8 +5,8 @@ export enum TableLayoutType {
|
||||
FIXED = "fixed",
|
||||
}
|
||||
|
||||
class TableLayoutAttributes extends XmlAttributeComponent<{ type: TableLayoutType }> {
|
||||
protected xmlKeys = { type: "w:type" };
|
||||
class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: TableLayoutType }> {
|
||||
protected readonly xmlKeys = { type: "w:type" };
|
||||
}
|
||||
|
||||
export class TableLayout extends XmlComponent {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user