Socket
Socket
Sign inDemoInstall

docx

Package Overview
Dependencies
20
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.2.2 to 5.3.0

build/file/styles/defaults/document-defaults.d.ts

3

build/file/document/body/section-properties/page-number/page-number.d.ts

@@ -14,3 +14,4 @@ import { XmlAttributeComponent, XmlComponent } from "../../../../../file/xml-components";

UPPER_LETTER = "upperLetter",
UPPER_ROMAN = "upperRoman"
UPPER_ROMAN = "upperRoman",
DECIMAL_FULL_WIDTH = "decimalFullWidth"
}

@@ -17,0 +18,0 @@ export interface IPageNumberTypeAttributes {

@@ -34,3 +34,3 @@ import { AppProperties } from "./app-properties/app-properties";

readonly properties?: SectionPropertiesOptions;
readonly children: Array<Paragraph | Table | TableOfContents | HyperlinkRef>;
readonly children: (Paragraph | Table | TableOfContents | HyperlinkRef)[];
}

@@ -37,0 +37,0 @@ export declare class File {

import { Paragraph } from "./paragraph";
import { Table } from "./table";
export interface IHeaderOptions {
readonly children: Array<Paragraph | Table>;
readonly children: (Paragraph | Table)[];
}

@@ -6,0 +6,0 @@ export declare class Header {

import { XmlComponent } from "../../file/xml-components";
import { AlignmentType } from "../paragraph/formatting";
import { IParagraphStyleOptions2, IRunStyleOptions } from "../styles/style-options";
import { IParagraphStylePropertiesOptions } from "../paragraph/properties";
import { IRunStylePropertiesOptions } from "../paragraph/run/properties";
export declare enum LevelSuffix {

@@ -17,4 +18,4 @@ NOTHING = "nothing",

readonly style?: {
readonly run?: IRunStyleOptions;
readonly paragraph?: IParagraphStyleOptions2;
readonly run?: IRunStylePropertiesOptions;
readonly paragraph?: IParagraphStylePropertiesOptions;
};

@@ -21,0 +22,0 @@ }

@@ -5,6 +5,6 @@ import { IXmlableObject, XmlComponent } from "../../file/xml-components";

export interface INumberingOptions {
readonly config: Array<{
readonly config: {
readonly levels: ILevelsOptions[];
readonly reference: string;
}>;
}[];
}

@@ -11,0 +11,0 @@ export declare class Numbering extends XmlComponent {

import { FootnoteReferenceRun } from "../../file/footnotes/footnote/run/reference-run";
import { IXmlableObject, XmlComponent } from "../../file/xml-components";
import { File } from "../file";
import { AlignmentType } from "./formatting/alignment";
import { IBorderOptions } from "./formatting/border";
import { IIndentAttributesProperties } from "./formatting/indent";
import { PageBreak } from "./formatting/page-break";
import { ISpacingProperties } from "./formatting/spacing";
import { HeadingLevel } from "./formatting/style";
import { LeaderType, TabStopPosition, TabStopType } from "./formatting/tab-stop";
import { Bookmark, HyperlinkRef } from "./links";
import { IParagraphPropertiesOptions } from "./properties";
import { PictureRun, Run, SequentialIdentifier, SymbolRun, TextRun } from "./run";
export interface IParagraphOptions {
export interface IParagraphOptions extends IParagraphPropertiesOptions {
readonly text?: string;
readonly border?: IBorderOptions;
readonly spacing?: ISpacingProperties;
readonly outlineLevel?: number;
readonly alignment?: AlignmentType;
readonly heading?: HeadingLevel;
readonly bidirectional?: boolean;
readonly thematicBreak?: boolean;
readonly pageBreakBefore?: boolean;
readonly contextualSpacing?: boolean;
readonly indent?: IIndentAttributesProperties;
readonly keepLines?: boolean;
readonly keepNext?: boolean;
readonly tabStops?: Array<{
readonly position: number | TabStopPosition;
readonly type: TabStopType;
readonly leader?: LeaderType;
}>;
readonly style?: string;
readonly bullet?: {
readonly level: number;
};
readonly numbering?: {
readonly reference: string;
readonly level: number;
readonly custom?: boolean;
};
readonly children?: Array<TextRun | PictureRun | SymbolRun | Bookmark | PageBreak | SequentialIdentifier | FootnoteReferenceRun | HyperlinkRef>;
readonly children?: (TextRun | PictureRun | SymbolRun | Bookmark | PageBreak | SequentialIdentifier | FootnoteReferenceRun | HyperlinkRef)[];
}

@@ -43,0 +12,0 @@ export declare class Paragraph extends XmlComponent {

import { IgnoreIfEmptyXmlComponent, XmlComponent } from "../../file/xml-components";
import { AlignmentType } from "./formatting/alignment";
import { IBorderOptions } from "./formatting/border";
interface IParagraphPropertiesOptions {
import { IIndentAttributesProperties } from "./formatting/indent";
import { ISpacingProperties } from "./formatting/spacing";
import { HeadingLevel } from "./formatting/style";
import { LeaderType, TabStopPosition, TabStopType } from "./formatting/tab-stop";
export interface IParagraphStylePropertiesOptions {
readonly alignment?: AlignmentType;
readonly thematicBreak?: boolean;
readonly contextualSpacing?: boolean;
readonly rightTabStop?: number;
readonly leftTabStop?: number;
readonly indent?: IIndentAttributesProperties;
readonly spacing?: ISpacingProperties;
readonly keepNext?: boolean;
readonly keepLines?: boolean;
readonly outlineLevel?: number;
}
export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions {
readonly border?: IBorderOptions;
readonly heading?: HeadingLevel;
readonly bidirectional?: boolean;
readonly pageBreakBefore?: boolean;
readonly tabStops?: {
readonly position: number | TabStopPosition;
readonly type: TabStopType;
readonly leader?: LeaderType;
}[];
readonly style?: string;
readonly bullet?: {
readonly level: number;
};
readonly numbering?: {
readonly reference: string;
readonly level: number;
readonly custom?: boolean;
};
}
export declare class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
constructor(options: IParagraphPropertiesOptions);
constructor(options?: IParagraphPropertiesOptions);
push(item: XmlComponent): void;
}
export {};
export * from "./run";
export * from "./properties";
export * from "./text-run";

@@ -3,0 +4,0 @@ export * from "./symbol-run";

@@ -0,5 +1,51 @@

import { ShadingType } from "../../../file/table";
import { IgnoreIfEmptyXmlComponent, XmlComponent } from "../../../file/xml-components";
import { EmphasisMarkType } from "./emphasis-mark";
import { IFontAttributesProperties } from "./run-fonts";
import { UnderlineType } from "./underline";
interface IFontOptions {
readonly name: string;
readonly hint?: string;
}
export interface IRunStylePropertiesOptions {
readonly bold?: boolean;
readonly boldComplexScript?: boolean;
readonly italics?: boolean;
readonly italicsComplexScript?: boolean;
readonly underline?: {
readonly color?: string;
readonly type?: UnderlineType;
};
readonly emphasisMark?: {
readonly type?: EmphasisMarkType;
};
readonly color?: string;
readonly size?: number;
readonly sizeComplexScript?: boolean | number;
readonly rightToLeft?: boolean;
readonly smallCaps?: boolean;
readonly allCaps?: boolean;
readonly strike?: boolean;
readonly doubleStrike?: boolean;
readonly subScript?: boolean;
readonly superScript?: boolean;
readonly font?: string | IFontOptions | IFontAttributesProperties;
readonly highlight?: string;
readonly highlightComplexScript?: boolean | string;
readonly characterSpacing?: number;
readonly shading?: {
readonly type: ShadingType;
readonly fill: string;
readonly color: string;
};
readonly shadingComplexScript?: boolean | IRunStylePropertiesOptions["shading"];
readonly shadow?: IRunStylePropertiesOptions["shading"];
}
export interface IRunPropertiesOptions extends IRunStylePropertiesOptions {
readonly style?: string;
}
export declare class RunProperties extends IgnoreIfEmptyXmlComponent {
constructor();
constructor(options?: IRunPropertiesOptions);
push(item: XmlComponent): void;
}
export {};

@@ -1,42 +0,8 @@

import { ShadingType } from "../../../file/table";
import { XmlComponent } from "../../../file/xml-components";
import { FootnoteReferenceRun } from "../../../file/footnotes/footnote/run/reference-run";
import { FieldInstruction } from "../../../file/table-of-contents/field-instruction";
import { EmphasisMarkType } from "./emphasis-mark";
import { Begin, End, Separate } from "./field";
import { RunProperties } from "./properties";
import { IFontAttributesProperties } from "./run-fonts";
import { UnderlineType } from "./underline";
interface IFontOptions {
readonly name: string;
readonly hint?: string;
}
export interface IRunOptions {
readonly bold?: true;
readonly italics?: true;
readonly underline?: {
readonly color?: string;
readonly type?: UnderlineType;
};
readonly emphasisMark?: {
readonly type?: EmphasisMarkType;
};
readonly color?: string;
readonly size?: number;
readonly rightToLeft?: boolean;
readonly smallCaps?: boolean;
readonly allCaps?: boolean;
readonly strike?: boolean;
readonly doubleStrike?: boolean;
readonly subScript?: boolean;
readonly superScript?: boolean;
readonly style?: string;
readonly font?: IFontOptions | IFontAttributesProperties;
readonly highlight?: string;
readonly shading?: {
readonly type: ShadingType;
readonly fill: string;
readonly color: string;
};
readonly children?: Array<Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string>;
import { IRunPropertiesOptions, RunProperties } from "./properties";
export interface IRunOptions extends IRunPropertiesOptions {
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
readonly text?: string;

@@ -54,2 +20,1 @@ }

}
export {};

@@ -1,6 +0,3 @@

import { XmlComponent } from "../../../file/xml-components";
export declare class DocumentDefaults extends XmlComponent {
private readonly runPropertiesDefaults;
private readonly paragraphPropertiesDefaults;
constructor();
}
export * from "./paragraph-properties";
export * from "./run-properties";
export * from "./document-defaults";

@@ -0,4 +1,5 @@

import { IParagraphStylePropertiesOptions } from "../../../file/paragraph/properties";
import { XmlComponent } from "../../../file/xml-components";
export declare class ParagraphPropertiesDefaults extends XmlComponent {
constructor();
constructor(options?: IParagraphStylePropertiesOptions);
}

@@ -1,8 +0,6 @@

import { IFontAttributesProperties } from "../../../file/paragraph/run/run-fonts";
import { IRunStylePropertiesOptions } from "../../../file/paragraph/run/properties";
import { XmlComponent } from "../../../file/xml-components";
export declare class RunPropertiesDefaults extends XmlComponent {
private readonly properties;
constructor();
size(size: number): RunPropertiesDefaults;
font(font: string | IFontAttributesProperties): RunPropertiesDefaults;
constructor(options?: IRunStylePropertiesOptions);
}
export * from "./styles";
export * from "./style/character-style";
export * from "./style/paragraph-style";
export * from "./style-options";
export * from "./defaults";

@@ -1,4 +0,2 @@

import { EmphasisMarkType } from "../../../file/paragraph/run/emphasis-mark";
import { IFontAttributesProperties } from "../../../file/paragraph/run/run-fonts";
import { UnderlineType } from "../../../file/paragraph/run/underline";
import { IRunStylePropertiesOptions } from "../../../file/paragraph/run/properties";
import { Style } from "./style";

@@ -9,29 +7,3 @@ export interface IBaseCharacterStyleOptions {

readonly semiHidden?: boolean;
readonly run?: {
readonly size?: number;
readonly bold?: boolean;
readonly italics?: boolean;
readonly smallCaps?: boolean;
readonly allCaps?: boolean;
readonly strike?: boolean;
readonly doubleStrike?: boolean;
readonly subScript?: boolean;
readonly superScript?: boolean;
readonly underline?: {
readonly type?: UnderlineType;
readonly color?: string;
};
readonly emphasisMark?: {
readonly type?: EmphasisMarkType;
};
readonly color?: string;
readonly font?: string | IFontAttributesProperties;
readonly characterSpacing?: number;
readonly highlight?: string;
readonly shadow?: {
readonly type: string;
readonly fill: string;
readonly color: string;
};
};
readonly run?: IRunStylePropertiesOptions;
}

@@ -38,0 +10,0 @@ export interface ICharacterStyleOptions extends IBaseCharacterStyleOptions {

@@ -1,2 +0,2 @@

import { IParagraphStyleOptions2, IRunStyleOptions } from "../style-options";
import { IParagraphStylePropertiesOptions, IRunStylePropertiesOptions } from "../../../file/paragraph";
import { Style } from "./style";

@@ -11,4 +11,4 @@ export interface IBaseParagraphStyleOptions {

readonly unhideWhenUsed?: boolean;
readonly run?: IRunStyleOptions;
readonly paragraph?: IParagraphStyleOptions2;
readonly paragraph?: IParagraphStylePropertiesOptions;
readonly run?: IRunStylePropertiesOptions;
}

@@ -15,0 +15,0 @@ export interface IParagraphStyleOptions extends IBaseParagraphStyleOptions {

@@ -10,3 +10,3 @@ import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "../../file/xml-components";

readonly characterStyles?: ICharacterStyleOptions[];
readonly importedStyles?: Array<XmlComponent | ParagraphStyle | CharacterStyle | ImportedXmlComponent>;
readonly importedStyles?: (XmlComponent | ParagraphStyle | CharacterStyle | ImportedXmlComponent)[];
}

@@ -13,0 +13,0 @@ export declare class Styles extends XmlComponent {

@@ -43,3 +43,3 @@ import { Paragraph } from "../../../file/paragraph";

};
readonly children: Array<Paragraph | Table>;
readonly children: (Paragraph | Table)[];
}

@@ -46,0 +46,0 @@ export declare class TableCell extends XmlComponent {

@@ -6,3 +6,3 @@ import { File } from "../file";

export declare abstract class XmlComponent extends BaseXmlComponent {
protected root: Array<BaseXmlComponent | string | any>;
protected root: (BaseXmlComponent | string | any)[];
constructor(rootKey: string);

@@ -9,0 +9,0 @@ prepForXml(file?: File): IXmlableObject | undefined;

{
"name": "docx",
"version": "5.2.2",
"version": "5.3.0",
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",

@@ -67,6 +67,6 @@ "main": "build/index.js",

"@types/chai": "^3.4.35",
"@types/mocha": "^2.2.39",
"@types/mocha": "^8.0.0",
"@types/request-promise": "^4.1.42",
"@types/shortid": "0.0.29",
"@types/sinon": "^4.3.1",
"@types/sinon": "^9.0.4",
"@types/webpack": "^4.4.24",

@@ -81,5 +81,5 @@ "awesome-typescript-loader": "^3.4.1",

"mocha-webpack": "^1.0.1",
"nyc": "^14.1.1",
"nyc": "^15.1.0",
"pre-commit": "^1.2.2",
"prettier": "^1.15.2",
"prettier": "^2.0.5",
"prompt": "^1.0.0",

@@ -89,9 +89,9 @@ "replace-in-file": "^3.1.0",

"request-promise": "^4.2.2",
"rimraf": "^2.5.2",
"shelljs": "^0.7.7",
"sinon": "^5.0.7",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"rimraf": "^3.0.2",
"shelljs": "^0.8.4",
"sinon": "^9.0.2",
"ts-node": "^8.10.2",
"tslint": "^6.1.3",
"tslint-immutable": "^4.9.0",
"typedoc": "^0.11.1",
"typedoc": "^0.16.11",
"typescript": "2.9.2",

@@ -101,4 +101,4 @@ "webpack": "^3.10.0"

"engines": {
"node": ">=8"
"node": ">=10"
}
}

@@ -37,2 +37,11 @@ <p align="center">

Here is an example of `docx` working in `React`:
* https://stackblitz.com/edit/react-ts-qq25sp
* https://stackblitz.com/edit/react-ts-qdqu7z (adding images to Word Document)
Here is an example of `docx` working in `Vue.js`:
* https://stackblitz.com/edit/vuejs-docx
## Node

@@ -54,3 +63,3 @@

More [here](https://docx.js.org/#/examples) and [here](https://github.com/dolanmiu/docx/tree/master/demo)
More [here](https://github.com/dolanmiu/docx/tree/master/demo)

@@ -57,0 +66,0 @@ # How to use & Documentation

@@ -19,3 +19,3 @@ /* tslint:disable:typedef space-before-function-paren */

describe("#compile()", () => {
it("should pack all the content", async function() {
it("should pack all the content", async function () {
this.timeout(99999999);

@@ -39,3 +39,3 @@ const zipFile = compiler.compile(file);

it("should pack all additional headers and footers", async function() {
it("should pack all additional headers and footers", async function () {
file.addSection({

@@ -42,0 +42,0 @@ headers: {

@@ -39,3 +39,3 @@ /* tslint:disable:typedef space-before-function-paren */

describe("#toBuffer()", () => {
it("should create a standard docx file", async function() {
it("should create a standard docx file", async function () {
this.timeout(99999999);

@@ -65,3 +65,3 @@ const buffer = await Packer.toBuffer(file);

describe("#toBase64String()", () => {
it("should create a standard docx file", async function() {
it("should create a standard docx file", async function () {
this.timeout(99999999);

@@ -68,0 +68,0 @@ const str = await Packer.toBase64String(file);

@@ -48,3 +48,3 @@ import { IXmlableObject, XmlComponent } from "file/xml-components";

const properties = new ParagraphProperties({});
properties.addChildElement(section);
properties.push(section);
paragraph.addChildElement(properties);

@@ -51,0 +51,0 @@ return paragraph;

@@ -17,2 +17,3 @@ // http://officeopenxml.com/WPSectionPgNumType.php

UPPER_ROMAN = "upperRoman",
DECIMAL_FULL_WIDTH = "decimalFullWidth",
}

@@ -19,0 +20,0 @@

@@ -44,3 +44,3 @@ import * as shortid from "shortid";

readonly properties?: SectionPropertiesOptions;
readonly children: Array<Paragraph | Table | TableOfContents | HyperlinkRef>;
readonly children: (Paragraph | Table | TableOfContents | HyperlinkRef)[];
}

@@ -47,0 +47,0 @@

@@ -5,3 +5,3 @@ import { Paragraph } from "./paragraph";

export interface IHeaderOptions {
readonly children: Array<Paragraph | Table>;
readonly children: (Paragraph | Table)[];
}

@@ -8,0 +8,0 @@

@@ -24,10 +24,3 @@ import { IDrawingOptions } from "../drawing";

// https://gist.github.com/6174/6062387
return (
Math.random()
.toString(36)
.substring(2, 15) +
Math.random()
.toString(36)
.substring(2, 15)
);
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}

@@ -34,0 +27,0 @@

@@ -10,2 +10,3 @@ import { expect } from "chai";

import { AbstractNumbering } from "./abstract-numbering";
import { LevelSuffix } from "./level";

@@ -52,2 +53,16 @@ describe("AbstractNumbering", () => {

it("has suffix", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 3,
format: "lowerLetter",
text: "%1)",
alignment: AlignmentType.END,
suffix: LevelSuffix.SPACE,
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:suff": { _attr: { "w:val": "space" } } });
});
describe("formatting methods: paragraph properties", () => {

@@ -288,18 +303,37 @@ it("#indent", () => {

describe("formatting methods: run properties", () => {
it("#size", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: {
size: 24,
const sizeTests = [
{
size: 24,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: true,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: false,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: 26,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 26 } } }],
},
];
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
it(`#size ${size} cs ${sizeComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: { size, sizeComplexScript },
},
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }],
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});

@@ -484,79 +518,181 @@ });

it("#bold", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: {
bold: true,
const boldTests = [
{
bold: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: false,
expected: [{ "w:b": { _attr: { "w:val": true } } }],
},
];
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: { bold, boldComplexScript },
},
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }],
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});
});
it("#italics", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: {
italics: true,
const italicsTests = [
{
italics: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: false,
expected: [{ "w:i": { _attr: { "w:val": true } } }],
},
];
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: { italics, italicsComplexScript },
},
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }],
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});
});
it("#highlight", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: {
highlight: "005599",
const highlightTests = [
{
highlight: "005599",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: true,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: false,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: "550099",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "550099" } } }],
},
];
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: { highlight, highlightComplexScript },
},
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});
});
it("#shadow", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: {
shadow: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
const shadingTests = [
{
shadow: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: true,
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: false,
expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "00FF00",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "00FF00" } } },
],
},
];
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
it("#shadow correctly", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: { shadow, shading, shadingComplexScript },
},
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});

@@ -563,0 +699,0 @@ });

import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
import {
Alignment,
AlignmentType,
Indent,
KeepLines,
KeepNext,
Spacing,
TabStop,
TabStopType,
ThematicBreak,
} from "../paragraph/formatting";
import { ParagraphProperties } from "../paragraph/properties";
import * as formatting from "../paragraph/run/formatting";
import { RunProperties } from "../paragraph/run/properties";
import { IParagraphStyleOptions2, IRunStyleOptions } from "../styles/style-options";
import { AlignmentType } from "../paragraph/formatting";
import { IParagraphStylePropertiesOptions, ParagraphProperties } from "../paragraph/properties";
import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/properties";

@@ -88,4 +76,4 @@ interface ILevelAttributesProperties {

readonly style?: {
readonly run?: IRunStyleOptions;
readonly paragraph?: IParagraphStyleOptions2;
readonly run?: IRunStylePropertiesOptions;
readonly paragraph?: IParagraphStylePropertiesOptions;
};

@@ -129,4 +117,4 @@ }

this.paragraphProperties = new ParagraphProperties({});
this.runProperties = new RunProperties();
this.paragraphProperties = new ParagraphProperties(style && style.paragraph);
this.runProperties = new RunProperties(style && style.run);

@@ -139,100 +127,2 @@ this.root.push(this.paragraphProperties);

}
if (style) {
if (style.run) {
if (style.run.size) {
this.runProperties.push(new formatting.Size(style.run.size));
}
if (style.run.bold) {
this.runProperties.push(new formatting.Bold());
}
if (style.run.italics) {
this.runProperties.push(new formatting.Italics());
}
if (style.run.smallCaps) {
this.runProperties.push(new formatting.SmallCaps());
}
if (style.run.allCaps) {
this.runProperties.push(new formatting.Caps());
}
if (style.run.strike) {
this.runProperties.push(new formatting.Strike());
}
if (style.run.doubleStrike) {
this.runProperties.push(new formatting.DoubleStrike());
}
if (style.run.subScript) {
this.runProperties.push(new formatting.SubScript());
}
if (style.run.superScript) {
this.runProperties.push(new formatting.SuperScript());
}
if (style.run.underline) {
this.runProperties.push(new formatting.Underline(style.run.underline.type, style.run.underline.color));
}
if (style.run.emphasisMark) {
this.runProperties.push(new formatting.EmphasisMark(style.run.emphasisMark.type));
}
if (style.run.color) {
this.runProperties.push(new formatting.Color(style.run.color));
}
if (style.run.font) {
this.runProperties.push(new formatting.RunFonts(style.run.font));
}
if (style.run.highlight) {
this.runProperties.push(new formatting.Highlight(style.run.highlight));
}
if (style.run.shadow) {
this.runProperties.push(new formatting.Shading(style.run.shadow.type, style.run.shadow.fill, style.run.shadow.color));
}
}
if (style.paragraph) {
if (style.paragraph.alignment) {
this.paragraphProperties.push(new Alignment(style.paragraph.alignment));
}
if (style.paragraph.thematicBreak) {
this.paragraphProperties.push(new ThematicBreak());
}
if (style.paragraph.rightTabStop) {
this.paragraphProperties.push(new TabStop(TabStopType.RIGHT, style.paragraph.rightTabStop));
}
if (style.paragraph.leftTabStop) {
this.paragraphProperties.push(new TabStop(TabStopType.LEFT, style.paragraph.leftTabStop));
}
if (style.paragraph.indent) {
this.paragraphProperties.push(new Indent(style.paragraph.indent));
}
if (style.paragraph.spacing) {
this.paragraphProperties.push(new Spacing(style.paragraph.spacing));
}
if (style.paragraph.keepNext) {
this.paragraphProperties.push(new KeepNext());
}
if (style.paragraph.keepLines) {
this.paragraphProperties.push(new KeepLines());
}
}
}
}

@@ -239,0 +129,0 @@ }

@@ -11,6 +11,6 @@ // http://officeopenxml.com/WPnumbering.php

export interface INumberingOptions {
readonly config: Array<{
readonly config: {
readonly levels: ILevelsOptions[];
readonly reference: string;
}>;
}[];
}

@@ -17,0 +17,0 @@

@@ -545,10 +545,4 @@ import { assert, expect } from "chai";

const tree = new Formatter().format(paragraph);
expect(tree)
.to.have.property("w:p")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree["w:p"][0])
.to.have.property("w:pPr")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({

@@ -566,10 +560,4 @@ "w:pStyle": { _attr: { "w:val": "ListParagraph" } },

const tree = new Formatter().format(paragraph);
expect(tree)
.to.have.property("w:p")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree["w:p"][0])
.to.have.property("w:pPr")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({

@@ -587,10 +575,4 @@ "w:pStyle": { _attr: { "w:val": "ListParagraph" } },

const tree = new Formatter().format(paragraph);
expect(tree)
.to.have.property("w:p")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree["w:p"][0])
.to.have.property("w:pPr")
.which.is.an("array")
.which.has.length.at.least(2);
expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(2);
expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({

@@ -611,10 +593,4 @@ "w:numPr": [{ "w:ilvl": { _attr: { "w:val": 1 } } }, { "w:numId": { _attr: { "w:val": 1 } } }],

const tree = new Formatter().format(paragraph);
expect(tree)
.to.have.property("w:p")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree["w:p"][0])
.to.have.property("w:pPr")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1);
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({

@@ -621,0 +597,0 @@ "w:pStyle": { _attr: { "w:val": "ListParagraph" } },

@@ -6,47 +6,19 @@ // http://officeopenxml.com/WPparagraph.php

import { File } from "../file";
import { Alignment, AlignmentType } from "./formatting/alignment";
import { Bidirectional } from "./formatting/bidirectional";
import { IBorderOptions, ThematicBreak } from "./formatting/border";
import { IIndentAttributesProperties, Indent } from "./formatting/indent";
import { KeepLines, KeepNext } from "./formatting/keep";
import { PageBreak, PageBreakBefore } from "./formatting/page-break";
import { ContextualSpacing, ISpacingProperties, Spacing } from "./formatting/spacing";
import { HeadingLevel, Style } from "./formatting/style";
import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop";
import { NumberProperties } from "./formatting/unordered-list";
import { Bookmark, HyperlinkRef, OutlineLevel } from "./links";
import { ParagraphProperties } from "./properties";
import { PageBreak } from "./formatting/page-break";
import { Bookmark, HyperlinkRef } from "./links";
import { IParagraphPropertiesOptions, ParagraphProperties } from "./properties";
import { PictureRun, Run, SequentialIdentifier, SymbolRun, TextRun } from "./run";
export interface IParagraphOptions {
export interface IParagraphOptions extends IParagraphPropertiesOptions {
readonly text?: string;
readonly border?: IBorderOptions;
readonly spacing?: ISpacingProperties;
readonly outlineLevel?: number;
readonly alignment?: AlignmentType;
readonly heading?: HeadingLevel;
readonly bidirectional?: boolean;
readonly thematicBreak?: boolean;
readonly pageBreakBefore?: boolean;
readonly contextualSpacing?: boolean;
readonly indent?: IIndentAttributesProperties;
readonly keepLines?: boolean;
readonly keepNext?: boolean;
readonly tabStops?: Array<{
readonly position: number | TabStopPosition;
readonly type: TabStopType;
readonly leader?: LeaderType;
}>;
readonly style?: string;
readonly bullet?: {
readonly level: number;
};
readonly numbering?: {
readonly reference: string;
readonly level: number;
readonly custom?: boolean;
};
readonly children?: Array<
TextRun | PictureRun | SymbolRun | Bookmark | PageBreak | SequentialIdentifier | FootnoteReferenceRun | HyperlinkRef
>;
readonly children?: (
| TextRun
| PictureRun
| SymbolRun
| Bookmark
| PageBreak
| SequentialIdentifier
| FootnoteReferenceRun
| HyperlinkRef
)[];
}

@@ -74,5 +46,3 @@

this.properties = new ParagraphProperties({
border: options.border,
});
this.properties = new ParagraphProperties(options);

@@ -85,68 +55,2 @@ this.root.push(this.properties);

if (options.spacing) {
this.properties.push(new Spacing(options.spacing));
}
if (options.outlineLevel !== undefined) {
this.properties.push(new OutlineLevel(options.outlineLevel));
}
if (options.alignment) {
this.properties.push(new Alignment(options.alignment));
}
if (options.heading) {
this.properties.push(new Style(options.heading));
}
if (options.bidirectional) {
this.properties.push(new Bidirectional());
}
if (options.thematicBreak) {
this.properties.push(new ThematicBreak());
}
if (options.pageBreakBefore) {
this.properties.push(new PageBreakBefore());
}
if (options.contextualSpacing) {
this.properties.push(new ContextualSpacing(options.contextualSpacing));
}
if (options.indent) {
this.properties.push(new Indent(options.indent));
}
if (options.keepLines) {
this.properties.push(new KeepLines());
}
if (options.keepNext) {
this.properties.push(new KeepNext());
}
if (options.tabStops) {
for (const tabStop of options.tabStops) {
this.properties.push(new TabStop(tabStop.type, tabStop.position, tabStop.leader));
}
}
if (options.style) {
this.properties.push(new Style(options.style));
}
if (options.bullet) {
this.properties.push(new Style("ListParagraph"));
this.properties.push(new NumberProperties(1, options.bullet.level));
}
if (options.numbering) {
if (!options.numbering.custom) {
this.properties.push(new Style("ListParagraph"));
}
this.properties.push(new NumberProperties(options.numbering.reference, options.numbering.level));
}
if (options.children) {

@@ -153,0 +57,0 @@ for (const child of options.children) {

// http://officeopenxml.com/WPparagraphProperties.php
import { IgnoreIfEmptyXmlComponent, XmlComponent } from "file/xml-components";
import { Alignment, AlignmentType } from "./formatting/alignment";
import { Bidirectional } from "./formatting/bidirectional";
import { Border, IBorderOptions, ThematicBreak } from "./formatting/border";
import { IIndentAttributesProperties, Indent } from "./formatting/indent";
import { KeepLines, KeepNext } from "./formatting/keep";
import { PageBreakBefore } from "./formatting/page-break";
import { ContextualSpacing, ISpacingProperties, Spacing } from "./formatting/spacing";
import { HeadingLevel, Style } from "./formatting/style";
import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop";
import { NumberProperties } from "./formatting/unordered-list";
import { OutlineLevel } from "./links";
import { Border, IBorderOptions } from "./formatting/border";
export interface IParagraphStylePropertiesOptions {
readonly alignment?: AlignmentType;
readonly thematicBreak?: boolean;
readonly contextualSpacing?: boolean;
readonly rightTabStop?: number;
readonly leftTabStop?: number;
readonly indent?: IIndentAttributesProperties;
readonly spacing?: ISpacingProperties;
readonly keepNext?: boolean;
readonly keepLines?: boolean;
readonly outlineLevel?: number;
}
interface IParagraphPropertiesOptions {
export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions {
readonly border?: IBorderOptions;
readonly heading?: HeadingLevel;
readonly bidirectional?: boolean;
readonly pageBreakBefore?: boolean;
readonly tabStops?: {
readonly position: number | TabStopPosition;
readonly type: TabStopType;
readonly leader?: LeaderType;
}[];
readonly style?: string;
readonly bullet?: {
readonly level: number;
};
readonly numbering?: {
readonly reference: string;
readonly level: number;
readonly custom?: boolean;
};
}
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
constructor(options: IParagraphPropertiesOptions) {
constructor(options?: IParagraphPropertiesOptions) {
super("w:pPr");
if (!options) {
return;
}
if (options.border) {
this.push(new Border(options.border));
}
if (options.spacing) {
this.push(new Spacing(options.spacing));
}
if (options.outlineLevel !== undefined) {
this.push(new OutlineLevel(options.outlineLevel));
}
if (options.alignment) {
this.push(new Alignment(options.alignment));
}
if (options.heading) {
this.push(new Style(options.heading));
}
if (options.bidirectional) {
this.push(new Bidirectional());
}
if (options.thematicBreak) {
this.push(new ThematicBreak());
}
if (options.pageBreakBefore) {
this.push(new PageBreakBefore());
}
if (options.contextualSpacing) {
this.push(new ContextualSpacing(options.contextualSpacing));
}
if (options.indent) {
this.push(new Indent(options.indent));
}
if (options.keepLines) {
this.push(new KeepLines());
}
if (options.keepNext) {
this.push(new KeepNext());
}
if (options.tabStops) {
for (const tabStop of options.tabStops) {
this.push(new TabStop(tabStop.type, tabStop.position, tabStop.leader));
}
}
if (options.style) {
this.push(new Style(options.style));
}
if (options.bullet) {
this.push(new Style("ListParagraph"));
this.push(new NumberProperties(1, options.bullet.level));
}
if (options.numbering) {
if (!options.numbering.custom) {
this.push(new Style("ListParagraph"));
}
this.push(new NumberProperties(options.numbering.reference, options.numbering.level));
}
if (options.rightTabStop) {
this.push(new TabStop(TabStopType.RIGHT, options.rightTabStop));
}
if (options.leftTabStop) {
this.push(new TabStop(TabStopType.LEFT, options.leftTabStop));
}
}

@@ -18,0 +135,0 @@

@@ -118,13 +118,2 @@ import { Attributes, XmlComponent } from "file/xml-components";

/* export class Shadow extends XmlComponent {
constructor() {
super("w:shadow");
this.root.push(
new Attributes({
val: true,
}),
);
}
} */
export class SmallCaps extends XmlComponent {

@@ -131,0 +120,0 @@ constructor() {

export * from "./run";
export * from "./properties";
export * from "./text-run";

@@ -3,0 +4,0 @@ export * from "./symbol-run";

@@ -0,6 +1,181 @@

import { ShadingType } from "file/table";
import { IgnoreIfEmptyXmlComponent, XmlComponent } from "file/xml-components";
import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark";
import {
Bold,
BoldComplexScript,
Caps,
CharacterSpacing,
Color,
DoubleStrike,
Highlight,
HighlightComplexScript,
Italics,
ItalicsComplexScript,
RightToLeft,
Shading,
ShadowComplexScript,
Size,
SizeComplexScript,
SmallCaps,
Strike,
} from "./formatting";
import { IFontAttributesProperties, RunFonts } from "./run-fonts";
import { SubScript, SuperScript } from "./script";
import { Style } from "./style";
import { Underline, UnderlineType } from "./underline";
interface IFontOptions {
readonly name: string;
readonly hint?: string;
}
export interface IRunStylePropertiesOptions {
readonly bold?: boolean;
readonly boldComplexScript?: boolean;
readonly italics?: boolean;
readonly italicsComplexScript?: boolean;
readonly underline?: {
readonly color?: string;
readonly type?: UnderlineType;
};
readonly emphasisMark?: {
readonly type?: EmphasisMarkType;
};
readonly color?: string;
readonly size?: number;
readonly sizeComplexScript?: boolean | number;
readonly rightToLeft?: boolean;
readonly smallCaps?: boolean;
readonly allCaps?: boolean;
readonly strike?: boolean;
readonly doubleStrike?: boolean;
readonly subScript?: boolean;
readonly superScript?: boolean;
readonly font?: string | IFontOptions | IFontAttributesProperties;
readonly highlight?: string;
readonly highlightComplexScript?: boolean | string;
readonly characterSpacing?: number;
readonly shading?: {
readonly type: ShadingType;
readonly fill: string;
readonly color: string;
};
readonly shadingComplexScript?: boolean | IRunStylePropertiesOptions["shading"];
readonly shadow?: IRunStylePropertiesOptions["shading"];
}
export interface IRunPropertiesOptions extends IRunStylePropertiesOptions {
readonly style?: string;
}
export class RunProperties extends IgnoreIfEmptyXmlComponent {
constructor() {
constructor(options?: IRunPropertiesOptions) {
super("w:rPr");
if (!options) {
return;
}
if (options.bold) {
this.push(new Bold());
}
if ((options.boldComplexScript === undefined && options.bold) || options.boldComplexScript) {
this.push(new BoldComplexScript());
}
if (options.italics) {
this.push(new Italics());
}
if ((options.italicsComplexScript === undefined && options.italics) || options.italicsComplexScript) {
this.push(new ItalicsComplexScript());
}
if (options.underline) {
this.push(new Underline(options.underline.type, options.underline.color));
}
if (options.emphasisMark) {
this.push(new EmphasisMark(options.emphasisMark.type));
}
if (options.color) {
this.push(new Color(options.color));
}
if (options.size) {
this.push(new Size(options.size));
}
const szCs =
options.sizeComplexScript === undefined || options.sizeComplexScript === true ? options.size : options.sizeComplexScript;
if (szCs) {
this.push(new SizeComplexScript(szCs));
}
if (options.rightToLeft) {
this.push(new RightToLeft());
}
if (options.smallCaps) {
this.push(new SmallCaps());
}
if (options.allCaps) {
this.push(new Caps());
}
if (options.strike) {
this.push(new Strike());
}
if (options.doubleStrike) {
this.push(new DoubleStrike());
}
if (options.subScript) {
this.push(new SubScript());
}
if (options.superScript) {
this.push(new SuperScript());
}
if (options.style) {
this.push(new Style(options.style));
}
if (options.font) {
if (typeof options.font === "string") {
this.push(new RunFonts(options.font));
} else if ("name" in options.font) {
this.push(new RunFonts(options.font.name, options.font.hint));
} else {
this.push(new RunFonts(options.font));
}
}
if (options.highlight) {
this.push(new Highlight(options.highlight));
}
const highlightCs =
options.highlightComplexScript === undefined || options.highlightComplexScript === true
? options.highlight
: options.highlightComplexScript;
if (highlightCs) {
this.push(new HighlightComplexScript(highlightCs));
}
if (options.characterSpacing) {
this.push(new CharacterSpacing(options.characterSpacing));
}
const shading = options.shading || options.shadow;
if (shading) {
this.push(new Shading(shading.type, shading.fill, shading.color));
}
const shdCs =
options.shadingComplexScript === undefined || options.shadingComplexScript === true ? shading : options.shadingComplexScript;
if (shdCs) {
this.push(new ShadowComplexScript(shdCs.type, shdCs.fill, shdCs.color));
}
}

@@ -7,0 +182,0 @@

@@ -119,3 +119,3 @@ import { expect } from "chai";

expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:smallCaps": {} }] }],
"w:r": [{ "w:rPr": [{ "w:smallCaps": { _attr: { "w:val": true } } }] }],
});

@@ -132,3 +132,3 @@ });

expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:caps": {} }] }],
"w:r": [{ "w:rPr": [{ "w:caps": { _attr: { "w:val": true } } }] }],
});

@@ -135,0 +135,0 @@ });

// http://officeopenxml.com/WPtext.php
import { ShadingType } from "file/table";
import { XmlComponent } from "file/xml-components";

@@ -8,62 +7,9 @@

import { Break } from "./break";
import { Caps, SmallCaps } from "./caps";
import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark";
import { Begin, End, Separate } from "./field";
import {
Bold,
BoldComplexScript,
Color,
DoubleStrike,
Highlight,
HighlightComplexScript,
Italics,
ItalicsComplexScript,
RightToLeft,
Shading,
ShadowComplexScript,
Size,
SizeComplexScript,
Strike,
} from "./formatting";
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
import { RunProperties } from "./properties";
import { IRunPropertiesOptions, RunProperties } from "./properties";
import { Text } from "./run-components/text";
import { IFontAttributesProperties, RunFonts } from "./run-fonts";
import { SubScript, SuperScript } from "./script";
import { Style } from "./style";
import { Underline, UnderlineType } from "./underline";
interface IFontOptions {
readonly name: string;
readonly hint?: string;
}
export interface IRunOptions {
readonly bold?: true;
readonly italics?: true;
readonly underline?: {
readonly color?: string;
readonly type?: UnderlineType;
};
readonly emphasisMark?: {
readonly type?: EmphasisMarkType;
};
readonly color?: string;
readonly size?: number;
readonly rightToLeft?: boolean;
readonly smallCaps?: boolean;
readonly allCaps?: boolean;
readonly strike?: boolean;
readonly doubleStrike?: boolean;
readonly subScript?: boolean;
readonly superScript?: boolean;
readonly style?: string;
readonly font?: IFontOptions | IFontAttributesProperties;
readonly highlight?: string;
readonly shading?: {
readonly type: ShadingType;
readonly fill: string;
readonly color: string;
};
readonly children?: Array<Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string>;
export interface IRunOptions extends IRunPropertiesOptions {
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
readonly text?: string;

@@ -83,82 +29,5 @@ }

super("w:r");
this.properties = new RunProperties();
this.properties = new RunProperties(options);
this.root.push(this.properties);
if (options.bold) {
this.properties.push(new Bold());
this.properties.push(new BoldComplexScript());
}
if (options.italics) {
this.properties.push(new Italics());
this.properties.push(new ItalicsComplexScript());
}
if (options.underline) {
this.properties.push(new Underline(options.underline.type, options.underline.color));
}
if (options.emphasisMark) {
this.properties.push(new EmphasisMark(options.emphasisMark.type));
}
if (options.color) {
this.properties.push(new Color(options.color));
}
if (options.size) {
this.properties.push(new Size(options.size));
this.properties.push(new SizeComplexScript(options.size));
}
if (options.rightToLeft) {
this.properties.push(new RightToLeft());
}
if (options.smallCaps) {
this.properties.push(new SmallCaps());
}
if (options.allCaps) {
this.properties.push(new Caps());
}
if (options.strike) {
this.properties.push(new Strike());
}
if (options.doubleStrike) {
this.properties.push(new DoubleStrike());
}
if (options.subScript) {
this.properties.push(new SubScript());
}
if (options.superScript) {
this.properties.push(new SuperScript());
}
if (options.style) {
this.properties.push(new Style(options.style));
}
if (options.font) {
if ("name" in options.font) {
this.properties.push(new RunFonts(options.font.name, options.font.hint));
} else {
this.properties.push(new RunFonts(options.font));
}
}
if (options.highlight) {
this.properties.push(new Highlight(options.highlight));
this.properties.push(new HighlightComplexScript(options.highlight));
}
if (options.shading) {
this.properties.push(new Shading(options.shading.type, options.shading.fill, options.shading.color));
this.properties.push(new ShadowComplexScript(options.shading.type, options.shading.fill, options.shading.color));
}
if (options.children) {

@@ -165,0 +34,0 @@ for (const child of options.children) {

@@ -1,16 +0,3 @@

import { XmlComponent } from "file/xml-components";
import { ParagraphPropertiesDefaults } from "./paragraph-properties";
import { RunPropertiesDefaults } from "./run-properties";
export class DocumentDefaults extends XmlComponent {
private readonly runPropertiesDefaults: RunPropertiesDefaults;
private readonly paragraphPropertiesDefaults: ParagraphPropertiesDefaults;
constructor() {
super("w:docDefaults");
this.runPropertiesDefaults = new RunPropertiesDefaults();
this.paragraphPropertiesDefaults = new ParagraphPropertiesDefaults();
this.root.push(this.runPropertiesDefaults);
this.root.push(this.paragraphPropertiesDefaults);
}
}
export * from "./paragraph-properties";
export * from "./run-properties";
export * from "./document-defaults";

@@ -1,9 +0,9 @@

import { ParagraphProperties } from "file/paragraph/properties";
import { IParagraphStylePropertiesOptions, ParagraphProperties } from "file/paragraph/properties";
import { XmlComponent } from "file/xml-components";
export class ParagraphPropertiesDefaults extends XmlComponent {
constructor() {
constructor(options?: IParagraphStylePropertiesOptions) {
super("w:pPrDefault");
this.root.push(new ParagraphProperties({}));
this.root.push(new ParagraphProperties(options));
}
}

@@ -1,4 +0,2 @@

import { Size, SizeComplexScript } from "file/paragraph/run/formatting";
import { RunProperties } from "file/paragraph/run/properties";
import { IFontAttributesProperties, RunFonts } from "file/paragraph/run/run-fonts";
import { IRunStylePropertiesOptions, RunProperties } from "file/paragraph/run/properties";
import { XmlComponent } from "file/xml-components";

@@ -9,18 +7,7 @@

constructor() {
constructor(options?: IRunStylePropertiesOptions) {
super("w:rPrDefault");
this.properties = new RunProperties();
this.properties = new RunProperties(options);
this.root.push(this.properties);
}
public size(size: number): RunPropertiesDefaults {
this.properties.push(new Size(size));
this.properties.push(new SizeComplexScript(size));
return this;
}
public font(font: string | IFontAttributesProperties): RunPropertiesDefaults {
this.properties.push(new RunFonts(font));
return this;
}
}
export * from "./styles";
export * from "./style/character-style";
export * from "./style/paragraph-style";
export * from "./style-options";
export * from "./defaults";

@@ -337,27 +337,48 @@ import { expect } from "chai";

describe("formatting methods: run properties", () => {
it("#size", () => {
const style = new CharacterStyle({
id: "myStyleId",
run: {
size: 24,
},
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
const sizeTests = [
{
size: 24,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: true,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: false,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: 26,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 26 } } }],
},
];
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
it(`#size ${size} cs ${sizeComplexScript}`, () => {
const style = new CharacterStyle({
id: "myStyleId",
run: { size, sizeComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": expected,
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
},
},
},
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
});
});

@@ -581,55 +602,87 @@ });

it("#bold", () => {
const style = new CharacterStyle({
id: "myStyleId",
run: {
bold: true,
},
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }],
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
const boldTests = [
{
bold: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: false,
expected: [{ "w:b": { _attr: { "w:val": true } } }],
},
];
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
const style = new CharacterStyle({
id: "myStyleId",
run: { bold, boldComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": expected,
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
},
},
},
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
});
});
});
it("#italics", () => {
const style = new CharacterStyle({
id: "myStyleId",
run: {
italics: true,
},
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }],
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
const italicsTests = [
{
italics: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: false,
expected: [{ "w:i": { _attr: { "w:val": true } } }],
},
];
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
const style = new CharacterStyle({
id: "myStyleId",
run: { italics, italicsComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": expected,
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
},
},
},
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
});
});

@@ -678,69 +731,137 @@ });

it("#highlight", () => {
const style = new CharacterStyle({
id: "myStyleId",
run: {
highlight: "005599",
},
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
const highlightTests = [
{
highlight: "005599",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: true,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: false,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: "550099",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "550099" } } }],
},
];
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
const style = new CharacterStyle({
id: "myStyleId",
run: { highlight, highlightComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": expected,
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
},
},
},
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
});
});
});
it("#shadow", () => {
const style = new CharacterStyle({
id: "myStyleId",
run: {
shadow: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
const shadingTests = [
{
shadow: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": [
{
"w:shd": {
_attr: {
"w:val": "pct10",
"w:fill": "00FFFF",
"w:color": "FF0000",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: true,
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: false,
expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "00FF00",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "00FF00" } } },
],
},
];
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
it("#shadow correctly", () => {
const style = new CharacterStyle({
id: "myStyleId",
run: { shadow, shading, shadingComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": expected,
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
},
],
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
},
},
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
});
});

@@ -747,0 +868,0 @@ });

@@ -1,6 +0,2 @@

import { EmphasisMarkType } from "file/paragraph/run/emphasis-mark";
import * as formatting from "file/paragraph/run/formatting";
import { RunProperties } from "file/paragraph/run/properties";
import { IFontAttributesProperties } from "file/paragraph/run/run-fonts";
import { UnderlineType } from "file/paragraph/run/underline";
import { IRunStylePropertiesOptions, RunProperties } from "file/paragraph/run/properties";

@@ -14,29 +10,3 @@ import { BasedOn, Link, SemiHidden, UiPriority, UnhideWhenUsed } from "./components";

readonly semiHidden?: boolean;
readonly run?: {
readonly size?: number;
readonly bold?: boolean;
readonly italics?: boolean;
readonly smallCaps?: boolean;
readonly allCaps?: boolean;
readonly strike?: boolean;
readonly doubleStrike?: boolean;
readonly subScript?: boolean;
readonly superScript?: boolean;
readonly underline?: {
readonly type?: UnderlineType;
readonly color?: string;
};
readonly emphasisMark?: {
readonly type?: EmphasisMarkType;
};
readonly color?: string;
readonly font?: string | IFontAttributesProperties;
readonly characterSpacing?: number;
readonly highlight?: string;
readonly shadow?: {
readonly type: string;
readonly fill: string;
readonly color: string;
};
};
readonly run?: IRunStylePropertiesOptions;
}

@@ -54,3 +24,5 @@

super({ type: "character", styleId: options.id }, options.name);
this.runProperties = new RunProperties();
this.runProperties = new RunProperties(options.run);
this.root.push(this.runProperties);

@@ -71,70 +43,3 @@ this.root.push(new UiPriority(99));

}
if (options.run) {
if (options.run.size) {
this.runProperties.push(new formatting.Size(options.run.size));
this.runProperties.push(new formatting.SizeComplexScript(options.run.size));
}
if (options.run.bold) {
this.runProperties.push(new formatting.Bold());
}
if (options.run.italics) {
this.runProperties.push(new formatting.Italics());
}
if (options.run.smallCaps) {
this.runProperties.push(new formatting.SmallCaps());
}
if (options.run.allCaps) {
this.runProperties.push(new formatting.Caps());
}
if (options.run.strike) {
this.runProperties.push(new formatting.Strike());
}
if (options.run.doubleStrike) {
this.runProperties.push(new formatting.DoubleStrike());
}
if (options.run.subScript) {
this.runProperties.push(new formatting.SubScript());
}
if (options.run.superScript) {
this.runProperties.push(new formatting.SuperScript());
}
if (options.run.underline) {
this.runProperties.push(new formatting.Underline(options.run.underline.type, options.run.underline.color));
}
if (options.run.emphasisMark) {
this.runProperties.push(new formatting.EmphasisMark(options.run.emphasisMark.type));
}
if (options.run.color) {
this.runProperties.push(new formatting.Color(options.run.color));
}
if (options.run.font) {
this.runProperties.push(new formatting.RunFonts(options.run.font));
}
if (options.run.characterSpacing) {
this.runProperties.push(new formatting.CharacterSpacing(options.run.characterSpacing));
}
if (options.run.highlight) {
this.runProperties.push(new formatting.Highlight(options.run.highlight));
}
if (options.run.shadow) {
this.runProperties.push(new formatting.Shading(options.run.shadow.type, options.run.shadow.fill, options.run.shadow.color));
}
}
}
}

@@ -361,18 +361,34 @@ import { expect } from "chai";

describe("formatting methods: run properties", () => {
it("#size", () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: {
size: 24,
},
const sizeTests = [
{
size: 24,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: true,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: false,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: 26,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 26 } } }],
},
];
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
it(`#size ${size} cs ${sizeComplexScript}`, () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: { size, sizeComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
});
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
],
});
});

@@ -547,85 +563,165 @@

it("#bold", () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: {
bold: true,
},
const boldTests = [
{
bold: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: false,
expected: [{ "w:b": { _attr: { "w:val": true } } }],
},
];
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: { bold, boldComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
});
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }],
},
],
});
});
it("#italics", () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: {
italics: true,
},
const italicsTests = [
{
italics: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: false,
expected: [{ "w:i": { _attr: { "w:val": true } } }],
},
];
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: { italics, italicsComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
});
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }],
},
],
});
});
it("#highlight", () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: {
highlight: "005599",
},
const highlightTests = [
{
highlight: "005599",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: true,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: false,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: "550099",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "550099" } } }],
},
];
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: { highlight, highlightComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
});
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
},
],
});
});
it("#shadow", () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: {
shadow: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
const shadingTests = [
{
shadow: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{
"w:rPr": [
{
"w:shd": {
_attr: {
"w:val": "pct10",
"w:fill": "00FFFF",
"w:color": "FF0000",
},
},
},
],
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: true,
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: false,
expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "00FF00",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "00FF00" } } },
],
},
];
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
it("#shadow correctly", () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: { shadow, shading, shadingComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
});
});

@@ -632,0 +728,0 @@ });

@@ -1,17 +0,4 @@

import {
Alignment,
ContextualSpacing,
Indent,
KeepLines,
KeepNext,
OutlineLevel,
ParagraphProperties,
Spacing,
ThematicBreak,
} from "file/paragraph";
import { TabStop, TabStopType } from "file/paragraph/formatting";
import * as formatting from "file/paragraph/run/formatting";
import { IParagraphStylePropertiesOptions, IRunStylePropertiesOptions, ParagraphProperties } from "file/paragraph";
import { RunProperties } from "file/paragraph/run/properties";
import { IParagraphStyleOptions2, IRunStyleOptions } from "../style-options";
import { BasedOn, Link, Next, QuickFormat, SemiHidden, UiPriority, UnhideWhenUsed } from "./components";

@@ -28,4 +15,4 @@ import { Style } from "./style";

readonly unhideWhenUsed?: boolean;
readonly run?: IRunStyleOptions;
readonly paragraph?: IParagraphStyleOptions2;
readonly paragraph?: IParagraphStylePropertiesOptions;
readonly run?: IRunStylePropertiesOptions;
}

@@ -37,2 +24,3 @@

}
export class ParagraphStyle extends Style {

@@ -44,4 +32,6 @@ private readonly paragraphProperties: ParagraphProperties;

super({ type: "paragraph", styleId: options.id }, options.name);
this.paragraphProperties = new ParagraphProperties({});
this.runProperties = new RunProperties();
this.paragraphProperties = new ParagraphProperties(options.paragraph);
this.runProperties = new RunProperties(options.run);
this.root.push(this.paragraphProperties);

@@ -77,112 +67,3 @@ this.root.push(this.runProperties);

}
if (options.run) {
if (options.run.size) {
this.runProperties.push(new formatting.Size(options.run.size));
this.runProperties.push(new formatting.SizeComplexScript(options.run.size));
}
if (options.run.bold) {
this.runProperties.push(new formatting.Bold());
}
if (options.run.italics) {
this.runProperties.push(new formatting.Italics());
}
if (options.run.smallCaps) {
this.runProperties.push(new formatting.SmallCaps());
}
if (options.run.allCaps) {
this.runProperties.push(new formatting.Caps());
}
if (options.run.strike) {
this.runProperties.push(new formatting.Strike());
}
if (options.run.doubleStrike) {
this.runProperties.push(new formatting.DoubleStrike());
}
if (options.run.subScript) {
this.runProperties.push(new formatting.SubScript());
}
if (options.run.superScript) {
this.runProperties.push(new formatting.SuperScript());
}
if (options.run.underline) {
this.runProperties.push(new formatting.Underline(options.run.underline.type, options.run.underline.color));
}
if (options.run.emphasisMark) {
this.runProperties.push(new formatting.EmphasisMark(options.run.emphasisMark.type));
}
if (options.run.color) {
this.runProperties.push(new formatting.Color(options.run.color));
}
if (options.run.font) {
this.runProperties.push(new formatting.RunFonts(options.run.font));
}
if (options.run.characterSpacing) {
this.runProperties.push(new formatting.CharacterSpacing(options.run.characterSpacing));
}
if (options.run.highlight) {
this.runProperties.push(new formatting.Highlight(options.run.highlight));
}
if (options.run.shadow) {
this.runProperties.push(new formatting.Shading(options.run.shadow.type, options.run.shadow.fill, options.run.shadow.color));
}
}
if (options.paragraph) {
if (options.paragraph.alignment) {
this.paragraphProperties.push(new Alignment(options.paragraph.alignment));
}
if (options.paragraph.thematicBreak) {
this.paragraphProperties.push(new ThematicBreak());
}
if (options.paragraph.contextualSpacing) {
this.paragraphProperties.push(new ContextualSpacing(options.paragraph.contextualSpacing));
}
if (options.paragraph.rightTabStop) {
this.paragraphProperties.push(new TabStop(TabStopType.RIGHT, options.paragraph.rightTabStop));
}
if (options.paragraph.leftTabStop) {
this.paragraphProperties.push(new TabStop(TabStopType.LEFT, options.paragraph.leftTabStop));
}
if (options.paragraph.indent) {
this.paragraphProperties.push(new Indent(options.paragraph.indent));
}
if (options.paragraph.spacing) {
this.paragraphProperties.push(new Spacing(options.paragraph.spacing));
}
if (options.paragraph.keepNext) {
this.paragraphProperties.push(new KeepNext());
}
if (options.paragraph.keepLines) {
this.paragraphProperties.push(new KeepLines());
}
if (options.paragraph.outlineLevel) {
this.paragraphProperties.push(new OutlineLevel(options.paragraph.outlineLevel));
}
}
}
}

@@ -12,3 +12,3 @@ import { BaseXmlComponent, ImportedXmlComponent, XmlComponent } from "file/xml-components";

readonly characterStyles?: ICharacterStyleOptions[];
readonly importedStyles?: Array<XmlComponent | ParagraphStyle | CharacterStyle | ImportedXmlComponent>;
readonly importedStyles?: (XmlComponent | ParagraphStyle | CharacterStyle | ImportedXmlComponent)[];
}

@@ -15,0 +15,0 @@

@@ -47,3 +47,3 @@ // http://officeopenxml.com/WPtableGrid.php

};
readonly children: Array<Paragraph | Table>;
readonly children: (Paragraph | Table)[];
}

@@ -50,0 +50,0 @@

@@ -271,6 +271,3 @@ /* tslint:disable:no-unused-expression */

const tree = new Formatter().format(table);
expect(tree)
.to.have.property("w:tbl")
.which.is.an("array")
.with.has.length.at.least(1);
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1);
expect(tree["w:tbl"][0]).to.deep.equal({

@@ -295,6 +292,3 @@ "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS, { "w:tblLayout": { _attr: { "w:type": "fixed" } } }],

const tree = new Formatter().format(table);
expect(tree)
.to.have.property("w:tbl")
.which.is.an("array")
.with.has.length.at.least(1);
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1);
expect(tree["w:tbl"][0]).to.deep.equal({

@@ -323,6 +317,3 @@ "w:tblPr": [DEFAULT_TABLE_PROPERTIES, BORDERS, WIDTHS, { "w:jc": { _attr: { "w:val": "center" } } }],

const tree = new Formatter().format(table);
expect(tree)
.to.have.property("w:tbl")
.which.is.an("array")
.with.has.length.at.least(1);
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1);
expect(tree["w:tbl"][0]).to.deep.equal({

@@ -361,10 +352,6 @@ "w:tblPr": [

const tree = new Formatter().format(table);
expect(tree)
.to.have.property("w:tbl")
.which.is.an("array");
expect(tree).to.have.property("w:tbl").which.is.an("array");
const row = tree["w:tbl"].find((x) => x["w:tr"]);
expect(row).not.to.be.undefined;
expect(row["w:tr"])
.to.be.an("array")
.which.has.length.at.least(1);
expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1);
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({

@@ -494,6 +481,3 @@ "w:tc": [

const tree = new Formatter().format(table);
expect(tree)
.to.have.property("w:tbl")
.which.is.an("array")
.with.has.length.at.least(1);
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1);
expect(tree["w:tbl"][0]).to.deep.equal({

@@ -500,0 +484,0 @@ "w:tblPr": [

@@ -9,3 +9,3 @@ import { File } from "../file";

// tslint:disable-next-line:readonly-keyword no-any
protected root: Array<BaseXmlComponent | string | any>;
protected root: (BaseXmlComponent | string | any)[];

@@ -12,0 +12,0 @@ constructor(rootKey: string) {

@@ -20,4 +20,4 @@ import * as JSZip from "jszip";

interface IDocumentRefs {
readonly headers: Array<{ readonly id: number; readonly type: HeaderReferenceType }>;
readonly footers: Array<{ readonly id: number; readonly type: FooterReferenceType }>;
readonly headers: { readonly id: number; readonly type: HeaderReferenceType }[];
readonly footers: { readonly id: number; readonly type: FooterReferenceType }[];
}

@@ -103,3 +103,3 @@

})
.filter((x) => !!x) as Array<Promise<IDocumentFooter>>;
.filter((x) => !!x) as Promise<IDocumentFooter>[];

@@ -139,3 +139,3 @@ return Promise.all(result);

})
.filter((x) => !!x) as Array<Promise<IDocumentHeader>>;
.filter((x) => !!x) as Promise<IDocumentHeader>[];

@@ -142,0 +142,0 @@ return Promise.all(result);

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc